Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(filters): Access fields through trait #3397

Merged
merged 8 commits into from
Apr 9, 2024

Conversation

jjbayer
Copy link
Member

@jjbayer jjbayer commented Apr 9, 2024

Currently, inbound filters only work for event types, that is error events and transactions. In the near future we will want inbound filters to apply to other data types as well, such as standalone spans and session replays. To prepare for this generalization, make filters act on a trait that supplies the necessary field instead of the Event itself:

// `Filterable` for legacy inbound filters,
// `Getter` for generic inbound filters.
pub fn should_filter<F: Filterable + Getter>(item: &F, ...); 

ref: #3317

#skip-changelog

@jjbayer jjbayer changed the title Ref/inbound filters interface ref(filters): Access fields through trait Apr 9, 2024
Comment on lines -11 to -13
if event.ty.value() != Some(&EventType::Transaction) {
return false;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check moved to the trait implementation.

use relay_event_schema::protocol::{Csp, Event, EventType, Exception, LogEntry, Values};

/// A data item to which filters can be applied.
pub trait Filterable {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm open for ideas on how to name this trait.

pub fn matches(event: &Event, browsers: &BTreeSet<LegacyBrowser>) -> bool {
if let Some(user_agent_string) = event.user_agent() {
let user_agent = relay_ua::parse_user_agent(user_agent_string);
fn matches(user_agent: &str, browsers: &BTreeSet<LegacyBrowser>) -> bool {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the matches functions private everywhere, they do not need to be public.

@jjbayer jjbayer marked this pull request as ready for review April 9, 2024 08:54
@jjbayer jjbayer requested a review from a team as a code owner April 9, 2024 08:54
@jjbayer jjbayer requested a review from cmanallen April 9, 2024 08:54
Copy link
Contributor

@iker-barriocanal iker-barriocanal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we should align all matches implementations for consistency -- sometimes they take item (convenience) and some others just the value to filter on.

relay-filter/src/interface.rs Outdated Show resolved Hide resolved
relay-filter/src/interface.rs Show resolved Hide resolved
relay-filter/src/localhost.rs Outdated Show resolved Hide resolved
Co-authored-by: Iker Barriocanal <32816711+iker-barriocanal@users.noreply.github.com>
Copy link
Member

@cmanallen cmanallen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect. This will be easy to implement for replays.

Copy link
Member Author

@jjbayer jjbayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we should align all matches implementations for consistency

@iker-barriocanal They are all private functions, so IMO they should do what makes the most sense in local context. I pass the value directly where the function needs only that value, and the full item in cases where the function needs more than one value. Let me know if that makes sense.

relay-filter/src/interface.rs Show resolved Hide resolved
relay-filter/src/localhost.rs Outdated Show resolved Hide resolved
@jjbayer jjbayer enabled auto-merge (squash) April 9, 2024 13:59
@jjbayer jjbayer merged commit c7bc957 into master Apr 9, 2024
20 checks passed
@jjbayer jjbayer deleted the ref/inbound-filters-interface branch April 9, 2024 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants