tower-http-opentelemetry 0.0.1

Tower middleware to emit conventional OpenTelemetry spans and metrics for HTTP and gRPC requests
Documentation

tower-http-opentelemetry

home

Tower middleware to emit conventional OpenTelemetry spans and metrics for HTTP and gRPC requests.

WARNING: This project is currently only a proof of concept. The middleware creates and enters an HTTP span, and records terminated connections. See ROADMAP.md for details.

Features

The emitted telemetry conforms to the OpenTelemetry semantic conventions 1.44.0.

The middleware works with any Tower-compatible HTTP and gRPC framework, for clients and servers, including:

Examples

The examples/ directory contains example HTTP and gRPC applications. Continue reading for a demonstration.

Optionally enter the Nix-powered development shell to install all necessary tools:

nix develop

Run an OpenTelemetry-compatible collector, for example:

# GUI (web-based)
otel-desktop-viewer --host 127.0.0.1

# TUI
otel-tui --host 127.0.0.1

# CLI (OpenTelemetry events and spans only, no logs or metrics)
otel-cli server json --verbose --stdout

HTTP example

The following commands run an axum-powered HTTP server, and a reqwest-powered HTTP client:

cargo run -p example-axum
cargo run -p example-reqwest

The second command should produce three traces, each with four spans:

  1. The client's query function
  2. The client's telemetry middleware span named GET
  3. The server's telemetry middleware span named GET /
  4. The server's request handler home

The first trace should indicate success, while the second and third trace should indicate connection terminated errors.

Alternatively, query the server using otel-cli and curl for more control:

export OTEL_EXPORTER_OTLP_ENDPOINT="http://127.0.0.1:4318"
otel-cli exec --name manual_query --fail -- \
  curl \
    --verbose \
    --no-progress-meter \
    --header "traceparent: {{traceparent}}" \
    http://127.0.0.1:8080/

gRPC example

The following commands run a tonic-powered gRPC server and client:

cargo run --bin example-tonic-server
cargo run --bin example-tonic-client

Maintenance

This project is actively maintained.

Releases adhere to Semantic Versioning 2.0.0. Furthermore, this project strives to follow the SemVer Compatibility guidelines of The Cargo Book.

The minimum supported Rust version (MSRV) is the latest stable release. A minor release may increase the MSRV with no further ado.

The Nix flake is experimental.

License

This work is dual-licensed under MIT or Apache License, Version 2.0.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project shall be dual-licensed under MIT or Apache License, Version 2.0, without any additional terms or conditions.

Contact

Feel free to contact me via email if you want to discuss this project.

See also

This project was inspired by tower-http's tracing middleware.

Feel free to check out the following alternatives to this project: