Skip to content

Commit a2945a4

Browse files
committed
middleware::log_request: Move request.id handling for Sentry into before() method
This allows us to add the metadata to issue reports as soon as possible, instead of only doing it in the `after()` method of the middleware.
1 parent b8ad2e6 commit a2945a4

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/middleware/log_request.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ impl Middleware for LogRequests {
2121
fn before(&self, req: &mut dyn RequestExt) -> BeforeResult {
2222
let path = OriginalPath(req.path().to_string());
2323
req.mut_extensions().insert(path);
24+
25+
if let Some(request_id) = req
26+
.headers()
27+
.get("x-request-id")
28+
.and_then(|value| value.to_str().ok())
29+
{
30+
sentry::configure_scope(|scope| scope.set_tag("request.id", request_id));
31+
}
32+
2433
Ok(())
2534
}
2635

@@ -103,14 +112,6 @@ fn report_to_sentry(req: &dyn RequestExt, res: &AfterResult, response_time: u64)
103112
scope.set_user(Some(user));
104113
}
105114

106-
if let Some(request_id) = req
107-
.headers()
108-
.get("x-request-id")
109-
.and_then(|value| value.to_str().ok())
110-
{
111-
scope.set_tag("request.id", request_id);
112-
}
113-
114115
{
115116
let status = res
116117
.as_ref()

0 commit comments

Comments
 (0)