You've already forked AstralRinth
forked from didirus/AstralRinth
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:
@@ -7,9 +7,13 @@ repository.workspace = true
|
||||
[dependencies]
|
||||
dotenvy = { workspace = true }
|
||||
eyre = { workspace = true }
|
||||
sentry = { workspace = true, optional = true, features = ["tracing"] }
|
||||
tracing = { workspace = true }
|
||||
tracing-ecs = { workspace = true }
|
||||
tracing-subscriber = { workspace = true }
|
||||
|
||||
[features]
|
||||
sentry = ["dep:sentry"]
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ serde_json = { workspace = true }
|
||||
[features]
|
||||
decimal = ["dep:rust_decimal", "utoipa?/decimal"]
|
||||
utoipa = ["dep:utoipa"]
|
||||
sentry = ["modrinth-log/sentry"]
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
Reference in New Issue
Block a user