Improve Labrinth Sentry integration (#5174)

* Improve Sentry integration

* remove debug routes

* fix ci

* sentry tracing stuff

* Add spans to Sentry logging

* Fix CI

* Redis op instrumentation

* pr comments
This commit is contained in:
aecsocket
2026-01-21 18:59:05 +00:00
committed by GitHub
parent 306eee3a21
commit e072f2237b
14 changed files with 485 additions and 47 deletions

View File

@@ -3,6 +3,8 @@
use std::str::FromStr;
use eyre::{Result, WrapErr, eyre};
#[cfg(feature = "sentry")]
use tracing::Level;
use tracing::level_filters::LevelFilter;
use tracing_ecs::ECSLayerBuilder;
use tracing_subscriber::{
@@ -71,25 +73,50 @@ pub fn init_with_config(compact: bool) -> Result<()> {
.with_default_directive(LevelFilter::INFO.into())
.from_env_lossy();
let result = match (output_format, compact) {
(OutputFormat::Human, false) => tracing_subscriber::registry()
.with(env_filter)
.with(tracing_subscriber::fmt::layer())
.try_init(),
(OutputFormat::Human, true) => tracing_subscriber::registry()
.with(env_filter)
.with(
let (layer1, layer2, layer3) = match (output_format, compact) {
(OutputFormat::Human, false) => {
(Some(tracing_subscriber::fmt::layer()), None, None)
}
(OutputFormat::Human, true) => (
None,
Some(
tracing_subscriber::fmt::layer()
.without_time()
.with_target(false),
)
.try_init(),
(OutputFormat::Json, _) => tracing_subscriber::registry()
.with(env_filter)
.with(ECSLayerBuilder::default().stdout())
.try_init(),
),
None,
),
(OutputFormat::Json, _) => {
(None, None, Some(ECSLayerBuilder::default().stdout()))
}
};
result.wrap_err("failed to initialize tracing registry")?;
let registry = tracing_subscriber::registry();
let registry = registry
.with(env_filter)
.with(layer1)
.with(layer2)
.with(layer3);
// Add Sentry layer but don't capture any events from tracing events, just breadcrumbs
#[cfg(feature = "sentry")]
let registry = registry.with(
sentry::integrations::tracing::SentryLayer::default().event_filter(
|metadata| match *metadata.level() {
Level::ERROR | Level::WARN | Level::INFO => {
sentry::integrations::tracing::EventFilter::Breadcrumb
}
Level::DEBUG | Level::TRACE => {
sentry::integrations::tracing::EventFilter::empty()
}
},
),
);
registry
.try_init()
.wrap_err("failed to initialize tracing registry")?;
Ok(())
}