tracing user #170
Answered
by
maxcountryman
nicolasauler
asked this question in
Q&A
-
Hi there, I was wondering if there was any way we could trace the user. My section of the code that I think would change is: .layer(auth_layer)
.layer(
ServiceBuilder::new()
.layer(HandleErrorLayer::new(|error: BoxError| {
return async move {
if error.is::<Elapsed>() {
return Ok(StatusCode::REQUEST_TIMEOUT);
}
return Err((
StatusCode::INTERNAL_SERVER_ERROR,
format!("Unhandled internal error: {error}"),
));
};
}))
.timeout(Duration::from_secs(10))
.layer(TraceLayer::new_for_http())
.into_inner(),
) I appreciate any help! |
Beta Was this translation helpful? Give feedback.
Answered by
maxcountryman
Jan 28, 2024
Replies: 1 comment 9 replies
-
Are you hoping to trace the full user as represented by e.g. a Display implementation or would just the ID suffice? If the latter, I think we could attach that to the trace span in the call method itself: I have #160 open to that end. |
Beta Was this translation helpful? Give feedback.
9 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can take the AuthSession off the request and check if there's a user and then log the request if you like
Or you can use the fact that the user ID is now attached to the span of the axum-login middleware itself to see which user IDs are associated with which requests.
Which you choose will depend on what exactly you intend to do with those logs.
For instance, in the case of the latter you'll only "see" the user ID when there's something for trace to log; i.e. you've sent an info, etc event: at this point you should see the user ID as a field of the call span.