Skip to content

Commit c11aa8c

Browse files
committed
feat(rust): add getting started docs for tracing
1 parent 23eae21 commit c11aa8c

File tree

3 files changed

+113
-0
lines changed

3 files changed

+113
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
title: tracing
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
---
2+
title: tracing
3+
description: "Learn about monitoring your Rust application with Sentry's tracing integration."
4+
---
5+
6+
The Sentry SDK offers an integration for tokio's [tracing](https://github.com/tokio-rs/tracing) ecosystem that supports:
7+
8+
- Reporting `tracing` events to Sentry as events, breadcrumbs, or logs.
9+
- Reporting `tracing` spans to Sentry.
10+
- Reporting errors and panics with the correct trace correlation.
11+
12+
## Install
13+
14+
<OnboardingOptionButtons
15+
options={["error-monitoring", "performance", "logs"]}
16+
/>
17+
18+
To add Sentry with the `tracing` integration to your Rust project, add the necessary dependencies to your `Cargo.toml`:
19+
20+
```toml {filename:Cargo.toml}
21+
[dependencies]
22+
tracing = "0.1.41"
23+
tracing-subscriber = "0.3.19"
24+
sentry = { version = "{{@inject packages.version('sentry.rust') }}", features = [
25+
"tracing",
26+
# ___PRODUCT_OPTION_START___ logs
27+
"logs",
28+
# ___PRODUCT_OPTION_END___ logs
29+
] }
30+
```
31+
32+
## Configure
33+
34+
Initialize the Sentry SDK and register the Sentry layer to start sending `tracing` events and spans to Sentry:
35+
36+
```rust
37+
use tracing_subscriber::prelude::*;
38+
39+
fn main() {
40+
// Initialize Sentry
41+
let _guard = sentry::init((
42+
"___PUBLIC_DSN___",
43+
sentry::ClientOptions {
44+
release: sentry::release_name!(),
45+
# ___PRODUCT_OPTION_START___ performance
46+
// Capture all traces and spans. Set to a lower value in production
47+
traces_sample_rate: 1.0,
48+
# ___PRODUCT_OPTION_END___ performance
49+
# ___PRODUCT_OPTION_START___ logs
50+
enable_logs:true
51+
# ___PRODUCT_OPTION_END___ logs
52+
..sentry::ClientOptions::default()
53+
},
54+
});
55+
56+
// Register the Sentry tracing layer
57+
tracing_subscriber::registry()
58+
.with(tracing_subscriber::fmt::layer())
59+
.with(sentry_layer)
60+
.init();
61+
62+
// Futures need to be bound to a Hub
63+
// Learn more at https://docs.rs/sentry-core/latest/sentry_core/#parallelism-concurrency-and-async
64+
fail().bind_hub(sentry::Hub::current()).await;
65+
}
66+
67+
# ___PRODUCT_OPTION_START___ performance
68+
#[tracing::instrument] // Captures a root span (transaction) around this function execution
69+
# ___PRODUCT_OPTION_END___ performance
70+
async fn fail() {
71+
# ___PRODUCT_OPTION_START___ performance
72+
let _span = tracing::info_span("Child span").entered(); // Captures a child span
73+
# ___PRODUCT_OPTION_END___ performance
74+
tracing::error!("Everything is on fire!");
75+
}
76+
```
77+
78+
{/* ___PRODUCT_OPTION_START___ logs */}
79+
80+
To capture logs for `tracing` events, you need to set up a custom event filter, like so:
81+
82+
```rs
83+
use sentry::integrations::tracing::EventFilter;
84+
85+
sentry::integrations::tracing::layer().event_filter(|md| match *md.level() {
86+
// Capture error level events as Sentry events
87+
tracing::Level::ERROR => EventFilter::Event,
88+
// Ignore trace level events, as they're too verbose
89+
tracing::Level::TRACE => EventFilter::Ignore,
90+
// Capture everything else as a structured log
91+
_ => EventFilter::Log,
92+
});
93+
```
94+
95+
{/* ___PRODUCT_OPTION_END___ logs */}
96+
97+
## Verify
98+
99+
<Alert>
100+
101+
Learn more about manually capturing an error or message in our <PlatformLink to="/usage/">Usage documentation</PlatformLink>.
102+
103+
</Alert>
104+
105+
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.

src/components/platformIcon.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ import SwiftSVG from 'platformicons/svg/swift.svg';
130130
import SymfonySVG from 'platformicons/svg/symfony.svg';
131131
import TanstackSVG from 'platformicons/svg/tanstack.svg';
132132
import TornadoSVG from 'platformicons/svg/tornado.svg';
133+
import TracingSVG from 'platformicons/svg/tracing.svg';
133134
import TrytonSVG from 'platformicons/svg/tryton.svg';
134135
import UnitySVG from 'platformicons/svg/unity.svg';
135136
import UnoSVG from 'platformicons/svg/uno.svg';
@@ -273,6 +274,7 @@ import SwiftSVGLarge from 'platformicons/svg_80x80/swift.svg';
273274
import SymfonySVGLarge from 'platformicons/svg_80x80/symfony.svg';
274275
import TanstackSVGLarge from 'platformicons/svg_80x80/tanstack.svg';
275276
import TornadoSVGLarge from 'platformicons/svg_80x80/tornado.svg';
277+
import TracingSVGLarge from 'platformicons/svg_80x80/tracing.svg';
276278
import TrytonSVGLarge from 'platformicons/svg_80x80/tryton.svg';
277279
import UnitySVGLarge from 'platformicons/svg_80x80/unity.svg';
278280
import UnoSVGLarge from 'platformicons/svg_80x80/uno.svg';
@@ -819,6 +821,10 @@ const formatToSVG = {
819821
sm: TornadoSVG,
820822
lg: TornadoSVGLarge,
821823
},
824+
tracing: {
825+
sm: TracingSVG,
826+
lg: TracingSVGLarge,
827+
},
822828
tryton: {
823829
sm: TrytonSVG,
824830
lg: TrytonSVGLarge,
@@ -1033,6 +1039,7 @@ export const PLATFORM_TO_ICON = {
10331039
'ruby-sinatra': 'sinatra',
10341040
rust: 'rust',
10351041
'rust-actix-web': 'actix',
1042+
'rust-tracing': 'tracing',
10361043
scala: 'scala',
10371044
stride3d: 'stride3d',
10381045
sql: 'sql',

0 commit comments

Comments
 (0)