Skip to content

Commit 305914e

Browse files
authored
Fix the ordering of the middlewares (#4452)
2 parents 3ef91d5 + cb74729 commit 305914e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

crates/cli/src/server.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ pub fn build_router(
291291
router = router.fallback(mas_handlers::fallback);
292292

293293
router
294+
.layer(axum::middleware::from_fn(log_response_middleware))
294295
.layer(
295296
InFlightCounterLayer::new("http.server.active_requests").on_request((
296297
name.map(|name| KeyValue::new(MAS_LISTENER_NAME, name.to_owned())),
@@ -316,12 +317,16 @@ pub fn build_router(
316317
span.record("otel.status_code", "OK");
317318
}),
318319
)
319-
.layer(axum::middleware::from_fn(log_response_middleware))
320320
.layer(mas_context::LogContextLayer::new(|req| {
321321
otel_http_method(req).into()
322322
}))
323-
.layer(NewSentryLayer::new_from_top())
323+
// Careful about the order here: the `NewSentryLayer` must be around the
324+
// `SentryHttpLayer`. axum makes new layers wrap the existing ones,
325+
// which is the other way around compared to `tower::ServiceBuilder`.
326+
// So even if the Sentry docs has an example that does
327+
// 'NewSentryHttpLayer then SentryHttpLayer', we must do the opposite.
324328
.layer(SentryHttpLayer::with_transaction())
329+
.layer(NewSentryLayer::new_from_top())
325330
.with_state(state)
326331
}
327332

0 commit comments

Comments
 (0)