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

feat(spans): Add inbound filters for spans #3552

Merged
merged 26 commits into from
May 21, 2024

Conversation

iambriccardo
Copy link
Member

@iambriccardo iambriccardo commented May 6, 2024

This PR adds support for inbound filters on spans which as of now should happen only on processing relays.

Closes: #3550

@@ -98,6 +102,19 @@ pub fn process(
_ => return ItemAction::Keep,
};

if let Some(span) = annotated_span.value() {
Copy link
Member Author

Choose a reason for hiding this comment

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

After some different implementations, I settled on just putting the filtering here, even though I don't know if it should be put into the process function. The only thing I know is that separating into two functions would require quite a bit of refactoring.

@@ -375,6 +375,7 @@ impl Getter for SpanData {
"ui\\.component_name" => self.ui_component_name.value()?.into(),
"url\\.scheme" => self.url_scheme.value()?.into(),
"transaction" => self.segment_name.as_str()?.into(),
"release" => self.release.as_str()?.into(),
Copy link
Member Author

Choose a reason for hiding this comment

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

Added this field since it was not there.

@@ -108,3 +110,41 @@ impl Filterable for Replay {
self.user_agent()
}
}

impl Filterable for Span {
Copy link
Member Author

Choose a reason for hiding this comment

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

We might want to extend the impl of the methods returning None in case we find a way to access those fields on the Span.

@iambriccardo iambriccardo marked this pull request as ready for review May 7, 2024 07:41
@iambriccardo iambriccardo requested a review from a team as a code owner May 7, 2024 07:41
@@ -3475,10 +3475,10 @@ mod tests {
processor.handle_process_metrics(&mut token, message);

let value = project_cache_rx.recv().await.unwrap();
let ProjectCache::MergeBuckets(merge_buckets) = value else {
let ProjectCache::AddMetricBuckets(add_metric_buckets) = value else {
Copy link
Member Author

Choose a reason for hiding this comment

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

Had to fix these tests for the PR to pass CI. The failures are related to: fc1c2aa

Copy link
Member

Choose a reason for hiding this comment

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

I think you can just merge or rebase on latest master, see #3560.

CHANGELOG.md Outdated Show resolved Hide resolved
relay-filter/src/interface.rs Outdated Show resolved Hide resolved
relay-filter/src/interface.rs Outdated Show resolved Hide resolved
@@ -3475,10 +3475,10 @@ mod tests {
processor.handle_process_metrics(&mut token, message);

let value = project_cache_rx.recv().await.unwrap();
let ProjectCache::MergeBuckets(merge_buckets) = value else {
let ProjectCache::AddMetricBuckets(add_metric_buckets) = value else {
Copy link
Member

Choose a reason for hiding this comment

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

I think you can just merge or rebase on latest master, see #3560.

relay-server/src/services/processor/span/processing.rs Outdated Show resolved Hide resolved
tests/integration/test_spans.py Outdated Show resolved Hide resolved
relay-filter/src/interface.rs Outdated Show resolved Hide resolved
relay-filter/src/interface.rs Outdated Show resolved Hide resolved
@iambriccardo iambriccardo requested a review from jjbayer May 8, 2024 13:49
Copy link
Member

@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.

Looks good! Please see comments before merging.

relay-filter/src/interface.rs Outdated Show resolved Hide resolved
assert summarize_outcomes() == {(12, 1): 1}

spans_consumer.assert_empty()
outcomes_consumer.assert_empty()
Copy link
Member

Choose a reason for hiding this comment

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

nit: Because integration tests take a long time to run, I suggest keeping only one of these two integration tests, and cover other filters with unit tests. See for example

#[test]
fn test_filters_known_blocked_source_files() {
let event = get_csp_event(None, Some("http://known.bad.com"), None);
let config = CspFilterConfig {
disallowed_sources: vec!["http://known.bad.com".to_string()],
};
let actual = should_filter(&event, &config);
assert_ne!(
actual,
Ok(()),
"CSP filter should have filtered known bad source file"
);
}

@@ -1594,3 +1594,71 @@ def test_span_extraction_with_tags(
assert transaction_span["tags"] == expected_tags

spans_consumer.assert_empty()


def test_span_filtering_with_generic_inbound_filter(
Copy link
Member Author

Choose a reason for hiding this comment

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

Created just one integration test for the end-to-end behavior since i tested other filters directly in unit tests.

@iambriccardo iambriccardo merged commit a404208 into master May 21, 2024
22 checks passed
@iambriccardo iambriccardo deleted the riccardo/feat/inbound-filters-spans branch May 21, 2024 09:01
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.

Call inbound filter logic in in span::process.
2 participants