Skip to content

Commit

Permalink
fix(filter): Added is_enabled field to transactions name filter (#2251)
Browse files Browse the repository at this point in the history
Co-authored-by: Joris Bayer <joris.bayer@sentry.io>
  • Loading branch information
RaduW and jjbayer committed Jun 26, 2023
1 parent c956a6f commit f7e38b7
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 4 additions & 0 deletions py/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
11 changes: 9 additions & 2 deletions relay-filter/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -284,6 +288,7 @@ mod tests {
},
ignore_transactions: IgnoreTransactionsFilterConfig {
patterns: [],
is_enabled: false,
},
}
"###);
Expand Down Expand Up @@ -320,6 +325,7 @@ mod tests {
},
ignore_transactions: IgnoreTransactionsFilterConfig {
patterns: GlobPatterns::new(vec!["*health*".to_string()]),
is_enabled: true,
},
};

Expand Down Expand Up @@ -363,7 +369,8 @@ mod tests {
"ignoreTransactions": {
"patterns": [
"*health*"
]
],
"isEnabled": true
}
}
"###);
Expand Down
27 changes: 27 additions & 0 deletions relay-filter/src/transaction_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -105,6 +109,7 @@ mod tests {
};
let config = IgnoreTransactionsFilterConfig {
patterns: _get_patterns(),
is_enabled: true,
};

let filter_result = should_filter(&event, &config);
Expand All @@ -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!(
Expand All @@ -144,6 +170,7 @@ mod tests {
&event,
&IgnoreTransactionsFilterConfig {
patterns: _get_patterns(),
is_enabled: true,
},
);
assert_eq!(
Expand Down
10 changes: 8 additions & 2 deletions tests/integration/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit f7e38b7

Please sign in to comment.