Expand description
HTTP instrumentation for tower services, and so for axum and hyper, following the OpenTelemetry semantic conventions. Part of oxtel.
HttpServerLayer: a span per request, continuing the caller’s trace;http.server.request.durationandhttp.server.active_requests; an access log.HttpClientLayer: a span per request, trace context sent along, andhttp.client.request.duration.ClientCallrecords the same for a client that isn’t a tower service.MetricsService: Prometheus/metricsas a tower service, for an axum router or a hyper server.
use axum::Router;
use axum::routing::get;
use oxtel_tower::{HttpServerLayer, MetricsService};
Router::new()
.route("/items/{id}", get(|| async { "item" }))
// `Router::layer` runs after routing, so `http.route` is the template.
.layer(HttpServerLayer::new())
.route_service("/metrics", MetricsService::new(exporter))Spans and events are recorded with tracing and metrics with metrics,
so they go wherever the program’s subscriber and recorder send them:
with oxtel::init(), to OTLP or Prometheus.
Modules§
- future
- The futures the services return.
Macros§
- server_
span - The span
HttpServerLayermakes for a request, from itsRequestInfo, with every standard field declared. Add fields of your own after the info, for middleware to record later:
Structs§
- Client
Call - One outgoing HTTP request, recorded as
HttpClientLayerrecords it: a client span, trace context for the request’s headers, andhttp.client.request.duration. For instrumenting an HTTP client that isn’t a tower service: - Client
Request Info - An outgoing request, as
ClientCall::startrecords it. - Http
Client - The service
HttpClientLayerwraps around a client. - Http
Client Layer - Instruments an HTTP client, as the OpenTelemetry semantic conventions for HTTP clients describe:
- Http
Server - The service
HttpServerLayerwraps around yours. - Http
Server Layer - Instruments an HTTP server, as the OpenTelemetry semantic conventions for HTTP servers describe:
- Metrics
Service - Answers every request with a Prometheus scrape of the exporter’s
metrics, in the format the
Acceptheader negotiates: OpenMetrics with exemplars for Prometheus, the classic text format otherwise. Mount it at/metrics: with axum,Router::route_service("/metrics", ...); with hyper, through hyper-util’sTowerToHyperService. - Request
Info - What an incoming request’s span records, as the HTTP semantic
conventions name it. Handed to a span-making hook; see
server_span!. - Span
Name - A span name, formatted without allocating until it’s recorded.
Functions§
- describe_
metrics - Give the current
metricsrecorder the units and descriptions of the HTTP metrics, so the duration histograms are in seconds with the conventions’ buckets. The layers do this when they’re made, so make them after installing the recorder (asoxtel::init()does), or call this once the recorder is in place.