From b225eeefc35ed156684ef7d7e6ca2304603f7cc5 Mon Sep 17 00:00:00 2001 From: Justin Abrahms Date: Wed, 21 Jun 2023 15:58:26 -0700 Subject: [PATCH 1/6] Add support for sentry tracing in noosphere-core --- rust/noosphere-core/Cargo.toml | 6 ++++ rust/noosphere-core/src/tracing.rs | 57 +++++++++++++++++++++--------- 2 files changed, 47 insertions(+), 16 deletions(-) diff --git a/rust/noosphere-core/Cargo.toml b/rust/noosphere-core/Cargo.toml index f8469910d..c32514467 100644 --- a/rust/noosphere-core/Cargo.toml +++ b/rust/noosphere-core/Cargo.toml @@ -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 } @@ -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 } diff --git a/rust/noosphere-core/src/tracing.rs b/rust/noosphere-core/src/tracing.rs index ab70b031e..e62cafdef 100644 --- a/rust/noosphere-core/src/tracing.rs +++ b/rust/noosphere-core/src/tracing.rs @@ -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() { @@ -305,23 +309,44 @@ mod inner { let subscriber = tracing_subscriber::registry().with(env_filter); + 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(()) From 6920b11768eff4e36b7a2485b0593bb9f7767b1b Mon Sep 17 00:00:00 2001 From: Justin Abrahms Date: Wed, 21 Jun 2023 16:05:05 -0700 Subject: [PATCH 2/6] Add note about magic value --- rust/noosphere-core/src/tracing.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/rust/noosphere-core/src/tracing.rs b/rust/noosphere-core/src/tracing.rs index e62cafdef..8905d8df8 100644 --- a/rust/noosphere-core/src/tracing.rs +++ b/rust/noosphere-core/src/tracing.rs @@ -309,6 +309,7 @@ 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, From 6d2dcc10b41029e8d1157052a5114fd66c80085c Mon Sep 17 00:00:00 2001 From: Justin Abrahms Date: Wed, 21 Jun 2023 16:42:40 -0700 Subject: [PATCH 3/6] Sentry is even *more* optional now. --- rust/noosphere-core/Cargo.toml | 1 - rust/noosphere-core/src/tracing.rs | 9 +++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/rust/noosphere-core/Cargo.toml b/rust/noosphere-core/Cargo.toml index c32514467..527dfc646 100644 --- a/rust/noosphere-core/Cargo.toml +++ b/rust/noosphere-core/Cargo.toml @@ -19,7 +19,6 @@ homepage = "https://github.com/subconsciousnetwork/noosphere" readme = "README.md" [features] -default = ["sentry"] sentry = ["dep:sentry", "dep:sentry-tracing"] [dependencies] diff --git a/rust/noosphere-core/src/tracing.rs b/rust/noosphere-core/src/tracing.rs index 8905d8df8..b4787f50d 100644 --- a/rust/noosphere-core/src/tracing.rs +++ b/rust/noosphere-core/src/tracing.rs @@ -250,6 +250,7 @@ mod inner { Ok(val) => val, Err(_) => 0.1 }; + let sentry_dsn = std::env::var("SENTRY_DSN").ok(); let noosphere_log = match noosphere_log_env { Some(value) => match value.parse() { @@ -309,8 +310,8 @@ 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 { + #[cfg(feature="sentry")] + let _guard = sentry::init((sentry_dsn, sentry::ClientOptions { release: sentry::release_name!(), traces_sample_rate: sentry_tracing_rate, ..sentry::ClientOptions::default() @@ -328,6 +329,10 @@ mod inner { .with_ansi(USE_ANSI_COLORS), )) ); + + #[cfg(feature="sentry")] + let subscriber = subscriber.with(sentry_tracing::layer()); + subscriber.init(); } NoosphereLogFormat::Verbose => { From 01da8f2f28031763eb9057429e5c00968565d262 Mon Sep 17 00:00:00 2001 From: Justin Abrahms Date: Wed, 21 Jun 2023 16:46:34 -0700 Subject: [PATCH 4/6] Fix issues around unused vars w/ config off and type casting --- rust/noosphere-core/src/tracing.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/rust/noosphere-core/src/tracing.rs b/rust/noosphere-core/src/tracing.rs index b4787f50d..e4e53f8d0 100644 --- a/rust/noosphere-core/src/tracing.rs +++ b/rust/noosphere-core/src/tracing.rs @@ -246,10 +246,12 @@ 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, + #[cfg(feature="sentry")] + let sentry_tracing_rate: f32 = match std::env::var("SENTRY_TRACING_RATE") { + Ok(val) => val.parse().unwrap(), Err(_) => 0.1 }; + #[cfg(feature="sentry")] let sentry_dsn = std::env::var("SENTRY_DSN").ok(); let noosphere_log = match noosphere_log_env { From 3a46647c8662608c27f6b56e776ffeb61bf85ab1 Mon Sep 17 00:00:00 2001 From: Justin Abrahms Date: Wed, 21 Jun 2023 17:18:49 -0700 Subject: [PATCH 5/6] rustfmt --- rust/noosphere-core/src/tracing.rs | 57 +++++++++++++++--------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/rust/noosphere-core/src/tracing.rs b/rust/noosphere-core/src/tracing.rs index e4e53f8d0..af30ac13e 100644 --- a/rust/noosphere-core/src/tracing.rs +++ b/rust/noosphere-core/src/tracing.rs @@ -246,12 +246,12 @@ 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(); - #[cfg(feature="sentry")] + #[cfg(feature = "sentry")] let sentry_tracing_rate: f32 = match std::env::var("SENTRY_TRACING_RATE") { Ok(val) => val.parse().unwrap(), - Err(_) => 0.1 + Err(_) => 0.1, }; - #[cfg(feature="sentry")] + #[cfg(feature = "sentry")] let sentry_dsn = std::env::var("SENTRY_DSN").ok(); let noosphere_log = match noosphere_log_env { @@ -312,49 +312,50 @@ mod inner { let subscriber = tracing_subscriber::registry().with(env_filter); - #[cfg(feature="sentry")] - let _guard = sentry::init((sentry_dsn, sentry::ClientOptions { - release: sentry::release_name!(), - traces_sample_rate: sentry_tracing_rate, - ..sentry::ClientOptions::default() - })); - + #[cfg(feature = "sentry")] + let _guard = sentry::init(( + sentry_dsn, + sentry::ClientOptions { + release: sentry::release_name!(), + traces_sample_rate: sentry_tracing_rate, + ..sentry::ClientOptions::default() + }, + )); match noosphere_log_format { 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), - )) - ); - - #[cfg(feature="sentry")] + let subscriber = subscriber.with( + Layer::default().event_format(NoosphereMinimalFormatter::new( + tracing_subscriber::fmt::format() + .without_time() + .with_target(false) + .with_ansi(USE_ANSI_COLORS), + )), + ); + + #[cfg(feature = "sentry")] let subscriber = subscriber.with(sentry_tracing::layer()); subscriber.init(); } NoosphereLogFormat::Verbose => { - let subscriber = subscriber - .with(tracing_subscriber::fmt::layer().with_ansi(USE_ANSI_COLORS)); + let subscriber = + subscriber.with(tracing_subscriber::fmt::layer().with_ansi(USE_ANSI_COLORS)); - #[cfg(feature="sentry")] + #[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)); + let subscriber = + subscriber.with(Layer::default().pretty().with_ansi(USE_ANSI_COLORS)); - #[cfg(feature="sentry")] + #[cfg(feature = "sentry")] let subscriber = subscriber.with(sentry_tracing::layer()); subscriber.init(); - } + } }; Ok(()) From e736bf28d272582d52a8eae3f52918e4b7ce6c2c Mon Sep 17 00:00:00 2001 From: Justin Abrahms Date: Wed, 21 Jun 2023 17:24:50 -0700 Subject: [PATCH 6/6] cargo.lock?? --- Cargo.lock | 241 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 235 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 17fa5c3a9..f32935b78 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,21 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + [[package]] name = "aead" version = "0.3.2" @@ -216,6 +231,9 @@ name = "anyhow" version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8" +dependencies = [ + "backtrace", +] [[package]] name = "arc-swap" @@ -633,6 +651,21 @@ dependencies = [ "syn 2.0.16", ] +[[package]] +name = "backtrace" +version = "0.3.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "233d376d6d185f2a3093e58f283f60f880315b6c60075b01f36b3b85154564ca" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + [[package]] name = "base-x" version = "0.2.11" @@ -1304,6 +1337,16 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "debugid" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef552e6f588e446098f6ba40d89ac146c8c7b64aade83c051ee00bb5d2bc18d" +dependencies = [ + "serde", + "uuid", +] + [[package]] name = "der" version = "0.6.1" @@ -1930,6 +1973,12 @@ dependencies = [ "syn 2.0.16", ] +[[package]] +name = "gimli" +version = "0.27.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" + [[package]] name = "globset" version = "0.4.10" @@ -2211,7 +2260,7 @@ checksum = "0646026eb1b3eea4cd9ba47912ea5ce9cc07713d105b1a14698f4e6433d348b7" dependencies = [ "http", "hyper", - "rustls 0.21.1", + "rustls 0.21.2", "tokio", "tokio-rustls", ] @@ -3153,6 +3202,15 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" +[[package]] +name = "miniz_oxide" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa" +dependencies = [ + "adler", +] + [[package]] name = "mio" version = "0.8.6" @@ -3569,6 +3627,8 @@ dependencies = [ "noosphere-storage", "once_cell", "rand 0.8.5", + "sentry", + "sentry-tracing", "serde", "serde_bytes", "serde_json", @@ -3863,6 +3923,15 @@ dependencies = [ "libc", ] +[[package]] +name = "object" +version = "0.30.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03b4680b86d9cfafba8fc491dc9b6df26b68cf40e9e6cd73909194759a63c385" +dependencies = [ + "memchr", +] + [[package]] name = "oid-registry" version = "0.4.0" @@ -3893,6 +3962,17 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +[[package]] +name = "os_info" +version = "3.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "006e42d5b888366f1880eda20371fedde764ed2213dc8496f49622fa0c99cd5e" +dependencies = [ + "log", + "serde", + "winapi", +] + [[package]] name = "overload" version = "0.1.1" @@ -4522,7 +4602,7 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", - "rustls 0.21.1", + "rustls 0.21.2", "rustls-pemfile", "serde", "serde_json", @@ -4536,7 +4616,7 @@ dependencies = [ "wasm-bindgen-futures", "wasm-streams", "web-sys", - "webpki-roots", + "webpki-roots 0.22.6", "winreg", ] @@ -4661,6 +4741,12 @@ dependencies = [ "webrtc-util", ] +[[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + [[package]] name = "rustc-hash" version = "1.1.0" @@ -4726,9 +4812,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.21.1" +version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c911ba11bc8433e811ce56fde130ccf32f5127cab0e0194e9c68c5a5b671791e" +checksum = "e32ca28af694bc1bbf399c33a516dbdf1c90090b8ab23c2bc24f834aa2247f5f" dependencies = [ "log", "ring", @@ -4895,6 +4981,115 @@ version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" +[[package]] +name = "sentry" +version = "0.31.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01b0ad16faa5d12372f914ed40d00bda21a6d1bdcc99264c5e5e1c9495cf3654" +dependencies = [ + "httpdate", + "reqwest", + "rustls 0.21.2", + "sentry-anyhow", + "sentry-backtrace", + "sentry-contexts", + "sentry-core", + "sentry-panic", + "sentry-tracing", + "tokio", + "ureq", + "webpki-roots 0.22.6", +] + +[[package]] +name = "sentry-anyhow" +version = "0.31.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f3a571f02f9982af445af829c4837fe4857568a431bd2bed9f7cf88de4a6c44" +dependencies = [ + "anyhow", + "sentry-backtrace", + "sentry-core", +] + +[[package]] +name = "sentry-backtrace" +version = "0.31.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11f2ee8f147bb5f22ac59b5c35754a759b9a6f6722402e2a14750b2a63fc59bd" +dependencies = [ + "backtrace", + "once_cell", + "regex", + "sentry-core", +] + +[[package]] +name = "sentry-contexts" +version = "0.31.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcd133362c745151eeba0ac61e3ba8350f034e9fe7509877d08059fe1d7720c6" +dependencies = [ + "hostname", + "libc", + "os_info", + "rustc_version", + "sentry-core", + "uname", +] + +[[package]] +name = "sentry-core" +version = "0.31.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7163491708804a74446642ff2c80b3acd668d4b9e9f497f85621f3d250fd012b" +dependencies = [ + "once_cell", + "rand 0.8.5", + "sentry-types", + "serde", + "serde_json", +] + +[[package]] +name = "sentry-panic" +version = "0.31.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4dfe8371c9b2e126a8b64f6fefa54cef716ff2a50e63b5558a48b899265bccd" +dependencies = [ + "sentry-backtrace", + "sentry-core", +] + +[[package]] +name = "sentry-tracing" +version = "0.31.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aca8b88978677a27ee1a91beafe4052306c474c06f582321fde72d2e2cc2f7f" +dependencies = [ + "sentry-backtrace", + "sentry-core", + "tracing-core", + "tracing-subscriber", +] + +[[package]] +name = "sentry-types" +version = "0.31.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e7a88e0c1922d19b3efee12a8215f6a8a806e442e665ada71cc222cab72985f" +dependencies = [ + "debugid", + "getrandom 0.2.9", + "hex", + "serde", + "serde_json", + "thiserror", + "time", + "url", + "uuid", +] + [[package]] name = "serde" version = "1.0.163" @@ -5466,7 +5661,7 @@ version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e0d409377ff5b1e3ca6437aa86c1eb7d40c134bfec254e44c830defa92669db5" dependencies = [ - "rustls 0.21.1", + "rustls 0.21.2", "tokio", ] @@ -5785,6 +5980,15 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "uname" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b72f89f0ca32e4db1c04e2a72f5345d59796d4866a1ee0609084569f73683dc8" +dependencies = [ + "libc", +] + [[package]] name = "unicase" version = "2.6.0" @@ -5884,6 +6088,21 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0976c77def3f1f75c4ef892a292c31c0bbe9e3d0702c63044d7c76db298171a3" +[[package]] +name = "ureq" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b11c96ac7ee530603dcdf68ed1557050f374ce55a5a07193ebf8cbc9f8927e9" +dependencies = [ + "base64 0.21.0", + "log", + "once_cell", + "rustls 0.21.2", + "rustls-webpki", + "url", + "webpki-roots 0.23.1", +] + [[package]] name = "url" version = "2.3.1" @@ -5915,6 +6134,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "345444e32442451b267fc254ae85a209c64be56d2890e601a0c37ff0c3c5ecd2" dependencies = [ "getrandom 0.2.9", + "serde", ] [[package]] @@ -6149,6 +6369,15 @@ dependencies = [ "webpki 0.22.0", ] +[[package]] +name = "webpki-roots" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b03058f88386e5ff5310d9111d53f48b17d732b401aeb83a8d5190f2ac459338" +dependencies = [ + "rustls-webpki", +] + [[package]] name = "webrtc" version = "0.6.0"