Expand description
HTTP client spans and metrics for reqwest, as the OpenTelemetry semantic conventions describe, with the trace carried on to the server. Part of oxtel.
One line wraps a reqwest client, and requests are made as before:
let client = oxtel_reqwest::client(reqwest::Client::new());
let items = client.get("https://api.example/items").send().await?.text().await?;Every request gets:
- a client span named for its method, with
http.request.method,server.address,server.port,url.full,network.protocol.versionandhttp.response.status_code. A 4xx or 5xx response, or a request that got no response, is an error, witherror.typesaying why: the status code, ortimeout,connect,redirect,body,decodeorrequest. - W3C
traceparentandtracestateheaders, so a server that reads them, such as one with oxtel-tower’sHttpServerLayer, continues the trace. http.client.request.durationin seconds, by method, server, scheme, status anderror.type.
The query string and any credentials in the URL are never recorded,
since either may hold secrets. These are the spans and metrics
oxtel-tower’s HttpClientLayer records, so a program using both gets
the same telemetry from each.
client returns reqwest-middleware’s
ClientWithMiddleware,
whose methods are reqwest’s own. A program with other middleware adds
HttpClientMiddleware with the rest. After retry middleware, each
attempt gets a span of its own; a redirect that reqwest follows itself is
part of the same span.
let client = reqwest_middleware::ClientBuilder::new(reqwest::Client::new())
// No trace context for requests that leave your systems.
.with(oxtel_reqwest::HttpClientMiddleware::new().with_propagation(false))
.build();Spans 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. Make the client after
oxtel::init(), so the duration is recorded in seconds with the
conventions’ buckets.
Re-exports§
pub use reqwest_middleware;
Structs§
- Http
Client Middleware - reqwest-middleware middleware that records each request: a client span,
trace context sent along, and
http.client.request.duration. See the crate documentation.
Functions§
- client
client, with every request it makes recorded:HttpClientMiddlewarewith its defaults.