Skip to content

Commit f99abae

Browse files
Nemo157syphar
authored andcommitted
Log errors even if sentry is configured
This makes it easier to see issues when inspecting the logs. Make sure to not double report errors to sentry by filtering them out of the tracing layer.
1 parent 5b4b428 commit f99abae

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/bin/cratesfyi.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,15 @@ fn main() {
3737
);
3838

3939
let _sentry_guard = if let Ok(sentry_dsn) = env::var("SENTRY_DSN") {
40-
tracing_registry.with(sentry_tracing::layer()).init();
40+
tracing_registry
41+
.with(sentry_tracing::layer().event_filter(|md| {
42+
if md.fields().field("reported_to_sentry").is_some() {
43+
sentry_tracing::EventFilter::Ignore
44+
} else {
45+
sentry_tracing::default_event_filter(md)
46+
}
47+
}))
48+
.init();
4149
Some(sentry::init((
4250
sentry_dsn,
4351
sentry::ClientOptions {

src/utils/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ pub(crate) const APP_USER_AGENT: &str = concat!(
3838
);
3939

4040
pub(crate) fn report_error(err: &anyhow::Error) {
41+
// Debug-format for anyhow errors includes context & backtrace
4142
if std::env::var("SENTRY_DSN").is_ok() {
4243
sentry_anyhow::capture_anyhow(err);
44+
error!(reported_to_sentry = true, "{err:?}");
4345
} else {
44-
// Debug-format for anyhow errors includes context & backtrace
45-
error!("{:?}", err);
46+
error!("{err:?}");
4647
}
4748
}
4849

0 commit comments

Comments
 (0)