Skip to main content

Crate oxtel_tower

Crate oxtel_tower 

Source
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.duration and http.server.active_requests; an access log.
  • HttpClientLayer: a span per request, trace context sent along, and http.client.request.duration. ClientCall records the same for a client that isn’t a tower service.
  • MetricsService: Prometheus /metrics as 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 HttpServerLayer makes for a request, from its RequestInfo, with every standard field declared. Add fields of your own after the info, for middleware to record later:

Structs§

ClientCall
One outgoing HTTP request, recorded as HttpClientLayer records it: a client span, trace context for the request’s headers, and http.client.request.duration. For instrumenting an HTTP client that isn’t a tower service:
ClientRequestInfo
An outgoing request, as ClientCall::start records it.
HttpClient
The service HttpClientLayer wraps around a client.
HttpClientLayer
Instruments an HTTP client, as the OpenTelemetry semantic conventions for HTTP clients describe:
HttpServer
The service HttpServerLayer wraps around yours.
HttpServerLayer
Instruments an HTTP server, as the OpenTelemetry semantic conventions for HTTP servers describe:
MetricsService
Answers every request with a Prometheus scrape of the exporter’s metrics, in the format the Accept header 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’s TowerToHyperService.
RequestInfo
What an incoming request’s span records, as the HTTP semantic conventions name it. Handed to a span-making hook; see server_span!.
SpanName
A span name, formatted without allocating until it’s recorded.

Functions§

describe_metrics
Give the current metrics recorder 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 (as oxtel::init() does), or call this once the recorder is in place.