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
@@ -69,11 +72,123 @@ As of today, array and object types will be converted to strings using their JSO
69
72
70
73
## Integrations
71
74
72
-
We're actively working on adding integration support for Logs.
73
-
Currently, we're looking at adding support for the `tracing` and `log` crates.
74
-
You can follow progress on the following GitHub issues or open a [new one](https://github.com/getsentry/sentry-rust/issues/new/choose) for any additional integration you would like to see.
To use the `tracing` integration with logs, add the necessary dependencies to your `Cargo.toml`.
78
+
79
+
```toml {filename:Cargo.toml}
80
+
[dependencies]
81
+
sentry = { version = "{{@inject packages.version('sentry.rust') }}", features = ["tracing", "logs"] }
82
+
tracing = "0.1.41"
83
+
tracing-subscriber = "0.3.19"
84
+
```
85
+
86
+
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.
87
+
Then, use standard `tracing` macros to capture logs.
// These are grouped into issues, representing high-severity errors to act upon
108
+
tracing::Level::ERROR=>EventFilter::Event,
109
+
// Ignore trace level events, as they're too verbose
110
+
tracing::Level::TRACE=>EventFilter::Ignore,
111
+
// Capture everything else as a traditional structured log
112
+
_=>EventFilter::Log,
113
+
});
114
+
115
+
tracing_subscriber::registry()
116
+
.with(tracing_subscriber::fmt::layer())
117
+
.with(sentry_layer)
118
+
.init();
119
+
120
+
info!("Hello, world!");
121
+
122
+
warn!(
123
+
database.host ="prod-db-01",
124
+
database.port =5432,
125
+
retry_attempt=2,
126
+
"Database connection slow"
127
+
);
128
+
129
+
error!(error_code=500, "Critical system failure");
130
+
}
131
+
```
132
+
133
+
The fields of `tracing` events are automatically captured as attributes in Sentry logs.
134
+
135
+
To map a `tracing` event to multiple `EventFilter`s, for example to capture both an event and a log for error level `tracing` events, use an additional Sentry layer with the desired event filter.
136
+
137
+
### `log` Integration
138
+
139
+
To use the `log` integration with logs, add the necessary dependencies to your `Cargo.toml`.
140
+
141
+
```toml {filename:Cargo.toml}
142
+
[dependencies]
143
+
sentry = { version = "{{@inject packages.version('sentry.rust') }}", features = ["log", "logs"] }
144
+
log = "0.4"
145
+
# optional: use any log implementation you prefer
146
+
env_logger = "0.11"
147
+
```
148
+
149
+
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.
// These are grouped into issues, representing high-severity errors to act upon
172
+
log::Level::Error=>LogFilter::Event,
173
+
// Ignore trace level records, as they're too verbose
174
+
log::Level::Trace=>LogFilter::Ignore,
175
+
// Capture everything else as a log
176
+
_=>LogFilter::Log,
177
+
});
178
+
179
+
log::set_boxed_logger(Box::new(logger)).unwrap();
180
+
log::set_max_level(log::LevelFilter::Trace);
181
+
182
+
info!("Hello, world!");
183
+
warn!("Database connection slow");
184
+
error!("Critical system failure");
185
+
}
186
+
```
187
+
188
+
### Additional Integrations
189
+
190
+
We're always looking to expand integration support for Logs.
191
+
If you'd like to see support for additional logging libraries, please open a [new issue](https://github.com/getsentry/sentry-rust/issues/new/choose) with your request.
0 commit comments