From f7e38b7ed9010331a0eaa4ee83821cece6ea3086 Mon Sep 17 00:00:00 2001 From: Radu Woinaroski <5281987+RaduW@users.noreply.github.com> Date: Mon, 26 Jun 2023 16:44:37 +0200 Subject: [PATCH] fix(filter): Added is_enabled field to transactions name filter (#2251) Co-authored-by: Joris Bayer --- CHANGELOG.md | 1 + py/CHANGELOG.md | 4 ++++ relay-filter/src/config.rs | 11 +++++++++-- relay-filter/src/transaction_name.rs | 27 +++++++++++++++++++++++++++ tests/integration/test_filters.py | 10 ++++++++-- 5 files changed, 49 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7aac93f232..5bf2a9bfce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ **Features**: +- Add is_enabled flag on transaction filter. ([#2251](https://github.com/getsentry/relay/pull/2251)) - Keep stackframes closest to crash when quantity exceeds limit. ([#2236](https://github.com/getsentry/relay/pull/2236)) - Add filter based on transaction names. ([#2118](https://github.com/getsentry/relay/pull/2118)) - Drop profiles without a transaction in the same envelope. ([#2169](https://github.com/getsentry/relay/pull/2169)) diff --git a/py/CHANGELOG.md b/py/CHANGELOG.md index 6f2858f789..e6885740ce 100644 --- a/py/CHANGELOG.md +++ b/py/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased + +- Add is_enabled flag on transaction filter. ([#2251](https://github.com/getsentry/relay/pull/2251)) + ## 0.8.26 - Add filter based on transaction names. ([#2118](https://github.com/getsentry/relay/pull/2118)) diff --git a/relay-filter/src/config.rs b/relay-filter/src/config.rs index f83b59cffa..6001753ac1 100644 --- a/relay-filter/src/config.rs +++ b/relay-filter/src/config.rs @@ -138,15 +138,19 @@ pub struct ErrorMessagesFilterConfig { /// Configuration for transaction name filter. #[derive(Clone, Debug, Default, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] pub struct IgnoreTransactionsFilterConfig { /// List of patterns for ignored transactions that should be filtered. pub patterns: GlobPatterns, + /// True if the filter is enabled + #[serde(default)] + pub is_enabled: bool, } impl IgnoreTransactionsFilterConfig { /// Returns true if no configuration for this filter is given. pub fn is_empty(&self) -> bool { - self.patterns.is_empty() + self.patterns.is_empty() || !self.is_enabled } } @@ -284,6 +288,7 @@ mod tests { }, ignore_transactions: IgnoreTransactionsFilterConfig { patterns: [], + is_enabled: false, }, } "###); @@ -320,6 +325,7 @@ mod tests { }, ignore_transactions: IgnoreTransactionsFilterConfig { patterns: GlobPatterns::new(vec!["*health*".to_string()]), + is_enabled: true, }, }; @@ -363,7 +369,8 @@ mod tests { "ignoreTransactions": { "patterns": [ "*health*" - ] + ], + "isEnabled": true } } "###); diff --git a/relay-filter/src/transaction_name.rs b/relay-filter/src/transaction_name.rs index f8fd7783d9..b5906d81d0 100644 --- a/relay-filter/src/transaction_name.rs +++ b/relay-filter/src/transaction_name.rs @@ -18,6 +18,10 @@ pub fn should_filter( event: &Event, config: &IgnoreTransactionsFilterConfig, ) -> Result<(), FilterStatKey> { + if config.is_empty() { + return Ok(()); + } + if matches(event, &config.patterns) { return Err(FilterStatKey::FilteredTransactions); } @@ -105,6 +109,7 @@ mod tests { }; let config = IgnoreTransactionsFilterConfig { patterns: _get_patterns(), + is_enabled: true, }; let filter_result = should_filter(&event, &config); @@ -125,6 +130,27 @@ mod tests { &event, &IgnoreTransactionsFilterConfig { patterns: GlobPatterns::new(vec![]), + is_enabled: true, + }, + ); + assert_eq!( + filter_result, + Ok(()), + "Event filtered although filter should have been disabled" + ) + } + #[test] + // Tests that is_enabled flag disables the transaction name filter + fn test_does_not_filter_when_disabled_with_flag() { + let event = Event { + transaction: Annotated::new("/health".into()), + ..Event::default() + }; + let filter_result = should_filter( + &event, + &IgnoreTransactionsFilterConfig { + patterns: _get_patterns(), + is_enabled: false, }, ); assert_eq!( @@ -144,6 +170,7 @@ mod tests { &event, &IgnoreTransactionsFilterConfig { patterns: _get_patterns(), + is_enabled: true, }, ); assert_eq!( diff --git a/tests/integration/test_filters.py b/tests/integration/test_filters.py index f050276d53..53cf75cc68 100644 --- a/tests/integration/test_filters.py +++ b/tests/integration/test_filters.py @@ -244,9 +244,15 @@ def test_ignore_transactions_filters_are_applied( project_config = mini_sentry.add_full_project_config(project_id) filter_settings = project_config["config"]["filterSettings"] if is_enabled: - filter_settings["ignoreTransactions"] = {"patterns": ["health*"]} + filter_settings["ignoreTransactions"] = { + "patterns": ["health*"], + "isEnabled": is_enabled, + } else: - filter_settings["ignoreTransactions"] = {"patterns": []} + filter_settings["ignoreTransactions"] = { + "patterns": [], + "isEnabled": is_enabled, + } transactions_consumer = transactions_consumer(timeout=10)