Skip to content

Commit ce9d739

Browse files
authored
feat(rust): document how to map a tracing event to multiple items (#14114)
1 parent 5cc62e8 commit ce9d739

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

docs/platforms/rust/common/logs/index.mdx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ fn main() {
103103

104104
let sentry_layer =
105105
sentry::integrations::tracing::layer().event_filter(|md| match *md.level() {
106-
// Capture error events as Sentry events
106+
// Capture error level events as Sentry events
107107
// These are grouped into issues, representing high-severity errors to act upon
108108
tracing::Level::ERROR => EventFilter::Event,
109109
// Ignore trace level events, as they're too verbose
@@ -132,6 +132,22 @@ fn main() {
132132

133133
The fields of `tracing` events are automatically captured as attributes in Sentry logs.
134134

135+
To map a `tracing` event to multiple items in Sentry (e.g. both an event and a log), combine multiple event filters using the bitwise or operator.
136+
137+
```rust
138+
use sentry::integrations::tracing::EventFilter;
139+
140+
let sentry_layer =
141+
sentry::integrations::tracing::layer().event_filter(|md| match *md.level() {
142+
// Capture error and warn level events as both logs and events in Sentry
143+
tracing::Level::ERROR | tracing::Level::WARN => EventFilter::Event | EventFilter::Log,
144+
// Ignore trace level events, as they're too verbose
145+
tracing::Level::TRACE => EventFilter::Ignore,
146+
// Capture everything else just as a log
147+
_ => EventFilter::Log,
148+
});
149+
```
150+
135151
### `log` Integration
136152

137153
To use the `log` integration with logs, add the necessary dependencies to your `Cargo.toml`.

0 commit comments

Comments
 (0)