sentry-rust
sentry-rust copied to clipboard
Provide a minimal example for propagating request IDs into the distributed tracing system (w/ Axum)
Hello there! Is it possible for any maintainer here to help me configure distributed tracing using Axum, Tracing, and Sentry?
I am following the guide on custom instrumentation for distributed tracing here posted here. However, this guide does not show how to inject an existing request ID from an incoming HTTP request into the system for distributed tracing.
I am generating a random request ID (x-request-id) and propagating the header using the Tower middleware. The following two layers are added to handle this for every request made to my Axum router.
As a part of my system, I also initialize a tracing Subscriber with the standard sentry_tracing::layer() (not shown, before the code below). After this is initialized in a tracing Registry, the sentry_tower::{SentryHttpLayer, SentryLayer} layers are added to my Axum router (with http/axum-matched-path features enabled).
Here's a snippet from my codebase (there's many LOC so it would take more time to create an MVCE):
let sentry_hub = sentry::Hub::current(); // use same hub as the sentry tracing layer?
Router::new()
.nest("/v1", services) // services is an Axum router
.layer(ServiceBuilder::new()
.layer(CorsLayer::new().allow_origin(Any).allow_methods(Any))
.catch_panic()
.trim_trailing_slash()
.trace_for_http()
.set_x_request_id(RandomRequestId::default()) // UUID v4
.propagate_x_request_id()
.layer(sentry_tower::SentryLayer::<_, _, Request>::new(sentry_hub))
.layer(sentry_tower::SentryHttpLayer::with_transaction())
)
In my Sentry dashboard, I see that new exceptions and events contain the header data from each request, including x-request-id. However, the transaction field for each event is (empty string), indicating that the with_transaction() layer variant does not work as intended (?). Additionally, each event has no custom trace ID that I can see, so it does not seem to be instrumented correctly either.
I have been at this for several days and I would greatly appreciate any help or guidance you could provide.
Thanks, Sean