From 9f771de58f02a76a7eb836f684efafd241174cc2 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Wed, 14 Oct 2026 22:08:11 +0000 Subject: [PATCH 1/2] feat(docs): Apply new quick start template to Rust quick start guides Co-Authored-By: Shannon Anahata --- docs/platforms/rust/guides/axum/index.mdx | 94 +++++++++++----- docs/platforms/rust/guides/tracing/index.mdx | 112 +++++++++++-------- 2 files changed, 131 insertions(+), 75 deletions(-) diff --git a/docs/platforms/rust/guides/axum/index.mdx b/docs/platforms/rust/guides/axum/index.mdx index 8bfa36ac49009..d615e7ddd7911 100644 --- a/docs/platforms/rust/guides/axum/index.mdx +++ b/docs/platforms/rust/guides/axum/index.mdx @@ -1,20 +1,18 @@ --- title: axum -description: "Learn about monitoring your axum application with Sentry." +description: "Learn how to set up Sentry in your Axum application and capture your first events." --- -The Sentry SDK offers a middleware for the [axum](https://github.com/tokio-rs/axum) framework that supports: +The Sentry SDK offers 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](/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`. +The integration also 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, add a new dependency to your `Cargo.toml`: +Add Sentry with the `axum` integration to your `Cargo.toml`: ```toml {filename:Cargo.toml} [dependencies] @@ -26,25 +24,32 @@ sentry = { version = "{{@inject packages.version('sentry.rust') }}", features = ## 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. +**Error Monitoring** starts working as soon as you call `sentry::init()`. **Logs** are supported in Rust SDK 0.42.0 and later and enabled by default. **Application Metrics** are available in Rust SDK 0.48.0 and later; both are covered in [Send Logs](#send-logs) and [Send Application Metrics](#send-application-metrics-). +This guide also enables **Tracing**. -This snippet sets up a service that always panics, so you can test that everything is working as soon as you set it up. +Initialize Sentry before starting the async runtime, then add the Sentry middleware to your Axum app. The example route panics so you can verify the setup in the next step. -Macros like `#[tokio::main]` are not supported. The Sentry client must be initialized before the async runtime is started, as shown below. +Macros like `#[tokio::main]` are not supported. Initialize the Sentry client before starting the async runtime, as shown below. +The snippet also turns on: + +- Tracing: via `traces_sample_rate` and `SentryHttpLayer::enable_transaction()`. +- User IP and HTTP header collection: via `send_default_pii`. Review the data your app sends before enabling this in production. + +Don't need a feature? Remove its options from the snippet. + ```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!") +async fn failing() { + panic!("Everything is on fire!"); } fn main() -> io::Result<()> { @@ -52,22 +57,18 @@ fn main() -> io::Result<()> { sentry::ClientOptions::new() .dsn("___PUBLIC_DSN___") .maybe_release(sentry::release_name!()) - # ___PRODUCT_OPTION_START___ performance - // Capture all traces and spans. Set to a lower value in production + // Enables Tracing. + // Set to 1.0 to capture 100% of spans for tracing. + // We recommend reducing this 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 + // Capture user IPs and potentially sensitive headers for HTTP server integrations. .send_default_pii(true), ); let app = Router::new().route("/", get(failing)).layer( ServiceBuilder::new() - .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 + .layer(NewSentryLayer::>::new_from_top()) + .layer(SentryHttpLayer::new().enable_transaction()), ); tokio::runtime::Builder::new_multi_thread() @@ -86,22 +87,53 @@ fn main() -> io::Result<()> { } ``` -## Verify +### Instrument Axum -Send a request to the application. The panic will be captured by Sentry. +`NewSentryLayer` binds a Hub to each request so Sentry can associate errors with the correct request. `SentryHttpLayer::enable_transaction()` starts a transaction for each request. -```bash -curl http://localhost:3001/ +If you bind the layers directly to the `Router`, apply them in the opposite order to avoid a memory leak. + +## Send Logs + +Use Sentry's `logger_*` macros to send logs at different levels. Logs are supported in Rust SDK 0.42.0 and later and enabled by default unless you compile the SDK without default features. For logging through the `tracing` or `log` crates, see the `tracing` integration and `log` integration guides. + +See Set Up Logs for all available logging methods and configuration options. + +```rust +use sentry::logger_info; + +logger_info!("Order processed"); ``` - +## Send Application Metrics -Learn more about manually capturing an error or message in our Usage documentation. +Use `sentry::metrics` to send counters, gauges, and distributions. Metrics require Rust SDK 0.48.0 or later and are enabled by default in the `sentry` crate. - +See Set Up Metrics for all available metric types and configuration options. -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. +```rust +use sentry::metrics; + +metrics::counter("checkout.failed", 1).capture(); +metrics::gauge("active_connections", 42).capture(); +``` + +## Verify Your Setup + +Send a request to the application. The route panics, and Sentry captures the error. + +```bash +curl http://localhost:3001/ +``` + +### View Captured Data in Sentry + +To view and resolve the recorded panic, log into [sentry.io](https://sentry.io) and select your project. Select **Issues** in the sidebar to find the new issue. ## Next Steps -- Explore [practical guides](/get-started/guides/) on what to monitor, log, track, and investigate after setup +At this point, you should have integrated Sentry into your Axum application. Here's what to explore next: + +- Explore [practical guides](/get-started/guides/) on what to monitor, log, track, and investigate after setup. +- Learn how to [manually capture errors](/platforms/rust/usage/). +- Instrument more operations with [custom tracing](/platforms/rust/tracing/instrumentation/custom-instrumentation/). diff --git a/docs/platforms/rust/guides/tracing/index.mdx b/docs/platforms/rust/guides/tracing/index.mdx index e3584f8578a6d..8e22ea195069a 100644 --- a/docs/platforms/rust/guides/tracing/index.mdx +++ b/docs/platforms/rust/guides/tracing/index.mdx @@ -1,6 +1,6 @@ --- title: tokio-rs/tracing -description: "Learn about monitoring your Rust application with Sentry's tokio-rs/tracing integration." +description: "Learn how to set up Sentry in your Rust application and capture your first events with the tokio-rs/tracing integration." --- The Sentry SDK offers an integration for tokio's [tracing](https://github.com/tokio-rs/tracing) ecosystem that supports: @@ -11,48 +11,49 @@ The Sentry SDK offers an integration for tokio's [tracing](https://github.com/to ## Install - - -To add Sentry with the `tracing` integration to your Rust project, add the necessary dependencies to your `Cargo.toml`: +Add Sentry and the `tracing` dependencies to your `Cargo.toml`. The `tracing` feature enables the Sentry tracing integration. ```toml {filename:Cargo.toml} [dependencies] tracing = "0.1.41" tracing-subscriber = "0.3.19" -sentry = { version = "{{@inject packages.version('sentry.rust') }}", features = [ - "tracing" -] } +sentry = { version = "{{@inject packages.version('sentry.rust') }}", features = ["tracing"] } tokio = { version = "1.45.0", features = ["full"] } ``` ## Configure -Initialize the Sentry SDK and register the Sentry layer to start sending `tracing` events and spans to Sentry: +**Error Monitoring** starts working as soon as you call `sentry::init()`. **Logs** are supported in Rust SDK 0.42.0 and later and enabled by default. **Application Metrics** are available in Rust SDK 0.48.0 and later; both are covered in [Send Logs](#send-logs) and [Send Application Metrics](#send-application-metrics-). +This guide also enables **Tracing**. + +Initialize Sentry before starting the async runtime, then register the Sentry tracing layer with `tracing_subscriber`. -Macros like `#[tokio::main]` and `#[actix_web::main]` are not supported. The Sentry client must be initialized before the async runtime is started, as shown below. +Macros like `#[tokio::main]` and `#[actix_web::main]` are not supported. Initialize the Sentry client before starting the async runtime, as shown below. -```rust +The snippet also turns on: + +- Tracing: via `traces_sample_rate`. + +Don't need a feature? Remove its options from the snippet. + +```rust {filename:main.rs} use tracing_subscriber::prelude::*; -fn main() { - // Initialize Sentry +fn main() -> Result<(), Box> { let _guard = sentry::init( sentry::ClientOptions::new() .dsn("___PUBLIC_DSN___") .maybe_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 + // Enables Tracing. + // Set to 1.0 to capture 100% of spans for tracing. + // We recommend reducing this value in production. + .traces_sample_rate(1.0), ); - // Register the Sentry tracing layer tracing_subscriber::registry() .with(tracing_subscriber::fmt::layer()) .with(sentry::integrations::tracing::layer()) @@ -62,59 +63,82 @@ fn main() { .enable_all() .build()? .block_on(async { - // Futures should to be bound to a Hub - // Learn more at https://docs.rs/sentry-core/latest/sentry_core/#parallelism-concurrency-and-async + // Bind async work to the current Sentry Hub. fail().bind_hub(sentry::Hub::current()).await; }); + + Ok(()) } -# ___PRODUCT_OPTION_START___ performance -#[tracing::instrument] // Captures a root span (transaction) around this function execution -# ___PRODUCT_OPTION_END___ performance +#[tracing::instrument] async fn fail() { - tracing::debug!("Doing work"); // Adds a breadrcumb - # ___PRODUCT_OPTION_START___ performance - let _span = tracing::info_span("Child span").entered(); // Captures a child span - # ___PRODUCT_OPTION_END___ performance + tracing::debug!("Doing work"); + let _span = tracing::info_span!("Child span").entered(); tracing::error!("Everything is on fire!"); } ``` -By default, error-level events from `tracing` are captured as Sentry events, while events at or above info level are added to the current scope as breadcrumbs. +By default, error-level events from `tracing` are captured as Sentry events, and events at or above info level are added to the current scope as breadcrumbs. Events at or above info level are also captured as Sentry logs unless logs are disabled when initializing the SDK. -Additionally, the SDK captures [logs](https://docs.sentry.io/product/logs/) for `tracing` events at the info level or above, unless logs were disabled when initializing the SDK. +### Customize Tracing Event Capture -This behavior can be customized by applying a custom `event_filter` when creating the layer. -The following snippet shows the default `event_filter` that's applied when using the `sentry` crate with the `tracing` feature flag. +You can customize how `tracing` events are sent by setting an `event_filter` on the Sentry layer. This example shows the default filter used with the `tracing` feature: ```rust use sentry::integrations::tracing::EventFilter; let sentry_layer = - sentry::integrations::tracing::layer().event_filter(|md| match *md.level() { - // Capture error and warn level events as both logs and events in Sentry + sentry::integrations::tracing::layer().event_filter(|metadata| match *metadata.level() { + // Capture error and warn events as both logs and events. tracing::Level::ERROR => EventFilter::Event | EventFilter::Log, - // Ignore trace level events, as they're too verbose + // Ignore trace events because they're too verbose. tracing::Level::TRACE => EventFilter::Ignore, - // Capture everything else as both a breadcrumb and a log + // Capture other events as both breadcrumbs and logs. _ => EventFilter::Breadcrumb | EventFilter::Log, }); ``` -## Verify +## Send Logs - +The Sentry tracing layer sends `tracing` events at info level and above as logs by default. Use the `tracing` integration to add log fields as searchable attributes. The Rust SDK also supports the `log` integration with the `log` feature enabled on `sentry`. -Learn more about manually capturing an error or message in our Usage documentation. +See Set Up Logs for all available logging methods and configuration options. - +```rust +tracing::info!(order_id = "order-123", "Order processed"); +tracing::error!(reason = "invalid email", "Validation failed"); +``` + +## Send Application Metrics -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. +Use `sentry::metrics` to send counters, gauges, and distributions. Metrics require Rust SDK 0.48.0 or later and are enabled by default in the `sentry` crate. -If you're using tracing (the Sentry feature), you can view the recorded traces and spans by selecting Explore, and then Traces in the sidebar. +See Set Up Metrics for all available metric types and configuration options. -If you're using logs, you can view the recorded logs by selecting Explore, and then Logs in the sidebar. +```rust +use sentry::metrics; + +metrics::counter("checkout.failed", 1).capture(); +metrics::gauge("active_connections", 42).capture(); +metrics::distribution("api_latency", 187.0).capture(); +``` + +## Verify Your Setup + +Send an error-level event to confirm that Sentry captures an event: + +```rust +tracing::error!("Sentry test event"); +``` + +### View Captured Data in Sentry + +To view the recorded event, log into [sentry.io](https://sentry.io) and select your project. Select **Issues** in the sidebar to find it. You can view traces in **Explore** > **Traces**, and captured logs in **Explore** > **Logs**. ## Next Steps -- Explore [practical guides](/get-started/guides/) on what to monitor, log, track, and investigate after setup +At this point, you should have integrated Sentry into your Rust application. Here's what to explore next: + +- Explore [practical guides](/get-started/guides/) on what to monitor, log, track, and investigate after setup. +- Learn how to [manually capture errors](/platforms/rust/usage/). +- Instrument more operations with [custom tracing](/platforms/rust/tracing/instrumentation/custom-instrumentation/). From bbd64209d84ddc761d906e6c41c5e648bbf219b0 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Thu, 15 Oct 2026 20:27:47 +0000 Subject: [PATCH 2/2] feat(docs): Apply new quick start template to Rust and Actix Web quick start guides Co-Authored-By: Shannon Anahata --- .../platforms/rust/guides/actix-web/index.mdx | 82 ++++++++--- docs/platforms/rust/index.mdx | 127 +++++++++++------- 2 files changed, 137 insertions(+), 72 deletions(-) diff --git a/docs/platforms/rust/guides/actix-web/index.mdx b/docs/platforms/rust/guides/actix-web/index.mdx index 1e2dab8681067..a2478bb988d4d 100644 --- a/docs/platforms/rust/guides/actix-web/index.mdx +++ b/docs/platforms/rust/guides/actix-web/index.mdx @@ -1,16 +1,16 @@ --- title: Actix Web -description: "Learn about monitoring your Actix Web application with Sentry." +description: "Learn how to set up Sentry in your Actix Web application and capture your first events." --- -The Sentry SDK offers a middleware for the [Actix Web](https://actix.rs/) framework that supports: +The Sentry SDK offers middleware for the [Actix Web](https://actix.rs/) framework that supports: - Capturing server errors returned by Actix Web services. - Starting a [transaction](/concepts/key-terms/tracing/) for each request-response cycle. ## Install -To add Sentry with the Actix Web integration to your Rust project, add a new dependency to your `Cargo.toml`: +Add Sentry with the `actix` integration to your `Cargo.toml`: ```toml {filename:Cargo.toml} [dependencies] @@ -20,16 +20,25 @@ sentry = { version = "{{@inject packages.version('sentry.rust') }}", features = ## Configure -Initialize and configure the Sentry client. This will enable a set of default integrations, such as panic reporting. -Then, initialize Actix Web with the Sentry middleware. -The Sentry middleware provides correct request and trace association for any captured errors or panics, so it should be the first to process the request, that means it should be the last in your chain of `wrap` calls. +**Error Monitoring** starts working as soon as you call `sentry::init()`. **Logs** are supported in Rust SDK 0.42.0 and later and enabled by default. **Application Metrics** are available in Rust SDK 0.48.0 and later; both are covered in [Send Logs](#send-logs) and [Send Application Metrics](#send-application-metrics-). +This guide also enables **Tracing**. + +Initialize Sentry before starting the async runtime, then add the Sentry middleware to your Actix Web app. The example route returns an error so you can verify the setup in the next step. -Macros like `#[tokio::main]` and `#[actix_web::main]` are not supported. The Sentry client must be initialized before the async runtime is started, as shown below. +Macros like `#[tokio::main]` and `#[actix_web::main]` are not supported. Initialize the Sentry client before starting the async runtime, as shown below. +The snippet also turns on: + +- Tracing: via `traces_sample_rate` and the middleware's `start_transaction(true)`. +- User IP and HTTP header collection: via `send_default_pii`. Review the data your app sends before enabling this in production. +- HTTP request body collection: via `max_request_body_size`. + +Don't need a feature? Remove its options from the snippet. + ```rust {filename:main.rs} use std::io; @@ -45,12 +54,14 @@ fn main() -> io::Result<()> { sentry::ClientOptions::new() .dsn("___PUBLIC_DSN___") .maybe_release(sentry::release_name!()) - // Capture all traces and spans. Set to a lower value in production + // Enables Tracing. + // Set to 1.0 to capture 100% of spans for tracing. + // We recommend reducing this 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 + // 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) - // Capture all HTTP request bodies, regardless of size + // Capture all HTTP request bodies, regardless of size. .max_request_body_size(sentry::MaxRequestBodySize::Always), ); @@ -74,24 +85,53 @@ fn main() -> io::Result<()> { } ``` -## Verify +### Instrument Actix Web -The snippet above sets up a service that always fails, so you can test that everything is working as soon as you set it up. +The Sentry middleware provides correct request and trace association for any captured errors or panics, so it should be the first to process the request. That means it should be the last in your chain of `wrap` calls. -Send a request to the application. The response error will be captured by Sentry. +`capture_server_errors(true)` reports server errors returned by your services to Sentry, and `start_transaction(true)` starts a transaction for each request. -```bash -curl http://localhost:3001/ +## Send Logs + +Use Sentry's `logger_*` macros to send logs at different levels. Logs are supported in Rust SDK 0.42.0 and later and enabled by default unless you compile the SDK without default features. In that case, enable the `logs` feature on `sentry`. For logging through the `tracing` or `log` crates, see the `tracing` integration and `log` integration guides. + +See Set Up Logs for all available logging methods and configuration options. + +```rust +use sentry::logger_info; + +logger_info!("Order processed"); ``` - +## Send Application Metrics -Learn more about manually capturing an error or message in our Usage documentation. +Use `sentry::metrics` to send counters, gauges, and distributions. Metrics require Rust SDK 0.48.0 or later and are enabled by default in the `sentry` crate. - +See Set Up Metrics for all available metric types and configuration options. -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. +```rust +use sentry::metrics; + +metrics::counter("checkout.failed", 1).capture(); +metrics::gauge("active_connections", 42).capture(); +``` + +## Verify Your Setup + +Send a request to the application. The route returns an error, and Sentry captures it. + +```bash +curl http://localhost:3001/ +``` + +### View Captured Data in Sentry + +To view and resolve the recorded error, log into [sentry.io](https://sentry.io) and select your project. Select **Issues** in the sidebar to find the new issue. ## Next Steps -- Explore [practical guides](/get-started/guides/) on what to monitor, log, track, and investigate after setup +At this point, you should have integrated Sentry into your Actix Web application. Here's what to explore next: + +- Explore [practical guides](/get-started/guides/) on what to monitor, log, track, and investigate after setup. +- Learn how to [manually capture errors](/platforms/rust/usage/). +- Instrument more operations with [custom tracing](/platforms/rust/tracing/instrumentation/custom-instrumentation/). diff --git a/docs/platforms/rust/index.mdx b/docs/platforms/rust/index.mdx index 91429a0d22be9..6bfff9ca8feee 100644 --- a/docs/platforms/rust/index.mdx +++ b/docs/platforms/rust/index.mdx @@ -31,26 +31,44 @@ sentry = "{{@inject packages.version('sentry.rust') }}" ## Configure -The most convenient way to use this library is the `sentry::init` function, which starts a Sentry client with a default set of integrations, and binds it to the current Hub. +**Error Monitoring** starts working as soon as you call `sentry::init()`. **Logs** are supported in Rust SDK 0.42.0 and later and enabled by default. **Application Metrics** are available in Rust SDK 0.48.0 and later; both are covered in [Send Logs](#send-logs) and [Send Application Metrics](#send-application-metrics-). +This guide also enables **Tracing**. -The `sentry::init` function returns a guard that when dropped, will flush Events that weren't yet sent to Sentry. It has a two-second deadline, so application shutdown may be slightly delayed as a result. Be sure to keep the guard or you won't be able to send events. +Call `sentry::init()` as early as possible in your `main` function. It starts a Sentry client with a default set of integrations, such as panic reporting, and binds it to the current Hub. + +`sentry::init()` returns a guard that flushes events that haven't been sent yet when it's dropped. The flush has a two-second deadline, so application shutdown may be slightly delayed. Keep the guard alive for as long as your app runs, or the SDK won't be able to send events. + +The snippet also turns on: + +- Tracing: via `traces_sample_rate`. +- User IP and HTTP header collection: via `send_default_pii`. Review the data your app sends before enabling this in production. + +Don't need a feature? Remove its options from the snippet. ```rust {filename:main.rs} -let _guard = sentry::init( - sentry::ClientOptions::new() - .dsn("___PUBLIC_DSN___") - .maybe_release(sentry::release_name!()) - // 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), -); +fn main() { + let _guard = sentry::init( + sentry::ClientOptions::new() + .dsn("___PUBLIC_DSN___") + .maybe_release(sentry::release_name!()) + // Enables Tracing. + // Set to 1.0 to capture 100% of spans for tracing. + // We recommend reducing this 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), + ); + + // implementation of main +} ``` **Important:** Remember your DSN. The DSN (Data Source Name) tells the SDK where to send events. If you forget it, you can find it by going to: Settings -> Projects -> [Client Keys (DSN)](https://sentry.io/orgredirect/organizations/:orgslug/settings/projects/:projectId/keys/) in sentry.io. ### Async Main Function -In a multithreaded application, spawned threads should inherit the Hub from the main thread. In order for that to happen, the Sentry client must be initialized before starting an async runtime or spawning threads. This means you'll have to avoid using macros such as `#[tokio::main]` or `#[actix_web::main]`, because they start the runtime first. So rather than doing this: +In a multithreaded application, spawned threads should inherit the Hub from the main thread. For that to happen, initialize the Sentry client before starting an async runtime or spawning threads. This means you'll have to avoid macros such as `#[tokio::main]` or `#[actix_web::main]`, because they start the runtime first. So rather than doing this: ```rust {filename:main.rs} // WRONG @@ -59,10 +77,7 @@ async fn main() { let _guard = sentry::init( sentry::ClientOptions::new() .dsn("___PUBLIC_DSN___") - .maybe_release(sentry::release_name!()) - // 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), + .maybe_release(sentry::release_name!()), ); // implementation of main @@ -77,10 +92,7 @@ fn main() { let _guard = sentry::init( sentry::ClientOptions::new() .dsn("___PUBLIC_DSN___") - .maybe_release(sentry::release_name!()) - // 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), + .maybe_release(sentry::release_name!()), ); tokio::runtime::Builder::new_multi_thread() @@ -93,33 +105,9 @@ fn main() { } ``` -## Verify Setup +### Integrations -The quickest way to verify Sentry in your Rust application is to cause a panic: - -```rust {filename:main.rs} -fn main() { - let _guard = sentry::init( - sentry::ClientOptions::new() - .dsn("___PUBLIC_DSN___") - .maybe_release(sentry::release_name!()) - // 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), - ); - - // Sentry will capture this - panic!("Everything is on fire!"); -} -``` - -## Integrations - -_Integrations_ extend the functionality of the SDK for some common frameworks -and libraries. - -A list of integrations and their feature flags can be found -[in the integration API docs](https://docs.rs/sentry/0/sentry/integrations/index.html). +_Integrations_ extend the functionality of the SDK for some common frameworks and libraries. A list of integrations and their feature flags can be found [in the integration API docs](https://docs.rs/sentry/0/sentry/integrations/index.html). @@ -131,13 +119,50 @@ Conflicts could lead to UI warning messages in Sentry, as it can be interpreted -## More Information +## Send Logs + +Use Sentry's `logger_*` macros to send logs at different levels. Logs are supported in Rust SDK 0.42.0 and later and enabled by default unless you compile the SDK without default features. In that case, enable the `logs` feature on `sentry`. For logging through the `tracing` or `log` crates, see the `tracing` integration and `log` integration guides. + +See Set Up Logs for all available logging methods and configuration options. + +```rust +use sentry::logger_info; + +logger_info!("Order processed"); +``` + +## Send Application Metrics -- [API Docs](https://docs.rs/sentry) -- [Crates.io page](https://crates.io/crates/sentry) -- [Bug Tracker](https://github.com/getsentry/sentry-rust/issues) -- [GitHub Project](https://github.com/getsentry/sentry-rust) +Use `sentry::metrics` to send counters, gauges, and distributions. Metrics require Rust SDK 0.48.0 or later and are enabled by default in the `sentry` crate. + +See Set Up Metrics for all available metric types and configuration options. + +```rust +use sentry::metrics; + +metrics::counter("checkout.failed", 1).capture(); +metrics::gauge("active_connections", 42).capture(); +metrics::distribution("api_latency", 187.0).capture(); +``` + +## Verify Your Setup + +The quickest way to verify Sentry in your Rust application is to cause a panic after initializing the SDK: + +```rust {filename:main.rs} +// Sentry will capture this +panic!("Everything is on fire!"); +``` + +### View Captured Data in Sentry + +To view and resolve the recorded panic, log into [sentry.io](https://sentry.io) and select your project. Select **Issues** in the sidebar to find the new issue. ## Next Steps -- Explore [practical guides](/get-started/guides/) on what to monitor, log, track, and investigate after setup +At this point, you should have integrated Sentry into your Rust application. Here's what to explore next: + +- Explore [practical guides](/get-started/guides/) on what to monitor, log, track, and investigate after setup. +- Learn how to [manually capture errors](/platforms/rust/usage/). +- Instrument more operations with [custom tracing](/platforms/rust/tracing/instrumentation/custom-instrumentation/). +- Browse the [API docs](https://docs.rs/sentry), the [crates.io page](https://crates.io/crates/sentry), and the [GitHub project](https://github.com/getsentry/sentry-rust). Report bugs in the [issue tracker](https://github.com/getsentry/sentry-rust/issues).