Skip to content

Commit 9df3816

Browse files
authored
docs(tower): suggest reordering layers when using axum (#881)
1 parent 4c4fc9d commit 9df3816

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

sentry-tower/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,19 @@
130130
//! # }
131131
//! ```
132132
//!
133+
//! When using `axum`, either use [`tower::ServiceBuilder`] as shown above, or make sure you
134+
//! reorder the layers, like so:
135+
//!
136+
//! ```rust
137+
//! let app = Router::new()
138+
//! .route("/", get(handler))
139+
//! .layer(sentry_tower::SentryHttpLayer::with_transaction())
140+
//! .layer(sentry_tower::NewSentryLayer::<Request>::new_from_top())
141+
//! ```
142+
//!
143+
//! This is because `axum` applies middleware in the opposite order as [`tower::ServiceBuilder`].
144+
//! Applying the layers in the wrong order can result in memory leaks.
145+
//!
133146
//! [`tower::ServiceBuilder`]: https://docs.rs/tower/latest/tower/struct.ServiceBuilder.html
134147
135148
#![doc(html_favicon_url = "https://sentry-brand.storage.googleapis.com/favicon.ico")]

0 commit comments

Comments
 (0)