Skip to content

Commit 20d51c0

Browse files
committed
Auto merge of #3919 - Turbo87:sentry-tracing, r=JohnTitor
sentry: Enable `tracing` feature https://github.com/tokio-rs/tracing/releases/tag/tracing-subscriber-0.2.21 enables us to use per-layer event filters, which previously blocked us from using the `tracing` feature of `sentry`. This PR enables the feature using the default configuration, which reports all `error!()` usages as errors and `warn!()` and `info!()` as breadcrumbs for associated errors.
2 parents 27b6c6a + b2bb38f commit 20d51c0

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

Cargo.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ rand = "0.8"
7373
reqwest = { version = "0.11", features = ["blocking", "gzip", "json"] }
7474
scheduled-thread-pool = "0.2.0"
7575
semver = { version = "1.0.3", features = ["serde"] }
76-
sentry = "0.23.0"
76+
sentry = { version = "0.23.0", features = ["tracing"] }
7777
serde = { version = "1.0.0", features = ["derive"] }
7878
serde_json = "1.0.0"
7979
sha2 = "0.9"

src/bin/server.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![warn(clippy::all, rust_2018_idioms)]
22

33
use cargo_registry::{metrics::LogEncoder, util::errors::AppResult, App, Env};
4-
use std::{fs::File, process::Command, sync::Arc, time::Duration};
4+
use std::{env, fs::File, process::Command, sync::Arc, time::Duration};
55

66
use conduit_hyper::Service;
77
use futures_util::future::FutureExt;
@@ -10,14 +10,27 @@ use reqwest::blocking::Client;
1010
use std::io::Write;
1111
use tokio::io::AsyncWriteExt;
1212
use tokio::signal::unix::{signal, SignalKind};
13+
use tracing::Level;
14+
use tracing_subscriber::{filter, prelude::*};
1315

1416
const CORE_THREADS: usize = 4;
1517

1618
fn main() -> Result<(), Box<dyn std::error::Error>> {
1719
let _sentry = cargo_registry::sentry::init();
1820

1921
// Initialize logging
20-
tracing_subscriber::fmt::init();
22+
23+
let log_filter = env::var("RUST_LOG")
24+
.unwrap_or_default()
25+
.parse::<filter::Targets>()
26+
.expect("Invalid RUST_LOG value");
27+
28+
let sentry_filter = filter::Targets::new().with_default(Level::INFO);
29+
30+
tracing_subscriber::registry()
31+
.with(tracing_subscriber::fmt::layer().with_filter(log_filter))
32+
.with(sentry::integrations::tracing::layer().with_filter(sentry_filter))
33+
.init();
2134

2235
let config = cargo_registry::config::Server::default();
2336
let env = config.env();

0 commit comments

Comments
 (0)