Skip to content

Commit c6f8c09

Browse files
committed
router: Set Sentry transaction field before calling the request handler
This disables the `router` feature of `sentry-conduit` and instead calls `set_transaction()` of Sentry manually before calling the route handler itself. This has the advantage of also adding the `transaction` field to Sentry issues that are not reported by the `sentry-conduit` middleware itself.
1 parent 61c1a7a commit c6f8c09

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ reqwest = { version = "0.11", features = ["blocking", "gzip", "json"] }
7474
scheduled-thread-pool = "0.2.0"
7575
semver = { version = "1.0.3", features = ["serde"] }
7676
sentry = { version = "0.23.0", features = ["tracing"] }
77-
sentry-conduit = "0.2.0"
77+
sentry-conduit = { version = "0.2.0", default-features = false }
7878
serde = { version = "1.0.0", features = ["derive"] }
7979
serde_json = "1.0.0"
8080
sha2 = "0.9"

src/router.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,17 @@ struct C(pub fn(&mut dyn RequestExt) -> EndpointResult);
151151

152152
impl Handler for C {
153153
fn call(&self, req: &mut dyn RequestExt) -> HandlerResult {
154-
// Allow blocking individual routes by their pattern through the `BLOCKED_ROUTES`
155-
// environment variable. This is not in a middleware because we need access to
156-
// `RoutePattern` before executing the response handler.
157154
if let Some(pattern) = req.extensions().find::<RoutePattern>() {
158-
if req.app().config.blocked_routes.contains(pattern.pattern()) {
155+
let pattern = pattern.pattern();
156+
157+
// Configure the Sentry `transaction` field *before* we handle the request,
158+
// but *after* the conduit-router has figured out which handler to use.
159+
sentry::configure_scope(|scope| scope.set_transaction(Some(pattern)));
160+
161+
// Allow blocking individual routes by their pattern through the `BLOCKED_ROUTES`
162+
// environment variable. This is not in a middleware because we need access to
163+
// `RoutePattern` before executing the response handler.
164+
if req.app().config.blocked_routes.contains(pattern) {
159165
return Ok(RouteBlocked.response().unwrap());
160166
}
161167
}

0 commit comments

Comments
 (0)