Skip to content
This repository has been archived by the owner on Sep 21, 2024. It is now read-only.

Add support for sentry tracing in noosphere-core #436

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions rust/noosphere-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ repository = "https://github.com/subconsciousnetwork/noosphere"
homepage = "https://github.com/subconsciousnetwork/noosphere"
readme = "README.md"

[features]
default = ["sentry"]
sentry = ["dep:sentry", "dep:sentry-tracing"]

[dependencies]
tracing = { workspace = true }
cid = { workspace = true }
Expand Down Expand Up @@ -50,6 +54,8 @@ noosphere-collections = { version = "0.6.0", path = "../noosphere-collections" }

ucan = { workspace = true }
ucan-key-support = { workspace = true }
sentry-tracing = { version = "0.31.5", optional = true }
sentry = { version = "0.31.5", optional = true, default-features = false, features=["reqwest", "rustls", "backtrace", "contexts", "panic", "anyhow"] }

[dev-dependencies]
wasm-bindgen-test = { workspace = true }
Expand Down
58 changes: 42 additions & 16 deletions rust/noosphere-core/src/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ mod inner {
let noosphere_log_env = std::env::var("NOOSPHERE_LOG").ok();
let noosphere_log_level_env = std::env::var("NOOSPHERE_LOG_LEVEL").ok();
let noosphere_log_format_env = std::env::var("NOOSPHERE_LOG_FORMAT").ok();
let sentry_tracing_rate = match std::env::var("SENTRY_TRACING_RATE") {
Ok(val) => val,
Err(_) => 0.1
};

let noosphere_log = match noosphere_log_env {
Some(value) => match value.parse() {
Expand Down Expand Up @@ -305,23 +309,45 @@ mod inner {

let subscriber = tracing_subscriber::registry().with(env_filter);

// This isn't a secret value, just where to send the error reports. We can make this configurable in the future if other folks care.
let _guard = sentry::init(("https://553fd6eda33842ed9f088d0c16a147f1@o4505393671569408.ingest.sentry.io/4505399702126593", sentry::ClientOptions {
release: sentry::release_name!(),
traces_sample_rate: sentry_tracing_rate,
..sentry::ClientOptions::default()
}));


match noosphere_log_format {
NoosphereLogFormat::Minimal => subscriber
.with(
Layer::default().event_format(NoosphereMinimalFormatter::new(
tracing_subscriber::fmt::format()
.without_time()
.with_target(false)
.with_ansi(USE_ANSI_COLORS),
)),
)
.init(),
NoosphereLogFormat::Verbose => subscriber
.with(tracing_subscriber::fmt::layer().with_ansi(USE_ANSI_COLORS))
.init(),
NoosphereLogFormat::Pretty => subscriber
.with(Layer::default().pretty().with_ansi(USE_ANSI_COLORS))
.init(),
NoosphereLogFormat::Minimal => {
let subscriber = subscriber
.with(
Layer::default().event_format(NoosphereMinimalFormatter::new(
tracing_subscriber::fmt::format()
.without_time()
.with_target(false)
.with_ansi(USE_ANSI_COLORS),
))
);
subscriber.init();
}
NoosphereLogFormat::Verbose => {
let subscriber = subscriber
.with(tracing_subscriber::fmt::layer().with_ansi(USE_ANSI_COLORS));

#[cfg(feature="sentry")]
let subscriber = subscriber.with(sentry_tracing::layer());

subscriber.init();
}
NoosphereLogFormat::Pretty => {
let subscriber = subscriber
.with(Layer::default().pretty().with_ansi(USE_ANSI_COLORS));

#[cfg(feature="sentry")]
let subscriber = subscriber.with(sentry_tracing::layer());

subscriber.init();
}
};

Ok(())
Expand Down