Skip to content

Commit 5bbc1d5

Browse files
committed
sentry: use native sentry-tower / axum integration for setting transaction name
1 parent 144032c commit 5bbc1d5

File tree

3 files changed

+3
-22
lines changed

3 files changed

+3
-22
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
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
@@ -17,7 +17,7 @@ exclude = [
1717
]
1818

1919
[dependencies]
20-
sentry = { version = "0.35.0", features = ["panic", "tracing", "tower-http", "anyhow", "backtrace"] }
20+
sentry = { version = "0.35.0", features = ["panic", "tracing", "tower-http", "anyhow", "backtrace", "tower-axum-matched-path"] }
2121
log = "0.4"
2222
tracing = "0.1.37"
2323
tracing-subscriber = { version = "0.3.16", default-features = false, features = ["ansi", "fmt", "json", "env-filter", "tracing-log"] }

src/web/mod.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ mod status;
3939
use crate::{impl_axum_webpage, Context};
4040
use anyhow::Error;
4141
use axum::{
42-
extract::{Extension, MatchedPath, Request as AxumRequest},
42+
extract::{Extension, Request as AxumRequest},
4343
http::StatusCode,
4444
middleware,
4545
middleware::Next,
@@ -382,23 +382,6 @@ async fn log_timeouts_to_sentry(req: AxumRequest, next: Next) -> AxumResponse {
382382
response
383383
}
384384

385-
async fn set_sentry_transaction_name_from_axum_route(
386-
request: AxumRequest,
387-
next: Next,
388-
) -> AxumResponse {
389-
let route_name = if let Some(path) = request.extensions().get::<MatchedPath>() {
390-
path.as_str()
391-
} else {
392-
request.uri().path()
393-
};
394-
395-
sentry::configure_scope(|scope| {
396-
scope.set_transaction(Some(route_name));
397-
});
398-
399-
next.run(request).await
400-
}
401-
402385
async fn apply_middleware<C: Context>(
403386
router: AxumRouter,
404387
context: &C,
@@ -415,9 +398,6 @@ async fn apply_middleware<C: Context>(
415398
.layer(TraceLayer::new_for_http())
416399
.layer(sentry_tower::NewSentryLayer::new_from_top())
417400
.layer(sentry_tower::SentryHttpLayer::with_transaction())
418-
.layer(middleware::from_fn(
419-
set_sentry_transaction_name_from_axum_route,
420-
))
421401
.layer(CatchPanicLayer::new())
422402
.layer(option_layer(
423403
config

0 commit comments

Comments
 (0)