Skip to content

Commit 89e978b

Browse files
committed
Configure sentry_tracing event filtering
Import EventFilter and replace the plain sentry_tracing::layer() with a layer configured via .event_filter(...). The filter maps tracing levels to Sentry behavior: ERROR -> Event, WARN/INFO/DEBUG -> Breadcrumb, TRACE -> Ignore. This customizes which tracing records become Sentry events vs breadcrumbs (or are dropped) while keeping the existing tracing subscriber initialization.
1 parent 5e064fa commit 89e978b

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/main.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use rand::RngCore;
2626
use sqlx::postgres::PgPoolOptions;
2727
use std::sync::Arc;
2828
use tracing_subscriber::prelude::*;
29+
use sentry_tracing::EventFilter;
2930
use utoipa_swagger_ui::SwaggerUi;
3031

3132
#[derive(
@@ -263,7 +264,15 @@ fn main() -> anyhow::Result<()> {
263264
tracing_subscriber::EnvFilter::try_from_default_env()
264265
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info")),
265266
)
266-
.with(sentry_tracing::layer())
267+
.with(
268+
sentry_tracing::layer().event_filter(|md| match *md.level() {
269+
tracing::Level::ERROR => EventFilter::Event,
270+
tracing::Level::WARN
271+
| tracing::Level::INFO
272+
| tracing::Level::DEBUG => EventFilter::Breadcrumb,
273+
tracing::Level::TRACE => EventFilter::Ignore,
274+
}),
275+
)
267276
.init();
268277

269278
actix_web::rt::System::new().block_on(async_main())

0 commit comments

Comments
 (0)