-
Hi, I'm extracting user information in a middleware and am using the Router::new()
.nest("/api/v1", app())
.layer(TraceLayer::new_for_http())
.route_layer(middleware::from_fn_with_state(
app_state.clone(),
middleware,
)) I'm unsure how to tackle this, I've tried the following, but it was not working correctly:
let span = span!(Level::ERROR, "user", username);
let _guard = span.enter(); I wouldn't mind adding it to the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
You need to use |
Beta Was this translation helpful? Give feedback.
-
Thank you for the response! I've tried what you're suggesting and it does not seem to work, seems like the middleware gets called before the
I found out that I need it to be like the following: Router::new()
.nest("/api/v1", app())
.route_layer(middleware::from_fn_with_state(
app_state.clone(),
middleware,
))
.layer(TraceLayer::new_for_http()) And If I do what you suggest, everything works, thank you :) Now I see the following:
|
Beta Was this translation helpful? Give feedback.
You need to use
.make_span_with
on theTraceLayer
to add the custom fields to the span (see this example), then useSpan::current().record("field", value)
in the middleware to set its value.