Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,14 @@ where

let query_string = req.query_string().to_string();

let request_id = req
.extensions()
.get::<tracing_actix_web::RequestId>()
.map(|req_id| header::HeaderValue::from_str(&req_id.to_string()));
// Check for x-request-id header first, fallback to generated one from extensions
let request_id = req.headers().get("x-request-id").cloned().or_else(|| {
req.extensions()
.get::<tracing_actix_web::RequestId>()
.and_then(|req_id| {
header::HeaderValue::from_str(&req_id.to_string()).ok()
})
});
Comment on lines +136 to +143
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The header_extractor enforces a 256 char limit which will address this as well - so moving the header_extraction here will solve both issues I believe.


let (http_req, mut payload) = req.into_parts();
let mut body_bytes = Vec::new();
Expand Down Expand Up @@ -181,7 +185,7 @@ where
let start_time = Instant::now();
res = service.call(new_req).await?;

if let Some(Ok(request_id)) = request_id {
if let Some(request_id) = request_id {
res.headers_mut()
.insert(header::HeaderName::from_static("x-request-id"), request_id);
}
Expand Down
7 changes: 6 additions & 1 deletion crates/superposition/src/log_span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ impl RootSpanBuilder for CustomRootSpanBuilder {
let org = header_extractor(headers, "x-org-id").unwrap_or_else(|| {
path_extractor(path, 0).unwrap_or_else(|| "no-org-header".to_string())
});
let request_id = header_extractor(headers, "x-request-id");
let method = request.method().to_string();
tracing_actix_web::root_span!(request, workspace, org, method, path,)
if let Some(request_id) = request_id {
tracing_actix_web::root_span!(request, request_id = %request_id, workspace, org, method, path,)
} else {
tracing_actix_web::root_span!(request, workspace, org, method, path,)
Comment on lines +42 to +47
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good one - should we move the sanitization ahead - so that what we log and what we use / send back are the same ?

}
}

fn on_request_end<B: MessageBody>(
Expand Down
Loading