opentelemetry-http
Version: 0.31.0 Theopentelemetry-http crate provides HTTP-related utilities for OpenTelemetry, including context propagation helpers and HTTP client abstractions for exporting telemetry.
Installation
Feature Flags
HTTP Client Implementations:reqwest: Async reqwest clientreqwest-blocking: Blocking reqwest clientreqwest-rustls: Reqwest with rustls TLSreqwest-rustls-webpki-roots: Reqwest with webpki trust rootshyper: Hyper client
internal-logs: Enable internal logging (enabled by default)
Context Propagation
Injecting Context into HTTP Requests
struct
Helper for injecting OpenTelemetry context into HTTP headers
Extracting Context from HTTP Requests
struct
Helper for extracting OpenTelemetry context from HTTP headers
HTTP Client Trait
trait
Minimal interface for sending HTTP requests. Used by exporters to send telemetry data.
Built-in HTTP Clients
Reqwest Client (Async)
Reqwest Blocking Client
Hyper Client
Complete Example
Context Propagation in HTTP Server
Using Custom HTTP Client with Exporter
Response Extension Trait
trait
Extension methods for
http::ResponseTypes
type
Type alias for boxed error:
Box<dyn std::error::Error + Send + Sync + 'static>re-export
Re-exported from
bytes crate for conveniencere-export
Re-exported from
http crate: http::Requestre-export
Re-exported from
http crate: http::ResponseUse Cases
Distributed Tracing
Propagate trace context across HTTP service boundaries
Custom Exporters
Implement custom HTTP-based telemetry exporters
Client Selection
Choose HTTP client based on async runtime and performance needs
Testing
Mock HTTP client for testing exporters
Example: Propagation in Web Framework
With Axum
Related Crates
- opentelemetry - Core API with propagation traits
- opentelemetry-otlp - OTLP exporter using
HttpClient - opentelemetry-zipkin - Zipkin exporter using
HttpClient - http - HTTP types
- reqwest - HTTP client
Documentation
Full API Documentation
View complete API reference on docs.rs
Context Propagation Example
Full working example on GitHub