Enable sentry reporting
This commit is contained in:
885
Cargo.lock
generated
885
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -18,6 +18,8 @@ mwbot = { version = "0.7.0", default-features = false, features = ["generators",
|
||||
rand = "0.9.2"
|
||||
reqwest = "0.12.22"
|
||||
scraper = "0.24.0"
|
||||
sentry = { version = "0.45.0", features = ["tracing"] }
|
||||
sentry-tracing = { version = "0.45.0", features = ["backtrace", "logs"] }
|
||||
serde = { version = "1.0.219", features = ["derive"] }
|
||||
serde_plain = "1.0.2"
|
||||
thiserror = "2.0.12"
|
||||
|
||||
47
src/main.rs
47
src/main.rs
@@ -24,6 +24,8 @@ use mwbot::{
|
||||
generators::{Generator, SortDirection, categories::CategoryMemberSort},
|
||||
};
|
||||
use std::path::Path;
|
||||
use tracing::level_filters::LevelFilter;
|
||||
use tracing_subscriber::{Layer, layer::SubscriberExt, util::SubscriberInitExt};
|
||||
|
||||
use crate::watchdog::watch_wanted;
|
||||
|
||||
@@ -61,12 +63,47 @@ pub enum AppError {
|
||||
}
|
||||
|
||||
fn main() -> Result<(), AppError> {
|
||||
tracing_subscriber::fmt()
|
||||
.with_level(true)
|
||||
.with_max_level(tracing::Level::INFO)
|
||||
.init();
|
||||
tracing::info!("Starting {}", app_signature());
|
||||
let fmt_filter = tracing_subscriber::fmt::layer().with_filter(
|
||||
tracing_subscriber::EnvFilter::builder()
|
||||
.with_default_directive(LevelFilter::INFO.into())
|
||||
.from_env_lossy(),
|
||||
);
|
||||
let _guard = match std::fs::read_to_string("sentry_dsn.txt") {
|
||||
Ok(dsn) => {
|
||||
let guard = sentry::init((
|
||||
dsn,
|
||||
sentry::ClientOptions {
|
||||
release: sentry::release_name!(),
|
||||
traces_sample_rate: 1.0,
|
||||
..Default::default()
|
||||
},
|
||||
));
|
||||
|
||||
let sentry_layer = sentry::integrations::tracing::layer()
|
||||
.event_filter(|md| match *md.level() {
|
||||
tracing::Level::ERROR => sentry_tracing::EventFilter::Event,
|
||||
_ => sentry_tracing::EventFilter::Ignore,
|
||||
})
|
||||
.span_filter(|md| {
|
||||
matches!(*md.level(), tracing::Level::ERROR | tracing::Level::WARN)
|
||||
});
|
||||
|
||||
tracing_subscriber::registry()
|
||||
.with(fmt_filter)
|
||||
.with(sentry_layer)
|
||||
.init();
|
||||
tracing::info!("Starting {} with sentry", app_signature());
|
||||
|
||||
Some(guard)
|
||||
}
|
||||
Err(error) => {
|
||||
tracing_subscriber::registry().with(fmt_filter).init();
|
||||
tracing::warn!("Could not load 'sentry_dsn.txt': {}", error);
|
||||
None
|
||||
}
|
||||
};
|
||||
|
||||
// Register the Sentry tracing layer to capture breadcrumbs, events, and spans:
|
||||
let rt = tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build()?;
|
||||
|
||||
Reference in New Issue
Block a user