Skip to main content
Dual export from a Rust service on actix-web. Built from the example examples/otel-rust-actix: actix-web 4.18.2 with opentelemetry-instrumentation-actix-web 0.25.0 (metrics feature) and opentelemetry 0.33.1, on Rust 1.99.1. tests/otelapps runs it against stock collectors in every export mode, and the apipath tag runs it against the real platform collector. Read the API quickstart first for the token and the environment variables.

Crates

The SDK setup

One tracer provider and one meter provider, each with two exporters; only the platform exporters carry the token. The exporters use HTTP with protobuf through the blocking reqwest client and rustls, so an https endpoint works without a system OpenSSL. That client must be built outside an async runtime, so the example sets telemetry up before the actix system starts:

Instrumenting the server

Wrap the routes with RequestMetrics and RequestTracing. The health check route sits outside the wrapped scope, so probes do not count as API traffic:
The middleware sets http.route from the actix route pattern (/accounts/{id}); see http-route.md.

Notes

  • Shut down cleanly. After HttpServer::run returns (actix stops gracefully on SIGTERM), call shutdown() on the meter provider and then the tracer provider, so the last interval is exported.
  • Exponential histograms need a view, which needs the spec_unstable_metrics_views feature of opentelemetry_sdk. The default explicit buckets need nothing extra.

Export modes the tests cover