From c11aa8c8c7b826fffcd36a11e52bb1fff6c381ee Mon Sep 17 00:00:00 2001 From: lcian Date: Sun, 22 Jun 2025 23:13:20 +0200 Subject: [PATCH 1/3] feat(rust): add getting started docs for tracing --- docs/platforms/rust/guides/tracing/config.yml | 1 + docs/platforms/rust/guides/tracing/index.mdx | 105 ++++++++++++++++++ src/components/platformIcon.tsx | 7 ++ 3 files changed, 113 insertions(+) create mode 100644 docs/platforms/rust/guides/tracing/config.yml create mode 100644 docs/platforms/rust/guides/tracing/index.mdx diff --git a/docs/platforms/rust/guides/tracing/config.yml b/docs/platforms/rust/guides/tracing/config.yml new file mode 100644 index 0000000000000..3b078316ccf90 --- /dev/null +++ b/docs/platforms/rust/guides/tracing/config.yml @@ -0,0 +1 @@ +title: tracing \ No newline at end of file diff --git a/docs/platforms/rust/guides/tracing/index.mdx b/docs/platforms/rust/guides/tracing/index.mdx new file mode 100644 index 0000000000000..63dae5dc0dd9d --- /dev/null +++ b/docs/platforms/rust/guides/tracing/index.mdx @@ -0,0 +1,105 @@ +--- +title: tracing +description: "Learn about monitoring your Rust application with Sentry's tracing integration." +--- + +The Sentry SDK offers an integration for tokio's [tracing](https://github.com/tokio-rs/tracing) ecosystem that supports: + +- Reporting `tracing` events to Sentry as events, breadcrumbs, or logs. +- Reporting `tracing` spans to Sentry. +- Reporting errors and panics with the correct trace correlation. + +## Install + + + +To add Sentry with the `tracing` integration to your Rust project, add the necessary dependencies to your `Cargo.toml`: + +```toml {filename:Cargo.toml} +[dependencies] +tracing = "0.1.41" +tracing-subscriber = "0.3.19" +sentry = { version = "{{@inject packages.version('sentry.rust') }}", features = [ + "tracing", + # ___PRODUCT_OPTION_START___ logs + "logs", + # ___PRODUCT_OPTION_END___ logs +] } +``` + +## Configure + +Initialize the Sentry SDK and register the Sentry layer to start sending `tracing` events and spans to Sentry: + +```rust +use tracing_subscriber::prelude::*; + +fn main() { + // Initialize Sentry + let _guard = sentry::init(( + "___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 + # ___PRODUCT_OPTION_START___ logs + enable_logs:true + # ___PRODUCT_OPTION_END___ logs + ..sentry::ClientOptions::default() + }, + }); + + // Register the Sentry tracing layer + tracing_subscriber::registry() + .with(tracing_subscriber::fmt::layer()) + .with(sentry_layer) + .init(); + + // Futures need to be bound to a Hub + // Learn more at https://docs.rs/sentry-core/latest/sentry_core/#parallelism-concurrency-and-async + fail().bind_hub(sentry::Hub::current()).await; +} + +# ___PRODUCT_OPTION_START___ performance +#[tracing::instrument] // Captures a root span (transaction) around this function execution +# ___PRODUCT_OPTION_END___ performance +async fn fail() { + # ___PRODUCT_OPTION_START___ performance + let _span = tracing::info_span("Child span").entered(); // Captures a child span + # ___PRODUCT_OPTION_END___ performance + tracing::error!("Everything is on fire!"); +} +``` + +{/* ___PRODUCT_OPTION_START___ logs */} + +To capture logs for `tracing` events, you need to set up a custom event filter, like so: + +```rs +use sentry::integrations::tracing::EventFilter; + +sentry::integrations::tracing::layer().event_filter(|md| match *md.level() { + // Capture error level events as Sentry events + tracing::Level::ERROR => EventFilter::Event, + // Ignore trace level events, as they're too verbose + tracing::Level::TRACE => EventFilter::Ignore, + // Capture everything else as a structured log + _ => EventFilter::Log, +}); +``` + +{/* ___PRODUCT_OPTION_END___ logs */} + +## Verify + + + +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. 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. \ No newline at end of file diff --git a/src/components/platformIcon.tsx b/src/components/platformIcon.tsx index 0470d9124b061..9a384a42c38f9 100644 --- a/src/components/platformIcon.tsx +++ b/src/components/platformIcon.tsx @@ -130,6 +130,7 @@ import SwiftSVG from 'platformicons/svg/swift.svg'; import SymfonySVG from 'platformicons/svg/symfony.svg'; import TanstackSVG from 'platformicons/svg/tanstack.svg'; import TornadoSVG from 'platformicons/svg/tornado.svg'; +import TracingSVG from 'platformicons/svg/tracing.svg'; import TrytonSVG from 'platformicons/svg/tryton.svg'; import UnitySVG from 'platformicons/svg/unity.svg'; import UnoSVG from 'platformicons/svg/uno.svg'; @@ -273,6 +274,7 @@ 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 TornadoSVGLarge from 'platformicons/svg_80x80/tornado.svg'; +import TracingSVGLarge from 'platformicons/svg_80x80/tracing.svg'; import TrytonSVGLarge from 'platformicons/svg_80x80/tryton.svg'; import UnitySVGLarge from 'platformicons/svg_80x80/unity.svg'; import UnoSVGLarge from 'platformicons/svg_80x80/uno.svg'; @@ -819,6 +821,10 @@ const formatToSVG = { sm: TornadoSVG, lg: TornadoSVGLarge, }, + tracing: { + sm: TracingSVG, + lg: TracingSVGLarge, + }, tryton: { sm: TrytonSVG, lg: TrytonSVGLarge, @@ -1033,6 +1039,7 @@ export const PLATFORM_TO_ICON = { 'ruby-sinatra': 'sinatra', rust: 'rust', 'rust-actix-web': 'actix', + 'rust-tracing': 'tracing', scala: 'scala', stride3d: 'stride3d', sql: 'sql', From ab9268f5472237acce216222cf4423925bd9af3c Mon Sep 17 00:00:00 2001 From: lcian Date: Thu, 7 Aug 2025 11:30:34 +0200 Subject: [PATCH 2/3] feat(rust): add getting started docs for tracing --- docs/platforms/rust/guides/tracing/index.mdx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/platforms/rust/guides/tracing/index.mdx b/docs/platforms/rust/guides/tracing/index.mdx index 63dae5dc0dd9d..6215fbff48bea 100644 --- a/docs/platforms/rust/guides/tracing/index.mdx +++ b/docs/platforms/rust/guides/tracing/index.mdx @@ -59,7 +59,7 @@ fn main() { .with(sentry_layer) .init(); - // Futures need to be bound to a Hub + // Futures should to be bound to a Hub // Learn more at https://docs.rs/sentry-core/latest/sentry_core/#parallelism-concurrency-and-async fail().bind_hub(sentry::Hub::current()).await; } @@ -68,6 +68,7 @@ fn main() { #[tracing::instrument] // Captures a root span (transaction) around this function execution # ___PRODUCT_OPTION_END___ performance 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 @@ -75,11 +76,13 @@ async fn fail() { } ``` +By default, error level events are captured as Sentry events, while anything at or above info is added as a breadcrumb. + {/* ___PRODUCT_OPTION_START___ logs */} -To capture logs for `tracing` events, you need to set up a custom event filter, like so: +To capture structured logs for `tracing` events instead, you need to set up the Sentry layer with a custom event filter that maps to logs, like so: -```rs +```rust use sentry::integrations::tracing::EventFilter; sentry::integrations::tracing::layer().event_filter(|md| match *md.level() { From de9699d44d7aa4f34aa5f329d43f94a43dccd852 Mon Sep 17 00:00:00 2001 From: lcian Date: Thu, 7 Aug 2025 12:59:54 +0200 Subject: [PATCH 3/3] improve --- docs/platforms/rust/guides/tracing/index.mdx | 22 +++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/docs/platforms/rust/guides/tracing/index.mdx b/docs/platforms/rust/guides/tracing/index.mdx index 6215fbff48bea..a451fec007b97 100644 --- a/docs/platforms/rust/guides/tracing/index.mdx +++ b/docs/platforms/rust/guides/tracing/index.mdx @@ -27,12 +27,19 @@ sentry = { version = "{{@inject packages.version('sentry.rust') }}", features = "logs", # ___PRODUCT_OPTION_END___ logs ] } +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: + + +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. + + + ```rust use tracing_subscriber::prelude::*; @@ -56,12 +63,17 @@ fn main() { // Register the Sentry tracing layer tracing_subscriber::registry() .with(tracing_subscriber::fmt::layer()) - .with(sentry_layer) + .with(sentry::integrations::tracing::layer()) .init(); - - // Futures should to be bound to a Hub - // Learn more at https://docs.rs/sentry-core/latest/sentry_core/#parallelism-concurrency-and-async - fail().bind_hub(sentry::Hub::current()).await; + + tokio::runtime::Builder::new_multi_thread() + .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 + fail().bind_hub(sentry::Hub::current()).await; + }); } # ___PRODUCT_OPTION_START___ performance