Assigning a unique request ID to all traces within a request's lifetime #2273
-
Hello, I am relatively new to Axum / Tower / Tracing, so I apologize if this is in the wrong place. I am trying to add a trace layer to my Axum service that adds a custom I think I have something like this working using the following customizations to the // ...
.layer(
TraceLayer::new_for_http()
.make_span_with(|request: &Request<Body>| {
let request_id = uuid::Uuid::new_v4();
tracing::span!(
Level::DEBUG,
"request",
method = tracing::field::display(request.method()),
uri = tracing::field::display(request.uri()),
version = tracing::field::debug(request.version()),
request_id = tracing::field::display(request_id)
)
})
)
// ... When testing this locally, it actually appears to be working.
I can see the What I am unsure of is how this will hold up in a "production" deployment with many threads and requests happening at once. My understanding of how I would like to handle this in the way that I currently have it setup, as it feels really clean, but maybe the safest way to do this is to set the Hopefully, this all makes sense. I really appreciate any feedback or guidance on this! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Where did you hear that? I think what you wrote should work fine. |
Beta Was this translation helpful? Give feedback.
-
what you need is tracing. just use the trace_id |
Beta Was this translation helpful? Give feedback.
-
What's the recommended approach to doing this? It would be great to include this use case in |
Beta Was this translation helpful? Give feedback.
Where did you hear that?
I think what you wrote should work fine.