tower-http-opentelemetry
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:
- axum
- reqwest (by means of tower-reqwest)
- tonic
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:
Run an OpenTelemetry-compatible collector, for example:
- otel-desktop-viewer, a graphical explorer
- otel-tui, an interactive terminal explorer
- otel-cli, a scriptable command-line tool
# GUI (web-based)
# TUI
# CLI (OpenTelemetry events and spans only, no logs or metrics)
HTTP example
The following commands run an axum-powered HTTP server, and a reqwest-powered HTTP client:
The second command should produce three traces, each with four spans:
- The client's
queryfunction - The client's telemetry middleware span named
GET - The server's telemetry middleware span named
GET / - 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:
gRPC example
The following commands run a tonic-powered gRPC server and 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:
- tower-otel provides a Tower layer for HTTP and gRPC clients and servers
- axum-tracing-opentelemetry provides a Tower layer specifically for axum-powered HTTP servers, and optionally a Prometheus-compatible metrics endpoint
- opentelemetry-instrumentation-tower provides a Tower layer for HTTP servers