Skip to main content

opentelemetry-http

Version: 0.31.0 The opentelemetry-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 client
  • reqwest-blocking: Blocking reqwest client
  • reqwest-rustls: Reqwest with rustls TLS
  • reqwest-rustls-webpki-roots: Reqwest with webpki trust roots
  • hyper: Hyper client
Other:
  • 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::Response

Types

type
Type alias for boxed error: Box<dyn std::error::Error + Send + Sync + 'static>
re-export
Re-exported from bytes crate for convenience
re-export
Re-exported from http crate: http::Request
re-export
Re-exported from http crate: http::Response

Use 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

Documentation

Full API Documentation

View complete API reference on docs.rs

Context Propagation Example

Full working example on GitHub

Minimum Rust Version

MSRV: 1.75.0