From efe4514cc81fec60a04986a70c186c43f96fa6d4 Mon Sep 17 00:00:00 2001 From: Joris Bayer Date: Tue, 9 Apr 2024 09:40:44 +0200 Subject: [PATCH 1/8] ref: trait --- relay-filter/Cargo.toml | 2 +- relay-filter/src/browser_extensions.rs | 15 ++-- relay-filter/src/csp.rs | 21 +++--- relay-filter/src/error_messages.rs | 14 ++-- relay-filter/src/generic.rs | 12 ++-- relay-filter/src/interface.rs | 15 ++++ relay-filter/src/legacy_browsers.rs | 98 ++++++++++++-------------- relay-filter/src/lib.rs | 26 +++---- relay-filter/src/localhost.rs | 9 ++- relay-filter/src/releases.rs | 13 ++-- relay-filter/src/transaction_name.rs | 21 +++--- relay-filter/src/web_crawlers.rs | 10 +-- 12 files changed, 135 insertions(+), 121 deletions(-) create mode 100644 relay-filter/src/interface.rs diff --git a/relay-filter/Cargo.toml b/relay-filter/Cargo.toml index f418564f91..8dfcdd3f6a 100644 --- a/relay-filter/Cargo.toml +++ b/relay-filter/Cargo.toml @@ -18,7 +18,7 @@ once_cell = { workspace = true } indexmap = { workspace = true } regex = { workspace = true } relay-common = { workspace = true } -relay-event-schema = { workspace = true } +relay-event-schema = { workspace = true } # TODO: not needed? relay-protocol = { workspace = true } relay-ua = { workspace = true } serde = { workspace = true } diff --git a/relay-filter/src/browser_extensions.rs b/relay-filter/src/browser_extensions.rs index 60366427d8..c4a1e4dc97 100644 --- a/relay-filter/src/browser_extensions.rs +++ b/relay-filter/src/browser_extensions.rs @@ -4,7 +4,7 @@ use once_cell::sync::Lazy; use regex::Regex; use relay_event_schema::protocol::{Event, Exception}; -use crate::{FilterConfig, FilterStatKey}; +use crate::{FilterConfig, FilterStatKey, Filterable}; static EXTENSION_EXC_VALUES: Lazy = Lazy::new(|| { Regex::new( @@ -81,13 +81,13 @@ static EXTENSION_EXC_SOURCES: Lazy = Lazy::new(|| { const ANONYMOUS_FRAMES: [&str; 2] = ["", "[native code]"]; /// Check if the event originates from known problematic browser extensions. -pub fn matches(event: &Event) -> bool { - if let Some(ex_val) = get_exception_value(event) { +pub fn matches(item: &F) -> bool { + if let Some(ex_val) = item.exception_value() { if EXTENSION_EXC_VALUES.is_match(ex_val) { return true; } } - if let Some(ex_source) = get_exception_source(event) { + if let Some(ex_source) = item.exception_source() { if EXTENSION_EXC_SOURCES.is_match(ex_source) { return true; } @@ -96,12 +96,15 @@ pub fn matches(event: &Event) -> bool { } /// Filters events originating from known problematic browser extensions. -pub fn should_filter(event: &Event, config: &FilterConfig) -> Result<(), FilterStatKey> { +pub fn should_filter(item: &F, config: &FilterConfig) -> Result<(), FilterStatKey> +where + F: Filterable, +{ if !config.is_enabled { return Ok(()); } - if matches(event) { + if matches(item) { Err(FilterStatKey::BrowserExtensions) } else { Ok(()) diff --git a/relay-filter/src/csp.rs b/relay-filter/src/csp.rs index afc4b2b7c1..31a6ac0ab9 100644 --- a/relay-filter/src/csp.rs +++ b/relay-filter/src/csp.rs @@ -2,19 +2,19 @@ //! //! Events originating from a CSP message can be filtered based on the source URL -use relay_event_schema::protocol::{Event, EventType}; +use relay_event_schema::protocol::{Csp, Event, EventType}; -use crate::{CspFilterConfig, FilterStatKey}; +use crate::{CspFilterConfig, FilterStatKey, Filterable}; /// Checks if the event is a CSP Event from one of the disallowed sources. -pub fn matches(event: &Event, disallowed_sources: It) -> bool +pub fn matches(csp: Option<&Csp>, disallowed_sources: It) -> bool where It: IntoIterator, S: AsRef, { - if event.ty.value() != Some(&EventType::Csp) { - return false; - } + // if event.ty.value() != Some(&EventType::Csp) { + // return false; + // } // TODO: move to trait // parse the sources for easy processing let disallowed_sources: Vec = disallowed_sources @@ -22,7 +22,7 @@ where .map(|origin| -> SchemeDomainPort { origin.as_ref().into() }) .collect(); - if let Some(csp) = event.csp.value() { + if let Some(csp) = csp { if matches_any_origin(csp.blocked_uri.as_str(), &disallowed_sources) { return true; } @@ -37,8 +37,11 @@ where } /// Filters CSP events based on disallowed sources. -pub fn should_filter(event: &Event, config: &CspFilterConfig) -> Result<(), FilterStatKey> { - if matches(event, &config.disallowed_sources) { +pub fn should_filter(item: &F, config: &CspFilterConfig) -> Result<(), FilterStatKey> +where + F: Filterable, +{ + if matches(item.csp(), &config.disallowed_sources) { Err(FilterStatKey::InvalidCsp) } else { Ok(()) diff --git a/relay-filter/src/error_messages.rs b/relay-filter/src/error_messages.rs index 9840bf5afe..5c51bdedda 100644 --- a/relay-filter/src/error_messages.rs +++ b/relay-filter/src/error_messages.rs @@ -8,11 +8,11 @@ use std::borrow::Cow; use relay_common::glob3::GlobPatterns; use relay_event_schema::protocol::Event; -use crate::{ErrorMessagesFilterConfig, FilterStatKey}; +use crate::{ErrorMessagesFilterConfig, FilterStatKey, Filterable}; /// Checks events by patterns in their error messages. -pub fn matches(event: &Event, patterns: &GlobPatterns) -> bool { - if let Some(logentry) = event.logentry.value() { +pub fn matches(item: &F, patterns: &GlobPatterns) -> bool { + if let Some(logentry) = item.logentry() { if let Some(message) = logentry.formatted.value() { if patterns.is_match(message.as_ref()) { return true; @@ -24,7 +24,7 @@ pub fn matches(event: &Event, patterns: &GlobPatterns) -> bool { } } - if let Some(exception_values) = event.exceptions.value() { + if let Some(exception_values) = item.exceptions() { if let Some(exceptions) = exception_values.values.value() { for exception in exceptions { if let Some(exception) = exception.value() { @@ -46,11 +46,11 @@ pub fn matches(event: &Event, patterns: &GlobPatterns) -> bool { } /// Filters events by patterns in their error messages. -pub fn should_filter( - event: &Event, +pub fn should_filter( + item: &F, config: &ErrorMessagesFilterConfig, ) -> Result<(), FilterStatKey> { - if matches(event, &config.patterns) { + if matches(item, &config.patterns) { Err(FilterStatKey::ErrorMessage) } else { Ok(()) diff --git a/relay-filter/src/generic.rs b/relay-filter/src/generic.rs index 948a1d014b..02a7cc02fb 100644 --- a/relay-filter/src/generic.rs +++ b/relay-filter/src/generic.rs @@ -8,7 +8,7 @@ use std::iter::FusedIterator; use crate::{FilterStatKey, GenericFilterConfig, GenericFiltersConfig, GenericFiltersMap}; use relay_event_schema::protocol::Event; -use relay_protocol::RuleCondition; +use relay_protocol::{Getter, RuleCondition}; /// Maximum supported version of the generic filters schema. /// @@ -25,15 +25,15 @@ pub fn are_generic_filters_supported( } /// Checks events by patterns in their error messages. -fn matches(event: &Event, condition: Option<&RuleCondition>) -> bool { +fn matches(item: &F, condition: Option<&RuleCondition>) -> bool { // TODO: the condition DSL needs to be extended to support more complex semantics, such as // collections operations. - condition.map_or(false, |condition| condition.matches(event)) + condition.map_or(false, |condition| condition.matches(item)) } /// Filters events by patterns in their error messages. -pub(crate) fn should_filter( - event: &Event, +pub(crate) fn should_filter( + item: &F, project_filters: &GenericFiltersConfig, global_filters: Option<&GenericFiltersConfig>, ) -> Result<(), FilterStatKey> { @@ -45,7 +45,7 @@ pub(crate) fn should_filter( ); for filter_config in filters { - if filter_config.is_enabled && matches(event, filter_config.condition) { + if filter_config.is_enabled && matches(item, filter_config.condition) { return Err(FilterStatKey::GenericFilter(filter_config.id.to_owned())); } } diff --git a/relay-filter/src/interface.rs b/relay-filter/src/interface.rs new file mode 100644 index 0000000000..389cf7716a --- /dev/null +++ b/relay-filter/src/interface.rs @@ -0,0 +1,15 @@ +//! TODO: docs + +use relay_event_schema::protocol::{Csp, Event}; + +/// TODO: docs +pub trait Filterable { + /// TODO: docs + fn csp(&self) -> Option<&Csp>; +} + +impl Filterable for Event { + fn csp(&self) -> Option<&Csp> { + self.csp.value() + } +} diff --git a/relay-filter/src/legacy_browsers.rs b/relay-filter/src/legacy_browsers.rs index 3d98d6c722..14306a1a95 100644 --- a/relay-filter/src/legacy_browsers.rs +++ b/relay-filter/src/legacy_browsers.rs @@ -5,71 +5,61 @@ use std::collections::BTreeSet; use relay_event_schema::protocol::Event; use relay_ua::UserAgent; -use crate::{FilterStatKey, LegacyBrowser, LegacyBrowsersFilterConfig}; +use crate::{FilterStatKey, Filterable, LegacyBrowser, LegacyBrowsersFilterConfig}; /// Checks if the event originates from legacy browsers. -pub fn matches(event: &Event, browsers: &BTreeSet) -> bool { - if let Some(user_agent_string) = event.user_agent() { - let user_agent = relay_ua::parse_user_agent(user_agent_string); +pub fn matches(user_agent: &str, browsers: &BTreeSet) -> bool { + let user_agent = relay_ua::parse_user_agent(user_agent); - // remap IE Mobile to IE (sentry python, filter compatibility) - let family = match user_agent.family.as_ref() { - "IE Mobile" => "IE", - other => other, - }; + // remap IE Mobile to IE (sentry python, filter compatibility) + let family = match user_agent.family.as_ref() { + "IE Mobile" => "IE", + other => other, + }; - if browsers.contains(&LegacyBrowser::Default) { - return default_filter(family, &user_agent); - } + if browsers.contains(&LegacyBrowser::Default) { + return default_filter(family, &user_agent); + } - for browser_type in browsers { - let should_filter = match browser_type { - LegacyBrowser::IePre9 => filter_browser(family, &user_agent, "IE", |x| x <= 8), - LegacyBrowser::Ie9 => filter_browser(family, &user_agent, "IE", |x| x == 9), - LegacyBrowser::Ie10 => filter_browser(family, &user_agent, "IE", |x| x == 10), - LegacyBrowser::Ie11 => filter_browser(family, &user_agent, "IE", |x| x == 11), - LegacyBrowser::OperaMiniPre8 => { - filter_browser(family, &user_agent, "Opera Mini", |x| x < 8) - } - LegacyBrowser::OperaPre15 => { - filter_browser(family, &user_agent, "Opera", |x| x < 15) - } - LegacyBrowser::AndroidPre4 => { - filter_browser(family, &user_agent, "Android", |x| x < 4) - } - LegacyBrowser::SafariPre6 => { - filter_browser(family, &user_agent, "Safari", |x| x < 6) - } - LegacyBrowser::EdgePre79 => filter_browser(family, &user_agent, "Edge", |x| x < 79), - LegacyBrowser::Ie => filter_browser(family, &user_agent, "IE", |x| x < 12), - LegacyBrowser::OperaMini => { - filter_browser(family, &user_agent, "Opera Mini", |x| x < 35) - } - LegacyBrowser::Opera => filter_browser(family, &user_agent, "Opera", |x| x < 51), - LegacyBrowser::Android => filter_browser(family, &user_agent, "Android", |x| x < 4), - LegacyBrowser::Safari => filter_browser(family, &user_agent, "Safari", |x| x < 12), - LegacyBrowser::Edge => filter_browser(family, &user_agent, "Edge", |x| x < 79), - LegacyBrowser::Chrome => filter_browser(family, &user_agent, "Chrome", |x| x < 63), - LegacyBrowser::Firefox => { - filter_browser(family, &user_agent, "Firefox", |x| x < 67) - } - LegacyBrowser::Unknown(_) => { - // unknown browsers should not be filtered - false - } - LegacyBrowser::Default => unreachable!(), - }; - if should_filter { - return true; + for browser_type in browsers { + let should_filter = match browser_type { + LegacyBrowser::IePre9 => filter_browser(family, &user_agent, "IE", |x| x <= 8), + LegacyBrowser::Ie9 => filter_browser(family, &user_agent, "IE", |x| x == 9), + LegacyBrowser::Ie10 => filter_browser(family, &user_agent, "IE", |x| x == 10), + LegacyBrowser::Ie11 => filter_browser(family, &user_agent, "IE", |x| x == 11), + LegacyBrowser::OperaMiniPre8 => { + filter_browser(family, &user_agent, "Opera Mini", |x| x < 8) } + LegacyBrowser::OperaPre15 => filter_browser(family, &user_agent, "Opera", |x| x < 15), + LegacyBrowser::AndroidPre4 => filter_browser(family, &user_agent, "Android", |x| x < 4), + LegacyBrowser::SafariPre6 => filter_browser(family, &user_agent, "Safari", |x| x < 6), + LegacyBrowser::EdgePre79 => filter_browser(family, &user_agent, "Edge", |x| x < 79), + LegacyBrowser::Ie => filter_browser(family, &user_agent, "IE", |x| x < 12), + LegacyBrowser::OperaMini => { + filter_browser(family, &user_agent, "Opera Mini", |x| x < 35) + } + LegacyBrowser::Opera => filter_browser(family, &user_agent, "Opera", |x| x < 51), + LegacyBrowser::Android => filter_browser(family, &user_agent, "Android", |x| x < 4), + LegacyBrowser::Safari => filter_browser(family, &user_agent, "Safari", |x| x < 12), + LegacyBrowser::Edge => filter_browser(family, &user_agent, "Edge", |x| x < 79), + LegacyBrowser::Chrome => filter_browser(family, &user_agent, "Chrome", |x| x < 63), + LegacyBrowser::Firefox => filter_browser(family, &user_agent, "Firefox", |x| x < 67), + LegacyBrowser::Unknown(_) => { + // unknown browsers should not be filtered + false + } + LegacyBrowser::Default => unreachable!(), + }; + if should_filter { + return true; } } false } /// Filters events originating from legacy browsers. -pub fn should_filter( - event: &Event, +pub fn should_filter( + item: &F, config: &LegacyBrowsersFilterConfig, ) -> Result<(), FilterStatKey> { if !config.is_enabled || config.browsers.is_empty() { @@ -77,7 +67,7 @@ pub fn should_filter( } let browsers = &config.browsers; - if matches(event, browsers) { + if item.user_agent().map_or(false, |ua| matches(ua, browsers)) { Err(FilterStatKey::LegacyBrowsers) } else { Ok(()) diff --git a/relay-filter/src/lib.rs b/relay-filter/src/lib.rs index 22cbcf5acc..321ce4242b 100644 --- a/relay-filter/src/lib.rs +++ b/relay-filter/src/lib.rs @@ -15,6 +15,7 @@ use std::net::IpAddr; use relay_event_schema::protocol::Event; +use relay_protocol::Getter; pub mod browser_extensions; pub mod client_ips; @@ -28,6 +29,7 @@ pub mod web_crawlers; mod common; mod config; +mod interface; mod releases; #[cfg(test)] @@ -36,15 +38,15 @@ mod testutils; pub use crate::common::*; pub use crate::config::*; pub use crate::csp::matches_any_origin; - pub use crate::generic::are_generic_filters_supported; +pub use interface::Filterable; /// Checks whether an event should be filtered for a particular configuration. /// /// If the event should be filtered, the `Err` returned contains a filter reason. /// The reason is the message returned by the first filter that didn't pass. -pub fn should_filter( - event: &Event, +pub fn should_filter( + item: &F, client_ip: Option, config: &ProjectFiltersConfig, global_config: Option<&GenericFiltersConfig>, @@ -52,19 +54,19 @@ pub fn should_filter( // In order to maintain backwards compatibility, we still want to run the old matching logic, // but we will try to match generic filters first, since the goal is to eventually fade out the // the normal filters except for the ones that have complex conditions. - generic::should_filter(event, &config.generic, global_config)?; + generic::should_filter(item, &config.generic, global_config)?; // The order of applying filters should not matter as they are additive. Still, be careful // when making changes to this order. - csp::should_filter(event, &config.csp)?; + csp::should_filter(item, &config.csp)?; client_ips::should_filter(client_ip, &config.client_ips)?; - releases::should_filter(event, &config.releases)?; - error_messages::should_filter(event, &config.error_messages)?; - localhost::should_filter(event, &config.localhost)?; - browser_extensions::should_filter(event, &config.browser_extensions)?; - legacy_browsers::should_filter(event, &config.legacy_browsers)?; - web_crawlers::should_filter(event, &config.web_crawlers)?; - transaction_name::should_filter(event, &config.ignore_transactions)?; + releases::should_filter(item, &config.releases)?; + error_messages::should_filter(item, &config.error_messages)?; + localhost::should_filter(item, &config.localhost)?; + browser_extensions::should_filter(item, &config.browser_extensions)?; + legacy_browsers::should_filter(item, &config.legacy_browsers)?; + web_crawlers::should_filter(item, &config.web_crawlers)?; + transaction_name::should_filter(item, &config.ignore_transactions)?; Ok(()) } diff --git a/relay-filter/src/localhost.rs b/relay-filter/src/localhost.rs index c1cc9a07c4..5d68c854c0 100644 --- a/relay-filter/src/localhost.rs +++ b/relay-filter/src/localhost.rs @@ -2,7 +2,7 @@ use relay_event_schema::protocol::Event; use url::Url; -use crate::{FilterConfig, FilterStatKey}; +use crate::{FilterConfig, FilterStatKey, Filterable}; const LOCAL_IPS: &[&str] = &["127.0.0.1", "::1"]; const LOCAL_DOMAINS: &[&str] = &["127.0.0.1", "localhost"]; @@ -34,11 +34,14 @@ pub fn matches(event: &Event) -> bool { } /// Filters events originating from the local host. -pub fn should_filter(event: &Event, config: &FilterConfig) -> Result<(), FilterStatKey> { +pub fn should_filter(item: &F, config: &FilterConfig) -> Result<(), FilterStatKey> +where + F: Filterable, +{ if !config.is_enabled { return Ok(()); } - if matches(event) { + if matches(item) { return Err(FilterStatKey::Localhost); } Ok(()) diff --git a/relay-filter/src/releases.rs b/relay-filter/src/releases.rs index 1f7781db8c..6a28c5d0ce 100644 --- a/relay-filter/src/releases.rs +++ b/relay-filter/src/releases.rs @@ -4,13 +4,14 @@ //! (known old bad releases) and Sentry will ignore events originating from //! clients with the specified release. -use relay_event_schema::protocol::Event; - -use crate::{FilterStatKey, ReleasesFilterConfig}; +use crate::{FilterStatKey, Filterable, ReleasesFilterConfig}; /// Filters events generated by known problematic SDK clients. -pub fn should_filter(event: &Event, config: &ReleasesFilterConfig) -> Result<(), FilterStatKey> { - if let Some(release) = event.release.as_str() { +pub fn should_filter(item: &F, config: &ReleasesFilterConfig) -> Result<(), FilterStatKey> +where + F: Filterable, +{ + if let Some(release) = item.release() { if config.releases.is_match(release) { return Err(FilterStatKey::ReleaseVersion); } @@ -22,7 +23,7 @@ pub fn should_filter(event: &Event, config: &ReleasesFilterConfig) -> Result<(), #[cfg(test)] mod tests { use relay_common::glob3::GlobPatterns; - use relay_event_schema::protocol::LenientString; + use relay_event_schema::protocol::{Event, LenientString}; use relay_protocol::Annotated; use super::*; diff --git a/relay-filter/src/transaction_name.rs b/relay-filter/src/transaction_name.rs index 70142f2798..d810698f3e 100644 --- a/relay-filter/src/transaction_name.rs +++ b/relay-filter/src/transaction_name.rs @@ -5,30 +5,27 @@ use relay_common::glob3::GlobPatterns; use relay_event_schema::protocol::{Event, EventType}; -use crate::{FilterStatKey, IgnoreTransactionsFilterConfig}; +use crate::{FilterStatKey, Filterable, IgnoreTransactionsFilterConfig}; -fn matches(event: &Event, patterns: &GlobPatterns) -> bool { - if event.ty.value() != Some(&EventType::Transaction) { - return false; - } +fn matches(transaction: Option<&str>, patterns: &GlobPatterns) -> bool { + // if event.ty.value() != Some(&EventType::Transaction) { + // return false; + // } // TODO: move to trait impl - event - .transaction - .value() - .map_or(false, |transaction| patterns.is_match(transaction)) + transaction.map_or(false, |transaction| patterns.is_match(transaction)) } /// Filters [Transaction](EventType::Transaction) events based on a list of provided transaction /// name globs. -pub fn should_filter( - event: &Event, +pub fn should_filter( + item: &F, config: &IgnoreTransactionsFilterConfig, ) -> Result<(), FilterStatKey> { if config.is_empty() { return Ok(()); } - if matches(event, &config.patterns) { + if matches(item.transaction(), &config.patterns) { return Err(FilterStatKey::FilteredTransactions); } Ok(()) diff --git a/relay-filter/src/web_crawlers.rs b/relay-filter/src/web_crawlers.rs index c480e7bdce..e19c5166a2 100644 --- a/relay-filter/src/web_crawlers.rs +++ b/relay-filter/src/web_crawlers.rs @@ -4,7 +4,7 @@ use once_cell::sync::Lazy; use regex::Regex; use relay_event_schema::protocol::Event; -use crate::{FilterConfig, FilterStatKey}; +use crate::{FilterConfig, FilterStatKey, Filterable}; static WEB_CRAWLERS: Lazy = Lazy::new(|| { Regex::new( @@ -49,8 +49,8 @@ static ALLOWED_WEB_CRAWLERS: Lazy = Lazy::new(|| { }); /// Checks if the event originates from a known web crawler. -pub fn matches(event: &Event) -> bool { - if let Some(user_agent) = event.user_agent() { +pub fn matches(user_agent: Option<&str>) -> bool { + if let Some(user_agent) = user_agent { WEB_CRAWLERS.is_match(user_agent) && !ALLOWED_WEB_CRAWLERS.is_match(user_agent) } else { false @@ -58,12 +58,12 @@ pub fn matches(event: &Event) -> bool { } /// Filters events originating from a known web crawler. -pub fn should_filter(event: &Event, config: &FilterConfig) -> Result<(), FilterStatKey> { +pub fn should_filter(item: &F, config: &FilterConfig) -> Result<(), FilterStatKey> { if !config.is_enabled { return Ok(()); } - if matches(event) { + if matches(item.user_agent()) { return Err(FilterStatKey::WebCrawlers); } From c29883c3d43a6ff783e3a5f2777d3c373290642f Mon Sep 17 00:00:00 2001 From: Joris Bayer Date: Tue, 9 Apr 2024 10:09:32 +0200 Subject: [PATCH 2/8] ref: Trait impl --- relay-filter/src/browser_extensions.rs | 16 ++++----- relay-filter/src/interface.rs | 49 ++++++++++++++++++++++++- relay-filter/src/localhost.rs | 16 ++------- relay-filter/src/transaction_name.rs | 50 +++++++++++--------------- 4 files changed, 79 insertions(+), 52 deletions(-) diff --git a/relay-filter/src/browser_extensions.rs b/relay-filter/src/browser_extensions.rs index c4a1e4dc97..a32e1945f1 100644 --- a/relay-filter/src/browser_extensions.rs +++ b/relay-filter/src/browser_extensions.rs @@ -82,12 +82,12 @@ const ANONYMOUS_FRAMES: [&str; 2] = ["", "[native code]"]; /// Check if the event originates from known problematic browser extensions. pub fn matches(item: &F) -> bool { - if let Some(ex_val) = item.exception_value() { + if let Some(ex_val) = get_exception_value(item) { if EXTENSION_EXC_VALUES.is_match(ex_val) { return true; } } - if let Some(ex_source) = item.exception_source() { + if let Some(ex_source) = get_exception_source(item) { if EXTENSION_EXC_SOURCES.is_match(ex_source) { return true; } @@ -111,19 +111,19 @@ where } } -fn get_first_exception(event: &Event) -> Option<&Exception> { - let values = event.exceptions.value()?; +fn get_first_exception(item: &F) -> Option<&Exception> { + let values = item.exceptions()?; let exceptions = values.values.value()?; exceptions.first()?.value() } -fn get_exception_value(event: &Event) -> Option<&str> { - let exception = get_first_exception(event)?; +fn get_exception_value(item: &F) -> Option<&str> { + let exception = get_first_exception(item)?; Some(exception.value.value()?.as_str()) } -fn get_exception_source(event: &Event) -> Option<&str> { - let exception = get_first_exception(event)?; +fn get_exception_source(item: &F) -> Option<&str> { + let exception = get_first_exception(item)?; let frames = exception.stacktrace.value()?.frames.value()?; // Iterate from the tail and get the first frame which is not anonymous. for f in frames.iter().rev() { diff --git a/relay-filter/src/interface.rs b/relay-filter/src/interface.rs index 389cf7716a..432197ab71 100644 --- a/relay-filter/src/interface.rs +++ b/relay-filter/src/interface.rs @@ -1,15 +1,62 @@ //! TODO: docs -use relay_event_schema::protocol::{Csp, Event}; +use relay_event_schema::protocol::{Csp, Event, EventType, Exception, LogEntry, Values}; +use url::Url; /// TODO: docs pub trait Filterable { /// TODO: docs + fn csp(&self) -> Option<&Csp>; + fn exceptions(&self) -> Option<&Values>; + fn ip_addr(&self) -> Option<&str>; + fn logentry(&self) -> Option<&LogEntry>; + fn release(&self) -> Option<&str>; + fn transaction(&self) -> Option<&str>; + fn url(&self) -> Option; + fn user_agent(&self) -> Option<&str>; + + // fn exceptions(&self) -> Option<&Exce } impl Filterable for Event { fn csp(&self) -> Option<&Csp> { + if self.ty.value() != Some(&EventType::Csp) { + return None; + } self.csp.value() } + + fn exceptions(&self) -> Option<&Values> { + self.exceptions.value() + } + + fn ip_addr(&self) -> Option<&str> { + let user = self.user.value()?; + Some(user.ip_address.value()?.as_ref()) + } + + fn logentry(&self) -> Option<&LogEntry> { + self.logentry.value() + } + + fn release(&self) -> Option<&str> { + self.release.as_str() + } + + fn transaction(&self) -> Option<&str> { + if self.ty.value() != Some(&EventType::Transaction) { + return None; + } + self.transaction.as_str() + } + + fn url(&self) -> Option { + let url_str = self.request.value()?.url.value()?; + Url::parse(url_str).ok() + } + + fn user_agent(&self) -> Option<&str> { + self.user_agent() + } } diff --git a/relay-filter/src/localhost.rs b/relay-filter/src/localhost.rs index 5d68c854c0..1fac0aadcb 100644 --- a/relay-filter/src/localhost.rs +++ b/relay-filter/src/localhost.rs @@ -8,8 +8,8 @@ const LOCAL_IPS: &[&str] = &["127.0.0.1", "::1"]; const LOCAL_DOMAINS: &[&str] = &["127.0.0.1", "localhost"]; /// Check if the event originates from the local host. -pub fn matches(event: &Event) -> bool { - if let Some(ip_addr) = get_ip_addr(event) { +pub fn matches(item: &F) -> bool { + if let Some(ip_addr) = item.ip_addr() { for &local_ip in LOCAL_IPS { if local_ip == ip_addr { return true; @@ -17,7 +17,7 @@ pub fn matches(event: &Event) -> bool { } } - if let Some(url) = get_url(event) { + if let Some(url) = item.url() { if let Some(host) = url.host_str() { for &local_domain in LOCAL_DOMAINS { if host == local_domain { @@ -47,16 +47,6 @@ where Ok(()) } -fn get_ip_addr(event: &Event) -> Option<&str> { - let user = event.user.value()?; - Some(user.ip_address.value()?.as_ref()) -} - -fn get_url(event: &Event) -> Option { - let url_str = event.request.value()?.url.value()?; - Url::parse(url_str).ok() -} - #[cfg(test)] mod tests { use relay_event_schema::protocol::{IpAddr, Request, User}; diff --git a/relay-filter/src/transaction_name.rs b/relay-filter/src/transaction_name.rs index d810698f3e..e97a95c7d6 100644 --- a/relay-filter/src/transaction_name.rs +++ b/relay-filter/src/transaction_name.rs @@ -37,7 +37,7 @@ mod tests { use super::*; - fn _get_patterns() -> GlobPatterns { + fn _get_config() -> IgnoreTransactionsFilterConfig { let patterns_raw = [ "*healthcheck*", "*healthy*", @@ -57,13 +57,16 @@ mod tests { .map(|val| val.to_string()) .to_vec(); - GlobPatterns::new(patterns_raw) + IgnoreTransactionsFilterConfig { + patterns: GlobPatterns::new(patterns_raw), + is_enabled: true, + } } /// tests matching for various transactions #[test] fn test_matches() { - let patterns = _get_patterns(); + let config = _get_config(); let transaction_names = [ "a/b/healthcheck/c", @@ -97,7 +100,10 @@ mod tests { ty: Annotated::new(EventType::Transaction), ..Event::default() }; - assert!(matches(&event, &patterns), "Did not match `{name}`") + assert!( + should_filter(&event, &config).is_err(), + "Did not match `{name}`" + ) } } /// tests non matching transactions transactions @@ -118,7 +124,7 @@ mod tests { "notready", "already", ]; - let patterns = _get_patterns(); + let config = _get_config(); for name in transaction_names { let event = Event { @@ -127,7 +133,7 @@ mod tests { ..Event::default() }; assert!( - !matches(&event, &patterns), + should_filter(&event, &config).is_ok(), "Did match `{name}` but it shouldn't have." ) } @@ -140,9 +146,9 @@ mod tests { ty: Annotated::new(EventType::Transaction), ..Event::default() }; - let patterns = _get_patterns(); + let config = _get_config(); assert!( - !matches(&event, &patterns), + should_filter(&event, &config).is_ok(), "Did match with empty transaction but it shouldn't have." ) } @@ -154,10 +160,7 @@ mod tests { ty: Annotated::new(EventType::Transaction), ..Event::default() }; - let config = IgnoreTransactionsFilterConfig { - patterns: _get_patterns(), - is_enabled: true, - }; + let config = _get_config(); let filter_result = should_filter(&event, &config); assert_eq!( @@ -195,13 +198,9 @@ mod tests { ty: Annotated::new(EventType::Transaction), ..Event::default() }; - let filter_result = should_filter( - &event, - &IgnoreTransactionsFilterConfig { - patterns: _get_patterns(), - is_enabled: false, - }, - ); + let mut config = _get_config(); + config.is_enabled = false; + let filter_result = should_filter(&event, &config); assert_eq!( filter_result, Ok(()), @@ -216,13 +215,7 @@ mod tests { ty: Annotated::new(EventType::Transaction), ..Event::default() }; - let filter_result = should_filter( - &event, - &IgnoreTransactionsFilterConfig { - patterns: _get_patterns(), - is_enabled: true, - }, - ); + let filter_result = should_filter(&event, &_get_config()); assert_eq!( filter_result, Ok(()), @@ -232,10 +225,7 @@ mod tests { #[test] fn test_only_filters_transactions_not_anything_else() { - let config = IgnoreTransactionsFilterConfig { - patterns: _get_patterns(), - is_enabled: true, - }; + let config = _get_config(); for event_type in [EventType::Transaction, EventType::Error, EventType::Csp] { let expect_to_filter = event_type == EventType::Transaction; From 5eede654b0a9f7bb882cb0cdcd272ddfd2aa6bd3 Mon Sep 17 00:00:00 2001 From: Joris Bayer Date: Tue, 9 Apr 2024 10:18:19 +0200 Subject: [PATCH 3/8] ref: imports --- relay-filter/src/browser_extensions.rs | 4 ++-- relay-filter/src/csp.rs | 4 ++-- relay-filter/src/error_messages.rs | 3 +-- relay-filter/src/generic.rs | 4 ++-- relay-filter/src/interface.rs | 24 ++++++++++++++++++------ relay-filter/src/legacy_browsers.rs | 1 - relay-filter/src/lib.rs | 1 - relay-filter/src/localhost.rs | 4 +--- relay-filter/src/transaction_name.rs | 2 +- relay-filter/src/web_crawlers.rs | 1 - 10 files changed, 27 insertions(+), 21 deletions(-) diff --git a/relay-filter/src/browser_extensions.rs b/relay-filter/src/browser_extensions.rs index a32e1945f1..cfdfeda3c1 100644 --- a/relay-filter/src/browser_extensions.rs +++ b/relay-filter/src/browser_extensions.rs @@ -2,7 +2,7 @@ use once_cell::sync::Lazy; use regex::Regex; -use relay_event_schema::protocol::{Event, Exception}; +use relay_event_schema::protocol::Exception; use crate::{FilterConfig, FilterStatKey, Filterable}; @@ -139,7 +139,7 @@ fn get_exception_source(item: &F) -> Option<&str> { #[cfg(test)] mod tests { use relay_event_schema::protocol::{ - Frame, JsonLenientString, RawStacktrace, Stacktrace, Values, + Event, Frame, JsonLenientString, RawStacktrace, Stacktrace, Values, }; use relay_protocol::Annotated; diff --git a/relay-filter/src/csp.rs b/relay-filter/src/csp.rs index 31a6ac0ab9..463263182f 100644 --- a/relay-filter/src/csp.rs +++ b/relay-filter/src/csp.rs @@ -2,7 +2,7 @@ //! //! Events originating from a CSP message can be filtered based on the source URL -use relay_event_schema::protocol::{Csp, Event, EventType}; +use relay_event_schema::protocol::Csp; use crate::{CspFilterConfig, FilterStatKey, Filterable}; @@ -162,7 +162,7 @@ pub fn matches_any_origin(url: Option<&str>, origins: &[SchemeDomainPort]) -> bo #[cfg(test)] mod tests { - use relay_event_schema::protocol::Csp; + use relay_event_schema::protocol::{Csp, Event, EventType}; use relay_protocol::Annotated; use super::*; diff --git a/relay-filter/src/error_messages.rs b/relay-filter/src/error_messages.rs index 5c51bdedda..a29800c17a 100644 --- a/relay-filter/src/error_messages.rs +++ b/relay-filter/src/error_messages.rs @@ -6,7 +6,6 @@ use std::borrow::Cow; use relay_common::glob3::GlobPatterns; -use relay_event_schema::protocol::Event; use crate::{ErrorMessagesFilterConfig, FilterStatKey, Filterable}; @@ -59,7 +58,7 @@ pub fn should_filter( #[cfg(test)] mod tests { - use relay_event_schema::protocol::{Exception, LogEntry, Values}; + use relay_event_schema::protocol::{Event, Exception, LogEntry, Values}; use relay_protocol::Annotated; use super::*; diff --git a/relay-filter/src/generic.rs b/relay-filter/src/generic.rs index 02a7cc02fb..74fe2f03fc 100644 --- a/relay-filter/src/generic.rs +++ b/relay-filter/src/generic.rs @@ -7,7 +7,7 @@ use std::iter::FusedIterator; use crate::{FilterStatKey, GenericFilterConfig, GenericFiltersConfig, GenericFiltersMap}; -use relay_event_schema::protocol::Event; + use relay_protocol::{Getter, RuleCondition}; /// Maximum supported version of the generic filters schema. @@ -173,7 +173,7 @@ mod tests { use super::*; - use relay_event_schema::protocol::LenientString; + use relay_event_schema::protocol::{Event, LenientString}; use relay_protocol::Annotated; fn mock_filters() -> GenericFiltersMap { diff --git a/relay-filter/src/interface.rs b/relay-filter/src/interface.rs index 432197ab71..d751cb10b3 100644 --- a/relay-filter/src/interface.rs +++ b/relay-filter/src/interface.rs @@ -1,22 +1,34 @@ -//! TODO: docs +//! This module contains the trait for items that can be filtered by Inbound Filters, plus +//! the implementation for [`Event`]. use relay_event_schema::protocol::{Csp, Event, EventType, Exception, LogEntry, Values}; use url::Url; -/// TODO: docs +/// A data item to which filters can be applied. pub trait Filterable { - /// TODO: docs - + /// The CSP report contained in the item. Only for CSP reports. fn csp(&self) -> Option<&Csp>; + + /// The exception values of the item. Only for error events. fn exceptions(&self) -> Option<&Values>; + + /// The IP address of the client that sent the data. fn ip_addr(&self) -> Option<&str>; + + /// The logentry message. Only for error events. fn logentry(&self) -> Option<&LogEntry>; + + /// The release string of the data item. fn release(&self) -> Option<&str>; + + /// The transaction name. Only for transaction events. fn transaction(&self) -> Option<&str>; + + /// The URL from which the data originates. Used for localhost filtering. fn url(&self) -> Option; - fn user_agent(&self) -> Option<&str>; - // fn exceptions(&self) -> Option<&Exce + /// The user agent of the client that sent the data. + fn user_agent(&self) -> Option<&str>; } impl Filterable for Event { diff --git a/relay-filter/src/legacy_browsers.rs b/relay-filter/src/legacy_browsers.rs index 14306a1a95..e68f29d3a8 100644 --- a/relay-filter/src/legacy_browsers.rs +++ b/relay-filter/src/legacy_browsers.rs @@ -2,7 +2,6 @@ use std::collections::BTreeSet; -use relay_event_schema::protocol::Event; use relay_ua::UserAgent; use crate::{FilterStatKey, Filterable, LegacyBrowser, LegacyBrowsersFilterConfig}; diff --git a/relay-filter/src/lib.rs b/relay-filter/src/lib.rs index 321ce4242b..90ff67f961 100644 --- a/relay-filter/src/lib.rs +++ b/relay-filter/src/lib.rs @@ -14,7 +14,6 @@ use std::net::IpAddr; -use relay_event_schema::protocol::Event; use relay_protocol::Getter; pub mod browser_extensions; diff --git a/relay-filter/src/localhost.rs b/relay-filter/src/localhost.rs index 1fac0aadcb..43fe925d0d 100644 --- a/relay-filter/src/localhost.rs +++ b/relay-filter/src/localhost.rs @@ -1,6 +1,4 @@ //! Implements filtering for events originating from the localhost -use relay_event_schema::protocol::Event; -use url::Url; use crate::{FilterConfig, FilterStatKey, Filterable}; @@ -49,7 +47,7 @@ where #[cfg(test)] mod tests { - use relay_event_schema::protocol::{IpAddr, Request, User}; + use relay_event_schema::protocol::{Event, IpAddr, Request, User}; use relay_protocol::Annotated; use super::*; diff --git a/relay-filter/src/transaction_name.rs b/relay-filter/src/transaction_name.rs index e97a95c7d6..ba7dc4ec98 100644 --- a/relay-filter/src/transaction_name.rs +++ b/relay-filter/src/transaction_name.rs @@ -3,7 +3,6 @@ //! If this filter is enabled transactions from healthcheck endpoints will be filtered out. use relay_common::glob3::GlobPatterns; -use relay_event_schema::protocol::{Event, EventType}; use crate::{FilterStatKey, Filterable, IgnoreTransactionsFilterConfig}; @@ -33,6 +32,7 @@ pub fn should_filter( #[cfg(test)] mod tests { + use relay_event_schema::protocol::{Event, EventType}; use relay_protocol::Annotated; use super::*; diff --git a/relay-filter/src/web_crawlers.rs b/relay-filter/src/web_crawlers.rs index e19c5166a2..de5d547621 100644 --- a/relay-filter/src/web_crawlers.rs +++ b/relay-filter/src/web_crawlers.rs @@ -2,7 +2,6 @@ use once_cell::sync::Lazy; use regex::Regex; -use relay_event_schema::protocol::Event; use crate::{FilterConfig, FilterStatKey, Filterable}; From c5979ff65d393b9246f49d7ac510e746ecf4fbf5 Mon Sep 17 00:00:00 2001 From: Joris Bayer Date: Tue, 9 Apr 2024 10:20:38 +0200 Subject: [PATCH 4/8] ref: doc --- relay-filter/Cargo.toml | 2 +- relay-filter/src/csp.rs | 4 ---- relay-filter/src/generic.rs | 6 +++++- relay-filter/src/transaction_name.rs | 4 ---- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/relay-filter/Cargo.toml b/relay-filter/Cargo.toml index 8dfcdd3f6a..f418564f91 100644 --- a/relay-filter/Cargo.toml +++ b/relay-filter/Cargo.toml @@ -18,7 +18,7 @@ once_cell = { workspace = true } indexmap = { workspace = true } regex = { workspace = true } relay-common = { workspace = true } -relay-event-schema = { workspace = true } # TODO: not needed? +relay-event-schema = { workspace = true } relay-protocol = { workspace = true } relay-ua = { workspace = true } serde = { workspace = true } diff --git a/relay-filter/src/csp.rs b/relay-filter/src/csp.rs index 463263182f..04ee446c63 100644 --- a/relay-filter/src/csp.rs +++ b/relay-filter/src/csp.rs @@ -12,10 +12,6 @@ where It: IntoIterator, S: AsRef, { - // if event.ty.value() != Some(&EventType::Csp) { - // return false; - // } // TODO: move to trait - // parse the sources for easy processing let disallowed_sources: Vec = disallowed_sources .into_iter() diff --git a/relay-filter/src/generic.rs b/relay-filter/src/generic.rs index 74fe2f03fc..c5b3eb0642 100644 --- a/relay-filter/src/generic.rs +++ b/relay-filter/src/generic.rs @@ -31,7 +31,11 @@ fn matches(item: &F, condition: Option<&RuleCondition>) -> bool { condition.map_or(false, |condition| condition.matches(item)) } -/// Filters events by patterns in their error messages. +/// Filters events by any generic condition. +/// +/// Note that conditions may have type-specific getter strings, e.g. `"event.some_field"`. In order +/// to make such a generic filter apply to non-Event types, make sure that the [`Getter`] implementation +/// for that type maps `"event.some_field"` to the corresponding field on that type. pub(crate) fn should_filter( item: &F, project_filters: &GenericFiltersConfig, diff --git a/relay-filter/src/transaction_name.rs b/relay-filter/src/transaction_name.rs index ba7dc4ec98..035e25ef9b 100644 --- a/relay-filter/src/transaction_name.rs +++ b/relay-filter/src/transaction_name.rs @@ -7,10 +7,6 @@ use relay_common::glob3::GlobPatterns; use crate::{FilterStatKey, Filterable, IgnoreTransactionsFilterConfig}; fn matches(transaction: Option<&str>, patterns: &GlobPatterns) -> bool { - // if event.ty.value() != Some(&EventType::Transaction) { - // return false; - // } // TODO: move to trait impl - transaction.map_or(false, |transaction| patterns.is_match(transaction)) } From 8159767c6adca9cf5a05981f19b0017784e26714 Mon Sep 17 00:00:00 2001 From: Joris Bayer Date: Tue, 9 Apr 2024 10:33:15 +0200 Subject: [PATCH 5/8] fix: doc link --- relay-filter/src/transaction_name.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/relay-filter/src/transaction_name.rs b/relay-filter/src/transaction_name.rs index 035e25ef9b..5968b7369b 100644 --- a/relay-filter/src/transaction_name.rs +++ b/relay-filter/src/transaction_name.rs @@ -10,7 +10,7 @@ fn matches(transaction: Option<&str>, patterns: &GlobPatterns) -> bool { transaction.map_or(false, |transaction| patterns.is_match(transaction)) } -/// Filters [Transaction](EventType::Transaction) events based on a list of provided transaction +/// Filters [Transaction](relay_event_schema::protocol::EventType::Transaction) events based on a list of provided transaction /// name globs. pub fn should_filter( item: &F, From d0f195d3467e864891165205e94ae658aa445f09 Mon Sep 17 00:00:00 2001 From: Joris Bayer Date: Tue, 9 Apr 2024 10:36:54 +0200 Subject: [PATCH 6/8] pub -> private --- relay-filter/src/browser_extensions.rs | 2 +- relay-filter/src/client_ips.rs | 2 +- relay-filter/src/csp.rs | 2 +- relay-filter/src/error_messages.rs | 2 +- relay-filter/src/interface.rs | 2 +- relay-filter/src/legacy_browsers.rs | 2 +- relay-filter/src/localhost.rs | 2 +- relay-filter/src/web_crawlers.rs | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/relay-filter/src/browser_extensions.rs b/relay-filter/src/browser_extensions.rs index cfdfeda3c1..2f3636f9e3 100644 --- a/relay-filter/src/browser_extensions.rs +++ b/relay-filter/src/browser_extensions.rs @@ -81,7 +81,7 @@ static EXTENSION_EXC_SOURCES: Lazy = Lazy::new(|| { const ANONYMOUS_FRAMES: [&str; 2] = ["", "[native code]"]; /// Check if the event originates from known problematic browser extensions. -pub fn matches(item: &F) -> bool { +fn matches(item: &F) -> bool { if let Some(ex_val) = get_exception_value(item) { if EXTENSION_EXC_VALUES.is_match(ex_val) { return true; diff --git a/relay-filter/src/client_ips.rs b/relay-filter/src/client_ips.rs index a62975c850..2de102063a 100644 --- a/relay-filter/src/client_ips.rs +++ b/relay-filter/src/client_ips.rs @@ -15,7 +15,7 @@ use crate::{ClientIpsFilterConfig, FilterStatKey}; /// The client IP is the address of the originator of the event. If it was forwarded through /// multiple proxies, this address should be derived from the `X-Forwarded-For` header. Otherwise, /// it is the remote socket address. -pub fn matches(client_ip: Option, blacklisted_ips: It) -> bool +fn matches(client_ip: Option, blacklisted_ips: It) -> bool where It: IntoIterator, S: AsRef, diff --git a/relay-filter/src/csp.rs b/relay-filter/src/csp.rs index 04ee446c63..a980d672d3 100644 --- a/relay-filter/src/csp.rs +++ b/relay-filter/src/csp.rs @@ -7,7 +7,7 @@ use relay_event_schema::protocol::Csp; use crate::{CspFilterConfig, FilterStatKey, Filterable}; /// Checks if the event is a CSP Event from one of the disallowed sources. -pub fn matches(csp: Option<&Csp>, disallowed_sources: It) -> bool +fn matches(csp: Option<&Csp>, disallowed_sources: It) -> bool where It: IntoIterator, S: AsRef, diff --git a/relay-filter/src/error_messages.rs b/relay-filter/src/error_messages.rs index a29800c17a..bab2ca0248 100644 --- a/relay-filter/src/error_messages.rs +++ b/relay-filter/src/error_messages.rs @@ -10,7 +10,7 @@ use relay_common::glob3::GlobPatterns; use crate::{ErrorMessagesFilterConfig, FilterStatKey, Filterable}; /// Checks events by patterns in their error messages. -pub fn matches(item: &F, patterns: &GlobPatterns) -> bool { +fn matches(item: &F, patterns: &GlobPatterns) -> bool { if let Some(logentry) = item.logentry() { if let Some(message) = logentry.formatted.value() { if patterns.is_match(message.as_ref()) { diff --git a/relay-filter/src/interface.rs b/relay-filter/src/interface.rs index d751cb10b3..f85bd3defe 100644 --- a/relay-filter/src/interface.rs +++ b/relay-filter/src/interface.rs @@ -1,8 +1,8 @@ //! This module contains the trait for items that can be filtered by Inbound Filters, plus //! the implementation for [`Event`]. +use url::Url; use relay_event_schema::protocol::{Csp, Event, EventType, Exception, LogEntry, Values}; -use url::Url; /// A data item to which filters can be applied. pub trait Filterable { diff --git a/relay-filter/src/legacy_browsers.rs b/relay-filter/src/legacy_browsers.rs index e68f29d3a8..35d7a19aa6 100644 --- a/relay-filter/src/legacy_browsers.rs +++ b/relay-filter/src/legacy_browsers.rs @@ -7,7 +7,7 @@ use relay_ua::UserAgent; use crate::{FilterStatKey, Filterable, LegacyBrowser, LegacyBrowsersFilterConfig}; /// Checks if the event originates from legacy browsers. -pub fn matches(user_agent: &str, browsers: &BTreeSet) -> bool { +fn matches(user_agent: &str, browsers: &BTreeSet) -> bool { let user_agent = relay_ua::parse_user_agent(user_agent); // remap IE Mobile to IE (sentry python, filter compatibility) diff --git a/relay-filter/src/localhost.rs b/relay-filter/src/localhost.rs index 43fe925d0d..3fc495ed58 100644 --- a/relay-filter/src/localhost.rs +++ b/relay-filter/src/localhost.rs @@ -6,7 +6,7 @@ const LOCAL_IPS: &[&str] = &["127.0.0.1", "::1"]; const LOCAL_DOMAINS: &[&str] = &["127.0.0.1", "localhost"]; /// Check if the event originates from the local host. -pub fn matches(item: &F) -> bool { +fn matches(item: &F) -> bool { if let Some(ip_addr) = item.ip_addr() { for &local_ip in LOCAL_IPS { if local_ip == ip_addr { diff --git a/relay-filter/src/web_crawlers.rs b/relay-filter/src/web_crawlers.rs index de5d547621..60cf49d28e 100644 --- a/relay-filter/src/web_crawlers.rs +++ b/relay-filter/src/web_crawlers.rs @@ -48,7 +48,7 @@ static ALLOWED_WEB_CRAWLERS: Lazy = Lazy::new(|| { }); /// Checks if the event originates from a known web crawler. -pub fn matches(user_agent: Option<&str>) -> bool { +fn matches(user_agent: Option<&str>) -> bool { if let Some(user_agent) = user_agent { WEB_CRAWLERS.is_match(user_agent) && !ALLOWED_WEB_CRAWLERS.is_match(user_agent) } else { From 082a4207e3d89a8eb5840d5661e05b1785277531 Mon Sep 17 00:00:00 2001 From: Joris Bayer Date: Tue, 9 Apr 2024 14:26:21 +0200 Subject: [PATCH 7/8] Update relay-filter/src/interface.rs Co-authored-by: Iker Barriocanal <32816711+iker-barriocanal@users.noreply.github.com> --- relay-filter/src/interface.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/relay-filter/src/interface.rs b/relay-filter/src/interface.rs index f85bd3defe..817f6d555b 100644 --- a/relay-filter/src/interface.rs +++ b/relay-filter/src/interface.rs @@ -24,7 +24,7 @@ pub trait Filterable { /// The transaction name. Only for transaction events. fn transaction(&self) -> Option<&str>; - /// The URL from which the data originates. Used for localhost filtering. + /// The URL from which the request originates. Used for localhost filtering. fn url(&self) -> Option; /// The user agent of the client that sent the data. From 6cdea4b2a0939e8900f2564368dd47256343180f Mon Sep 17 00:00:00 2001 From: Joris Bayer Date: Tue, 9 Apr 2024 14:42:47 +0200 Subject: [PATCH 8/8] inline --- relay-filter/src/browser_extensions.rs | 5 +---- relay-filter/src/localhost.rs | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/relay-filter/src/browser_extensions.rs b/relay-filter/src/browser_extensions.rs index 2f3636f9e3..c71836b757 100644 --- a/relay-filter/src/browser_extensions.rs +++ b/relay-filter/src/browser_extensions.rs @@ -96,10 +96,7 @@ fn matches(item: &F) -> bool { } /// Filters events originating from known problematic browser extensions. -pub fn should_filter(item: &F, config: &FilterConfig) -> Result<(), FilterStatKey> -where - F: Filterable, -{ +pub fn should_filter(item: &F, config: &FilterConfig) -> Result<(), FilterStatKey> { if !config.is_enabled { return Ok(()); } diff --git a/relay-filter/src/localhost.rs b/relay-filter/src/localhost.rs index 3fc495ed58..a8d3dccb37 100644 --- a/relay-filter/src/localhost.rs +++ b/relay-filter/src/localhost.rs @@ -32,10 +32,7 @@ fn matches(item: &F) -> bool { } /// Filters events originating from the local host. -pub fn should_filter(item: &F, config: &FilterConfig) -> Result<(), FilterStatKey> -where - F: Filterable, -{ +pub fn should_filter(item: &F, config: &FilterConfig) -> Result<(), FilterStatKey> { if !config.is_enabled { return Ok(()); }