pub struct HttpServerLayer { /* private fields */ }Expand description
Instruments an HTTP server, as the OpenTelemetry semantic conventions for HTTP servers describe:
- A span per request, a child of the caller’s when the request
carries W3C
traceparent. Named{method} {route}, withhttp.request.method,url.path,url.scheme,http.route,server.address,server.port,network.protocol.version,user_agent.original,http.response.status_code, anderror.typewith status Error for 5xx responses. - Metrics, through the
metricsfacade:http.server.request.duration(seconds) by method, scheme, route, status, protocol version anderror.type; andhttp.server.active_requestsby method and scheme. - An access log event, if asked for:
requestatinfo, orerrorfor 5xx, with the status and duration.
The duration runs until the response’s head is ready; a streamed body may take longer. The query string isn’t recorded.
Implementations§
Source§impl HttpServerLayer
impl HttpServerLayer
Sourcepub fn new() -> Self
pub fn new() -> Self
A layer with spans, propagation, metrics and the access log on. With
the axum feature, http.route comes from axum’s
MatchedPath. Make it after installing the metrics recorder; see
describe_metrics.
Sourcepub fn with_propagation(self, enabled: bool) -> Self
pub fn with_propagation(self, enabled: bool) -> Self
Continue the caller’s trace from W3C traceparent and tracestate
headers. Default: true. Turn it off at a trust boundary, where
callers shouldn’t choose your trace ids or sampling.
Sourcepub fn with_metrics(self, enabled: bool) -> Self
pub fn with_metrics(self, enabled: bool) -> Self
Record the request metrics. Default: true.
Sourcepub fn with_access_log(self, enabled: bool) -> Self
pub fn with_access_log(self, enabled: bool) -> Self
Log each finished request as an event: request at info, or at
error for a 5xx. Default: true. RUST_LOG=info,oxtel_tower=warn
also hides it, but keeps the errors.
Sourcepub fn with_scheme(self, scheme: &'static str) -> Self
pub fn with_scheme(self, scheme: &'static str) -> Self
The url.scheme for requests whose URI has none, as on a server
behind a proxy that ends TLS. Default: http.
Sourcepub fn with_route(
self,
route: impl for<'a> Fn(&'a Extensions) -> Option<&'a str> + Send + Sync + 'static,
) -> Self
pub fn with_route( self, route: impl for<'a> Fn(&'a Extensions) -> Option<&'a str> + Send + Sync + 'static, ) -> Self
Where the matched route template comes from, for routers other than axum’s.
Sourcepub fn with_span(
self,
make_span: impl Fn(&RequestInfo<'_>) -> Span + Send + Sync + 'static,
) -> Self
pub fn with_span( self, make_span: impl Fn(&RequestInfo<'_>) -> Span + Send + Sync + 'static, ) -> Self
Make each request’s span yourself, to declare fields of your own
for later middleware to record. Use server_span!
so the standard fields are declared too:
use oxtel_tower::{HttpServerLayer, server_span};
let layer = HttpServerLayer::new()
.with_span(|info| server_span!(info, app.user.id = tracing::field::Empty));