From f78ba5b5dbdbdaba88d32e13e4b36da5d9d1a9b7 Mon Sep 17 00:00:00 2001 From: lcian Date: Fri, 23 May 2025 17:48:39 +0200 Subject: [PATCH 01/12] feat(axum): provide docs for Axum --- docs/platforms/rust/guides/axum/config.yml | 1 + docs/platforms/rust/guides/axum/index.mdx | 99 ++++++++++++++++++++++ src/components/platformIcon.tsx | 7 ++ 3 files changed, 107 insertions(+) create mode 100644 docs/platforms/rust/guides/axum/config.yml create mode 100644 docs/platforms/rust/guides/axum/index.mdx diff --git a/docs/platforms/rust/guides/axum/config.yml b/docs/platforms/rust/guides/axum/config.yml new file mode 100644 index 00000000000000..3fd04b50c51c1b --- /dev/null +++ b/docs/platforms/rust/guides/axum/config.yml @@ -0,0 +1 @@ +title: axum \ No newline at end of file diff --git a/docs/platforms/rust/guides/axum/index.mdx b/docs/platforms/rust/guides/axum/index.mdx new file mode 100644 index 00000000000000..ca73ac3eac585d --- /dev/null +++ b/docs/platforms/rust/guides/axum/index.mdx @@ -0,0 +1,99 @@ +--- +title: axum +description: "Learn about monitoring your axum application with Sentry." +--- + +The Sentry SDK offers a middleware for the [`axum`](https://github.com/tokio-rs/axum) framework that supports: + +- Reporting errors and panics with the correct request correlation. +- Starting a [transaction](https://docs.sentry.io/concepts/key-terms/tracing/) for each request-response cycle. + +The integration actually supports any crate based on [`tower`](https://github.com/tower-rs/tower), not just `axum`. + +## Install + +To add Sentry with the `axum` integration to your Rust project, just add a new dependency to your `Cargo.toml`: + +```toml {filename:Cargo.toml} +[dependencies] +axum = "0.8.4" +tower = "0.5.2" +tokio = { version = "1.45.0", features = ["full"] } +sentry = { version = "{{@inject packages.version('sentry.rust') }}", features = ["tower-axum-matched-path"] } +``` + +## Configure + +Initialize and configure the Sentry client. This will enable a set of default integrations, such as panic reporting. +Then, initialize `axum` with the Sentry middleware. + + + +Macros like `#[tokio::main]` are not supported. The Sentry client must be initialized before the async runtime is started, as shown below. + + + +```rust {filename:main.rs} +use axum::{body::Body, http::Request, routing::get, Router}; +use sentry::integrations::tower::{NewSentryLayer, SentryHttpLayer}; +use std::io; +use tower::ServiceBuilder; + +async fn failing() -> () { + panic!("Everything is on fire!") +} + +fn main() -> io::Result<()> { + let _guard = sentry::init(( + "https://6b76fb2a5dc1164849cd797b75b6d879@o447951.ingest.us.sentry.io/4508694563782656", + sentry::ClientOptions { + release: sentry::release_name!(), + // Capture all traces. Set to a lower value in production. + traces_sample_rate: 1.0, + // Capture user IPs and potentially sensitive headers when using HTTP server integrations + // see https://docs.sentry.io/platforms/rust/data-management/data-collected for more info + send_default_pii: true, + ..Default::default() + }, + )); + + let app = Router::new().route("/", get(failing)).layer( + ServiceBuilder::new() + // If you're binding the layers directly on the `Router`, bind them in the opposite order, otherwise you might run into a memory leak. + .layer(NewSentryLayer::>::new_from_top()) // Bind a new Hub per request, to ensure correct error <> request correlation + .layer(SentryHttpLayer::new().enable_transaction()), // Start a transaction (Sentry root span) for each request + ); + + tokio::runtime::Builder::new_multi_thread() + .enable_all() + .build()? + .block_on(async { + let listener = tokio::net::TcpListener::bind("127.0.0.1:3001") + .await + .unwrap(); + axum::serve(listener, app.into_make_service()) + .await + .unwrap(); + }); + + Ok(()) +} +``` + +## Verify + +The snippet above sets up a service that always panics, so you can test that everything is working as soon as you set it up. + +Send a request to the application. The panic will be captured by Sentry. + +```bash +curl http://localhost:3001/ +``` + + + +Learn more about manually capturing an error or message in our Usage documentation. + + + +To view and resolve the recorded error, log into [sentry.io](https://sentry.io) and select your project. Clicking on the error's title will open a page where you can see detailed information and mark it as resolved. \ No newline at end of file diff --git a/src/components/platformIcon.tsx b/src/components/platformIcon.tsx index 0470d9124b061e..b1c6516596c342 100644 --- a/src/components/platformIcon.tsx +++ b/src/components/platformIcon.tsx @@ -129,6 +129,7 @@ import SvelteSVG from 'platformicons/svg/svelte.svg'; import SwiftSVG from 'platformicons/svg/swift.svg'; import SymfonySVG from 'platformicons/svg/symfony.svg'; import TanstackSVG from 'platformicons/svg/tanstack.svg'; +import TokioSVG from 'platformicons/svg/tokio.svg'; import TornadoSVG from 'platformicons/svg/tornado.svg'; import TrytonSVG from 'platformicons/svg/tryton.svg'; import UnitySVG from 'platformicons/svg/unity.svg'; @@ -272,6 +273,7 @@ import SvelteSVGLarge from 'platformicons/svg_80x80/svelte.svg'; import SwiftSVGLarge from 'platformicons/svg_80x80/swift.svg'; import SymfonySVGLarge from 'platformicons/svg_80x80/symfony.svg'; import TanstackSVGLarge from 'platformicons/svg_80x80/tanstack.svg'; +import TokioSVGLarge from 'platformicons/svg_80x80/tokio.svg'; import TornadoSVGLarge from 'platformicons/svg_80x80/tornado.svg'; import TrytonSVGLarge from 'platformicons/svg_80x80/tryton.svg'; import UnitySVGLarge from 'platformicons/svg_80x80/unity.svg'; @@ -346,6 +348,10 @@ const formatToSVG = { sm: AwslambdaSVG, lg: AwslambdaSVGLarge, }, + axum: { + sm: TokioSVG, + lg: TokioSVGLarge, + }, 'azure-functions': { sm: AzurefunctionsSVG, lg: AzurefunctionsSVGLarge, @@ -1033,6 +1039,7 @@ export const PLATFORM_TO_ICON = { 'ruby-sinatra': 'sinatra', rust: 'rust', 'rust-actix-web': 'actix', + 'rust-axum': 'axum', scala: 'scala', stride3d: 'stride3d', sql: 'sql', From 0d8ce115637766c769ebc24e3a4a5a004d41c6df Mon Sep 17 00:00:00 2001 From: lcian Date: Fri, 23 May 2025 17:51:31 +0200 Subject: [PATCH 02/12] public dsn --- docs/platforms/rust/guides/axum/index.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/platforms/rust/guides/axum/index.mdx b/docs/platforms/rust/guides/axum/index.mdx index ca73ac3eac585d..f5a899b5333d74 100644 --- a/docs/platforms/rust/guides/axum/index.mdx +++ b/docs/platforms/rust/guides/axum/index.mdx @@ -45,10 +45,10 @@ async fn failing() -> () { fn main() -> io::Result<()> { let _guard = sentry::init(( - "https://6b76fb2a5dc1164849cd797b75b6d879@o447951.ingest.us.sentry.io/4508694563782656", + "___PUBLIC_DSN___", sentry::ClientOptions { release: sentry::release_name!(), - // Capture all traces. Set to a lower value in production. + // Capture all traces and spans. Set to a lower value in production. traces_sample_rate: 1.0, // Capture user IPs and potentially sensitive headers when using HTTP server integrations // see https://docs.sentry.io/platforms/rust/data-management/data-collected for more info From 7efb69cd38edb4cfa767886fe1909cab95cc8283 Mon Sep 17 00:00:00 2001 From: Lorenzo Cian Date: Fri, 23 May 2025 17:56:00 +0200 Subject: [PATCH 03/12] Update index.mdx --- docs/platforms/rust/guides/axum/index.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/platforms/rust/guides/axum/index.mdx b/docs/platforms/rust/guides/axum/index.mdx index f5a899b5333d74..427f716fc553ad 100644 --- a/docs/platforms/rust/guides/axum/index.mdx +++ b/docs/platforms/rust/guides/axum/index.mdx @@ -48,7 +48,7 @@ fn main() -> io::Result<()> { "___PUBLIC_DSN___", sentry::ClientOptions { release: sentry::release_name!(), - // Capture all traces and spans. Set to a lower value in production. + // Capture all traces and spans. Set to a lower value in production traces_sample_rate: 1.0, // Capture user IPs and potentially sensitive headers when using HTTP server integrations // see https://docs.sentry.io/platforms/rust/data-management/data-collected for more info @@ -59,7 +59,7 @@ fn main() -> io::Result<()> { let app = Router::new().route("/", get(failing)).layer( ServiceBuilder::new() - // If you're binding the layers directly on the `Router`, bind them in the opposite order, otherwise you might run into a memory leak. + // If you're binding the layers directly on the `Router`, bind them in the opposite order, otherwise you might run into a memory leak .layer(NewSentryLayer::>::new_from_top()) // Bind a new Hub per request, to ensure correct error <> request correlation .layer(SentryHttpLayer::new().enable_transaction()), // Start a transaction (Sentry root span) for each request ); @@ -96,4 +96,4 @@ Learn more about manually capturing an error or message in our -To view and resolve the recorded error, log into [sentry.io](https://sentry.io) and select your project. Clicking on the error's title will open a page where you can see detailed information and mark it as resolved. \ No newline at end of file +To view and resolve the recorded error, log into [sentry.io](https://sentry.io) and select your project. Clicking on the error's title will open a page where you can see detailed information and mark it as resolved. From 6ce41a5112121424e50e0e711336e29aabd132af Mon Sep 17 00:00:00 2001 From: lcian Date: Tue, 3 Jun 2025 11:24:32 +0200 Subject: [PATCH 04/12] trigger CI From 1dfba50b64b5726ad33878d02af2e295b594f77e Mon Sep 17 00:00:00 2001 From: Lorenzo Cian Date: Tue, 3 Jun 2025 11:26:37 +0200 Subject: [PATCH 05/12] Update index.mdx --- docs/platforms/rust/guides/axum/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/rust/guides/axum/index.mdx b/docs/platforms/rust/guides/axum/index.mdx index 427f716fc553ad..fa13b7ccdba45c 100644 --- a/docs/platforms/rust/guides/axum/index.mdx +++ b/docs/platforms/rust/guides/axum/index.mdx @@ -12,7 +12,7 @@ The integration actually supports any crate based on [`tower`](https://github.co ## Install -To add Sentry with the `axum` integration to your Rust project, just add a new dependency to your `Cargo.toml`: +To add Sentry with the `axum` integration to your Rust project, add a new dependency to your `Cargo.toml`: ```toml {filename:Cargo.toml} [dependencies] From 2c7652f8f42be68e80a75a4ec4f184e90915856a Mon Sep 17 00:00:00 2001 From: Lorenzo Cian Date: Sun, 22 Jun 2025 21:38:52 +0200 Subject: [PATCH 06/12] Update docs/platforms/rust/guides/axum/index.mdx Co-authored-by: Shannon Anahata --- docs/platforms/rust/guides/axum/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/rust/guides/axum/index.mdx b/docs/platforms/rust/guides/axum/index.mdx index fa13b7ccdba45c..7f39dbac7f8863 100644 --- a/docs/platforms/rust/guides/axum/index.mdx +++ b/docs/platforms/rust/guides/axum/index.mdx @@ -3,7 +3,7 @@ title: axum description: "Learn about monitoring your axum application with Sentry." --- -The Sentry SDK offers a middleware for the [`axum`](https://github.com/tokio-rs/axum) framework that supports: +The Sentry SDK offers a middleware for the [axum](https://github.com/tokio-rs/axum) framework that supports: - Reporting errors and panics with the correct request correlation. - Starting a [transaction](https://docs.sentry.io/concepts/key-terms/tracing/) for each request-response cycle. From 8371e4087577d1c12d4abb71c8c714517c877fe7 Mon Sep 17 00:00:00 2001 From: Lorenzo Cian Date: Sun, 22 Jun 2025 21:39:12 +0200 Subject: [PATCH 07/12] Update docs/platforms/rust/guides/axum/index.mdx Co-authored-by: Shannon Anahata --- docs/platforms/rust/guides/axum/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/rust/guides/axum/index.mdx b/docs/platforms/rust/guides/axum/index.mdx index 7f39dbac7f8863..1270aa15e871ce 100644 --- a/docs/platforms/rust/guides/axum/index.mdx +++ b/docs/platforms/rust/guides/axum/index.mdx @@ -6,7 +6,7 @@ description: "Learn about monitoring your axum application with Sentry." The Sentry SDK offers a middleware for the [axum](https://github.com/tokio-rs/axum) framework that supports: - Reporting errors and panics with the correct request correlation. -- Starting a [transaction](https://docs.sentry.io/concepts/key-terms/tracing/) for each request-response cycle. +- Starting a transaction for each request-response cycle. The integration actually supports any crate based on [`tower`](https://github.com/tower-rs/tower), not just `axum`. From a0a67c9ef5b513b80f41441e9614d38bc7a463df Mon Sep 17 00:00:00 2001 From: Lorenzo Cian Date: Sun, 22 Jun 2025 21:39:20 +0200 Subject: [PATCH 08/12] Update docs/platforms/rust/guides/axum/index.mdx Co-authored-by: Shannon Anahata --- docs/platforms/rust/guides/axum/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/rust/guides/axum/index.mdx b/docs/platforms/rust/guides/axum/index.mdx index 1270aa15e871ce..01646407bef205 100644 --- a/docs/platforms/rust/guides/axum/index.mdx +++ b/docs/platforms/rust/guides/axum/index.mdx @@ -8,7 +8,7 @@ The Sentry SDK offers a middleware for the [axum](https://github.com/tokio-rs/ax - Reporting errors and panics with the correct request correlation. - Starting a transaction for each request-response cycle. -The integration actually supports any crate based on [`tower`](https://github.com/tower-rs/tower), not just `axum`. +The integration actually supports any crate based on [tower](https://github.com/tower-rs/tower), not just `axum`. ## Install From 81b0f0ecf7067d30e147ded01247d1c1e001d892 Mon Sep 17 00:00:00 2001 From: lcian Date: Sun, 22 Jun 2025 22:18:37 +0200 Subject: [PATCH 09/12] update --- docs/platforms/rust/guides/axum/index.mdx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/docs/platforms/rust/guides/axum/index.mdx b/docs/platforms/rust/guides/axum/index.mdx index 01646407bef205..cadcf772eae010 100644 --- a/docs/platforms/rust/guides/axum/index.mdx +++ b/docs/platforms/rust/guides/axum/index.mdx @@ -12,9 +12,13 @@ The integration actually supports any crate based on [tower](https://github.com/ ## Install + + To add Sentry with the `axum` integration to your Rust project, add a new dependency to your `Cargo.toml`: -```toml {filename:Cargo.toml} +```toml {filename:Cargo.toml} [dependencies] axum = "0.8.4" tower = "0.5.2" @@ -27,6 +31,8 @@ sentry = { version = "{{@inject packages.version('sentry.rust') }}", features = Initialize and configure the Sentry client. This will enable a set of default integrations, such as panic reporting. Then, initialize `axum` with the Sentry middleware. +This snippet sets up a service that always panics, so you can test that everything is working as soon as you set it up. + Macros like `#[tokio::main]` are not supported. The Sentry client must be initialized before the async runtime is started, as shown below. @@ -48,8 +54,10 @@ fn main() -> io::Result<()> { "___PUBLIC_DSN___", sentry::ClientOptions { release: sentry::release_name!(), + # ___PRODUCT_OPTION_START___ performance // Capture all traces and spans. Set to a lower value in production traces_sample_rate: 1.0, + # ___PRODUCT_OPTION_END___ performance // Capture user IPs and potentially sensitive headers when using HTTP server integrations // see https://docs.sentry.io/platforms/rust/data-management/data-collected for more info send_default_pii: true, @@ -61,7 +69,9 @@ fn main() -> io::Result<()> { ServiceBuilder::new() // If you're binding the layers directly on the `Router`, bind them in the opposite order, otherwise you might run into a memory leak .layer(NewSentryLayer::>::new_from_top()) // Bind a new Hub per request, to ensure correct error <> request correlation + # ___PRODUCT_OPTION_START___ performance .layer(SentryHttpLayer::new().enable_transaction()), // Start a transaction (Sentry root span) for each request + # ___PRODUCT_OPTION_END___ performance ); tokio::runtime::Builder::new_multi_thread() @@ -82,8 +92,6 @@ fn main() -> io::Result<()> { ## Verify -The snippet above sets up a service that always panics, so you can test that everything is working as soon as you set it up. - Send a request to the application. The panic will be captured by Sentry. ```bash @@ -96,4 +104,4 @@ Learn more about manually capturing an error or message in our -To view and resolve the recorded error, log into [sentry.io](https://sentry.io) and select your project. Clicking on the error's title will open a page where you can see detailed information and mark it as resolved. +To view and resolve the recorded error, log into [sentry.io](https://sentry.io) and select your project. Select Issues, and then Errors & Outages in the sidebar, where you will find the newly created issue. Clicking on the issue's title will open a page where you can see detailed information and mark it as resolved. From efea63c928b6c2e06bfb9373b362e0515c0ee249 Mon Sep 17 00:00:00 2001 From: lcian Date: Sun, 22 Jun 2025 22:19:11 +0200 Subject: [PATCH 10/12] update --- docs/platforms/rust/guides/axum/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/rust/guides/axum/index.mdx b/docs/platforms/rust/guides/axum/index.mdx index cadcf772eae010..18a39b7d9f64eb 100644 --- a/docs/platforms/rust/guides/axum/index.mdx +++ b/docs/platforms/rust/guides/axum/index.mdx @@ -104,4 +104,4 @@ Learn more about manually capturing an error or message in our -To view and resolve the recorded error, log into [sentry.io](https://sentry.io) and select your project. Select Issues, and then Errors & Outages in the sidebar, where you will find the newly created issue. Clicking on the issue's title will open a page where you can see detailed information and mark it as resolved. +To view and resolve the recorded panic, log into [sentry.io](https://sentry.io) and select your project. Select Issues, and then Errors & Outages in the sidebar, where you will find the newly created issue. Clicking on the issue's title will open a page where you can see detailed information and mark it as resolved. From 06f157f6cd1fcf32fdbe3dc2a6f4c8e7fb61e5a3 Mon Sep 17 00:00:00 2001 From: Lorenzo Cian Date: Mon, 23 Jun 2025 13:21:07 +0200 Subject: [PATCH 11/12] Update index.mdx --- docs/platforms/rust/guides/axum/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/rust/guides/axum/index.mdx b/docs/platforms/rust/guides/axum/index.mdx index 18a39b7d9f64eb..f21765dff02758 100644 --- a/docs/platforms/rust/guides/axum/index.mdx +++ b/docs/platforms/rust/guides/axum/index.mdx @@ -6,7 +6,7 @@ description: "Learn about monitoring your axum application with Sentry." The Sentry SDK offers a middleware for the [axum](https://github.com/tokio-rs/axum) framework that supports: - Reporting errors and panics with the correct request correlation. -- Starting a transaction for each request-response cycle. +- Starting a [transaction](/concepts/key-terms/tracing/) for each request-response cycle. The integration actually supports any crate based on [tower](https://github.com/tower-rs/tower), not just `axum`. From b53d849774bedcd72714345f33e6f32a7d542b96 Mon Sep 17 00:00:00 2001 From: lcian Date: Thu, 3 Jul 2025 16:05:00 +0200 Subject: [PATCH 12/12] improve --- docs/platforms/rust/guides/axum/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/rust/guides/axum/index.mdx b/docs/platforms/rust/guides/axum/index.mdx index f21765dff02758..f045e23454db0b 100644 --- a/docs/platforms/rust/guides/axum/index.mdx +++ b/docs/platforms/rust/guides/axum/index.mdx @@ -67,10 +67,10 @@ fn main() -> io::Result<()> { let app = Router::new().route("/", get(failing)).layer( ServiceBuilder::new() - // If you're binding the layers directly on the `Router`, bind them in the opposite order, otherwise you might run into a memory leak .layer(NewSentryLayer::>::new_from_top()) // Bind a new Hub per request, to ensure correct error <> request correlation # ___PRODUCT_OPTION_START___ performance .layer(SentryHttpLayer::new().enable_transaction()), // Start a transaction (Sentry root span) for each request + // If you're binding the layers directly on the `Router`, bind them in the opposite order, otherwise you might run into a memory leak # ___PRODUCT_OPTION_END___ performance );