From 18f3e623ea55380138b165ca6c04d8ebf0d2ebee Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Tue, 20 Oct 2020 10:50:48 +0200 Subject: [PATCH] ref: Remove empty integrations --- CHANGELOG.md | 2 +- sentry-anyhow/src/lib.rs | 27 ++--------------------- sentry-backtrace/src/process.rs | 10 ++++----- sentry-backtrace/src/trim.rs | 6 ++++++ sentry-log/src/integration.rs | 24 --------------------- sentry-log/src/lib.rs | 8 +------ sentry-log/src/logger.rs | 6 +----- sentry-slog/src/drain.rs | 6 +----- sentry-slog/src/integration.rs | 18 ---------------- sentry-slog/src/lib.rs | 17 ++++++--------- sentry/examples/log-demo.rs | 11 ++++------ sentry/examples/thread-demo.rs | 11 ++++------ sentry/tests/test_log.rs | 38 ++++++++++++++------------------- 13 files changed, 47 insertions(+), 137 deletions(-) delete mode 100644 sentry-log/src/integration.rs delete mode 100644 sentry-slog/src/integration.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 59d172332..b9415a063 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ **Deprecations**: -- The `error-chain` and `failure` integration was officialy deprecated and will be removed soon. +- The `error-chain` and `failure` integration was officially deprecated and will be removed soon. ## 0.20.1 diff --git a/sentry-anyhow/src/lib.rs b/sentry-anyhow/src/lib.rs index d9e17ce2e..40b551268 100644 --- a/sentry-anyhow/src/lib.rs +++ b/sentry-anyhow/src/lib.rs @@ -3,14 +3,12 @@ //! # Example //! //! ```no_run -//! use sentry_anyhow::{capture_anyhow, AnyhowIntegration}; +//! use sentry_anyhow::capture_anyhow; //! //! fn function_that_might_fail() -> anyhow::Result<()> { //! Err(anyhow::anyhow!("some kind of error")) //! } //! -//! let _sentry = sentry::init(sentry::ClientOptions::new().add_integration(AnyhowIntegration)); -//! //! if let Err(err) = function_that_might_fail() { //! capture_anyhow(&err); //! } @@ -22,28 +20,7 @@ #![deny(unsafe_code)] use sentry_core::types::Uuid; -use sentry_core::{ClientOptions, Hub, Integration}; - -/// The Sentry anyhow Integration. -#[derive(Debug, Default)] -pub struct AnyhowIntegration; - -impl AnyhowIntegration { - /// Creates a new anyhow Integration. - pub fn new() -> Self { - Self::default() - } -} - -impl Integration for AnyhowIntegration { - fn name(&self) -> &'static str { - "anyhow" - } - - fn setup(&self, cfg: &mut ClientOptions) { - cfg.in_app_exclude.push("anyhow::"); - } -} +use sentry_core::Hub; /// Captures an `anyhow::Error`. /// diff --git a/sentry-backtrace/src/process.rs b/sentry-backtrace/src/process.rs index 2a4d2e7ac..1d2b5cc78 100644 --- a/sentry-backtrace/src/process.rs +++ b/sentry-backtrace/src/process.rs @@ -49,9 +49,10 @@ pub fn process_event_stacktrace(stacktrace: &mut Stacktrace, options: &ClientOpt None => {} } - for m in &options.in_app_exclude { + for m in &options.in_app_include { if function_starts_with(func_name, m) { - frame.in_app = Some(false); + frame.in_app = Some(true); + any_in_app = true; break; } } @@ -60,10 +61,9 @@ pub fn process_event_stacktrace(stacktrace: &mut Stacktrace, options: &ClientOpt continue; } - for m in &options.in_app_include { + for m in &options.in_app_exclude { if function_starts_with(func_name, m) { - frame.in_app = Some(true); - any_in_app = true; + frame.in_app = Some(false); break; } } diff --git a/sentry-backtrace/src/trim.rs b/sentry-backtrace/src/trim.rs index d903f3a59..ff8fa1ad2 100644 --- a/sentry-backtrace/src/trim.rs +++ b/sentry-backtrace/src/trim.rs @@ -14,11 +14,17 @@ lazy_static::lazy_static! { // these are not modules but things like __rust_maybe_catch_panic "__rust_", "___rust_", + // these are well-known library frames + "anyhow::", + "log::", ]; static ref WELL_KNOWN_BORDER_FRAMES: Vec<&'static str> = vec![ "std::panicking::begin_panic", "core::panicking::panic", + // well-known library frames + "anyhow::", + "::log", ]; // TODO: remove all of this together with the deprecated `error_chain` support diff --git a/sentry-log/src/integration.rs b/sentry-log/src/integration.rs deleted file mode 100644 index 055cf157d..000000000 --- a/sentry-log/src/integration.rs +++ /dev/null @@ -1,24 +0,0 @@ -use sentry_core::{ClientOptions, Integration}; - -/// The Sentry [`log`] Integration. -#[derive(Default)] -pub struct LogIntegration; - -impl Integration for LogIntegration { - fn name(&self) -> &'static str { - "log" - } - - fn setup(&self, cfg: &mut ClientOptions) { - cfg.in_app_exclude.push("log::"); - cfg.extra_border_frames - .push("::log"); - } -} - -impl LogIntegration { - /// Creates a new `log` Integration. - pub fn new() -> Self { - Self::default() - } -} diff --git a/sentry-log/src/lib.rs b/sentry-log/src/lib.rs index b8c87dc31..68dc3000b 100644 --- a/sentry-log/src/lib.rs +++ b/sentry-log/src/lib.rs @@ -15,10 +15,7 @@ //! log::set_boxed_logger(Box::new(logger)).unwrap(); //! log::set_max_level(log::LevelFilter::Info); //! -//! let log_integration = sentry_log::LogIntegration::default(); -//! let _sentry = sentry::init( -//! sentry::ClientOptions::new().add_integration(sentry_log::LogIntegration::new()), -//! ); +//! let _sentry = sentry::init(()); //! //! log::info!("Generates a breadcrumb"); //! log::error!("Generates an event"); @@ -39,12 +36,9 @@ #![doc(html_favicon_url = "https://sentry-brand.storage.googleapis.com/favicon.ico")] #![doc(html_logo_url = "https://sentry-brand.storage.googleapis.com/sentry-glyph-black.png")] #![warn(missing_docs)] -#![allow(clippy::match_like_matches_macro)] mod converters; -mod integration; mod logger; pub use converters::*; -pub use integration::LogIntegration; pub use logger::*; diff --git a/sentry-log/src/logger.rs b/sentry-log/src/logger.rs index fd9071fe2..45773ed32 100644 --- a/sentry-log/src/logger.rs +++ b/sentry-log/src/logger.rs @@ -121,11 +121,7 @@ impl SentryLogger { impl log::Log for SentryLogger { fn enabled(&self, metadata: &log::Metadata<'_>) -> bool { - self.dest.enabled(metadata) - || match (self.filter)(metadata) { - LogFilter::Ignore => false, - _ => true, - } + self.dest.enabled(metadata) || !matches!((self.filter)(metadata), LogFilter::Ignore) } fn log(&self, record: &log::Record<'_>) { diff --git a/sentry-slog/src/drain.rs b/sentry-slog/src/drain.rs index c64ff8c87..0206444b9 100644 --- a/sentry-slog/src/drain.rs +++ b/sentry-slog/src/drain.rs @@ -127,10 +127,6 @@ impl slog::Drain for SentryDrain { } fn is_enabled(&self, level: slog::Level) -> bool { - self.drain.is_enabled(level) - || match (self.filter)(level) { - LevelFilter::Ignore => false, - _ => true, - } + self.drain.is_enabled(level) || !matches!((self.filter)(level), LevelFilter::Ignore) } } diff --git a/sentry-slog/src/integration.rs b/sentry-slog/src/integration.rs deleted file mode 100644 index 9f530e4b7..000000000 --- a/sentry-slog/src/integration.rs +++ /dev/null @@ -1,18 +0,0 @@ -use sentry_core::Integration; - -/// The Sentry `slog` Integration. -#[derive(Debug, Default)] -pub struct SlogIntegration {} - -impl SlogIntegration { - /// Create a new `slog` Integration. - pub fn new() -> Self { - Self::default() - } -} - -impl Integration for SlogIntegration { - fn name(&self) -> &'static str { - "slog" - } -} diff --git a/sentry-slog/src/lib.rs b/sentry-slog/src/lib.rs index 10ed86eb9..9038a716e 100644 --- a/sentry-slog/src/lib.rs +++ b/sentry-slog/src/lib.rs @@ -11,19 +11,17 @@ //! //! ``` //! use sentry::{init, ClientOptions}; -//! use sentry_slog::{SentryDrain, SlogIntegration}; +//! use sentry_slog::SentryDrain; //! -//! let options = ClientOptions::new().add_integration(SlogIntegration::new()); -//! let _sentry = sentry::init(options); +//! let _sentry = sentry::init(()); //! //! let drain = SentryDrain::new(slog::Discard); //! let root = slog::Logger::root(drain, slog::o!()); //! -//! # let options = ClientOptions::new().add_integration(SlogIntegration::new()); -//! # let events = sentry::test::with_captured_events_options(|| { +//! # let events = sentry::test::with_captured_events(|| { //! slog::info!(root, "recorded as breadcrumb"); //! slog::warn!(root, "recorded as regular event"); -//! # }, options.clone()); +//! # }); //! # let captured_event = events.into_iter().next().unwrap(); //! //! assert_eq!( @@ -35,9 +33,9 @@ //! Some("recorded as regular event") //! ); //! -//! # let events = sentry::test::with_captured_events_options(|| { +//! # let events = sentry::test::with_captured_events(|| { //! slog::crit!(root, "recorded as exception event"); -//! # }, options); +//! # }); //! # let captured_event = events.into_iter().next().unwrap(); //! //! assert_eq!(captured_event.exception.len(), 1); @@ -70,12 +68,9 @@ #![doc(html_logo_url = "https://sentry-brand.storage.googleapis.com/sentry-glyph-black.png")] #![warn(missing_docs)] #![deny(unsafe_code)] -#![allow(clippy::match_like_matches_macro)] mod converters; mod drain; -mod integration; pub use converters::*; pub use drain::{default_filter, LevelFilter, RecordMapping, SentryDrain}; -pub use integration::SlogIntegration; diff --git a/sentry/examples/log-demo.rs b/sentry/examples/log-demo.rs index e54fee32b..0536cb3fc 100644 --- a/sentry/examples/log-demo.rs +++ b/sentry/examples/log-demo.rs @@ -4,13 +4,10 @@ use log_ as log; fn main() { init_log(); - let _sentry = sentry::init( - sentry::ClientOptions { - release: sentry::release_name!(), - ..Default::default() - } - .add_integration(sentry_log::LogIntegration::new()), - ); + let _sentry = sentry::init(sentry::ClientOptions { + release: sentry::release_name!(), + ..Default::default() + }); debug!("System is booting"); info!("System is booting"); diff --git a/sentry/examples/thread-demo.rs b/sentry/examples/thread-demo.rs index 642acbc8f..5adb92fed 100644 --- a/sentry/examples/thread-demo.rs +++ b/sentry/examples/thread-demo.rs @@ -8,13 +8,10 @@ fn main() { // this initializes sentry. It also gives the thread that calls this some // special behavior in that all other threads spawned will get a hub based on // the hub from here. - let _sentry = sentry::init( - sentry::ClientOptions { - release: sentry::release_name!(), - ..Default::default() - } - .add_integration(sentry_log::LogIntegration::new()), - ); + let _sentry = sentry::init(sentry::ClientOptions { + release: sentry::release_name!(), + ..Default::default() + }); // the log integration sends to Hub::current() log::info!("Spawning thread"); diff --git a/sentry/tests/test_log.rs b/sentry/tests/test_log.rs index 186f47e5f..48d3d512d 100644 --- a/sentry/tests/test_log.rs +++ b/sentry/tests/test_log.rs @@ -11,17 +11,14 @@ fn test_log() { .map(|()| log::set_max_level(log::LevelFilter::Info)) .unwrap(); - let events = sentry::test::with_captured_events_options( - || { - sentry::configure_scope(|scope| { - scope.set_tag("worker", "worker1"); - }); - - log::info!("Hello World!"); - log::error!("Shit's on fire yo"); - }, - sentry::ClientOptions::new().add_integration(sentry_log::LogIntegration::new()), - ); + let events = sentry::test::with_captured_events(|| { + sentry::configure_scope(|scope| { + scope.set_tag("worker", "worker1"); + }); + + log::info!("Hello World!"); + log::error!("Shit's on fire yo"); + }); assert_eq!(events.len(), 1); let event = events.into_iter().next().unwrap(); @@ -37,17 +34,14 @@ fn test_slog() { let drain = sentry_slog::SentryDrain::new(slog::Discard); let root = slog::Logger::root(drain, slog::o!()); - let events = sentry::test::with_captured_events_options( - || { - sentry::configure_scope(|scope| { - scope.set_tag("worker", "worker1"); - }); - - slog::info!(root, "Hello World!"); - slog::error!(root, "Shit's on fire yo"); - }, - sentry::ClientOptions::new().add_integration(sentry_slog::SlogIntegration::new()), - ); + let events = sentry::test::with_captured_events(|| { + sentry::configure_scope(|scope| { + scope.set_tag("worker", "worker1"); + }); + + slog::info!(root, "Hello World!"); + slog::error!(root, "Shit's on fire yo"); + }); assert_eq!(events.len(), 1); let event = events.into_iter().next().unwrap();