You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/platforms/rust/common/logs/index.mdx
+13-42Lines changed: 13 additions & 42 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,22 +19,13 @@ sentry = { version = "{{@inject packages.version('sentry.rust') }}", features =
19
19
20
20
## Setup
21
21
22
-
To enable logging, you need to initialize the SDK with the `enable_logs` option set to `true`.
23
-
24
-
```rust
25
-
let_guard=sentry::init((
26
-
"___PUBLIC_DSN___",
27
-
sentry::ClientOptions {
28
-
release:sentry::release_name!(),
29
-
enable_logs:true,
30
-
..Default::default()
31
-
}
32
-
));
33
-
```
22
+
To enable logging, just add the `sentry` dependency with the `logs` feature flag.
23
+
This will set `enable_logs: true` by default in your `sentry::ClientOptions`.
24
+
You can opt-out from sending logs even while using the `logs` feature flag by explicitly initializing the SDK with `enable_logs: false`.
34
25
35
26
## Usage
36
27
37
-
Once the feature is enabled on the SDK and the SDK is initialized, you can send logs by using the logging macros.
28
+
Once the feature is enabled and the SDK is initialized, you can send logs by using the logging macros.
38
29
The `sentry` crate exposes macros that support six different log levels:
39
30
`logger_trace`, `logger_debug`, `logger_info`, `logger_warn`, `logger_error` and `logger_fatal`.
40
31
The macros support logging a simple message, or a message with parameters, with `format` syntax:
@@ -81,7 +72,6 @@ tracing = "0.1.41"
81
72
tracing-subscriber = "0.3.19"
82
73
```
83
74
84
-
Initialize the SDK with `enable_logs` set to `true`, and configure the `tracing` subscriber to map `tracing` events to logs based on metadata such as severity.
85
75
Then, use standard `tracing` macros to capture logs.
// Ignore trace level events, as they're too verbose
143
125
tracing::Level::TRACE=>EventFilter::Ignore,
144
-
// Capture everything else just as a log
145
-
_=>EventFilter::Log,
126
+
// Capture everything else as both a breadcrumb and a log
127
+
_=>EventFilter::Breadcrumb|EventFilter::Log,
146
128
});
147
129
```
148
130
@@ -158,7 +140,6 @@ log = "0.4"
158
140
env_logger = "0.11"
159
141
```
160
142
161
-
Initialize the SDK with `enable_logs` set to `true`, and configure the `log` integration to map `log` records to logs based on metadata such as severity.
Copy file name to clipboardExpand all lines: docs/platforms/rust/guides/tracing/index.mdx
+14-10Lines changed: 14 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -88,21 +88,25 @@ async fn fail() {
88
88
}
89
89
```
90
90
91
-
By default, errorlevel events from `tokio-rs/tracing` are captured as Sentry events, while anything at or above info is added as a breadcrumb.
91
+
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.
92
92
93
-
To capture structured logs from `tokio-rs/tracing` events instead, you need to pass `enable_logs: true` to `sentry::init`, and set up the Sentry layer with a custom event filter that maps to logs, like so:
93
+
Additionally, if the `logs` feature flag of the `sentry` crate is enabled and the SDK is initialized with `enable_logs: true`, then events from `tracing` at info level or above are also captured as [structured logs](https://docs.sentry.io/product/explore/logs/).
94
+
95
+
This behavior can be customized by applying a custom `event_filter` when creating the layer.
96
+
The following snippet shows the default `event_filter` that's applied when using the `sentry` crate with the `logs` feature flag.
0 commit comments