diff --git a/CHANGELOG.md b/CHANGELOG.md index b899b614a09..03df88cd489 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Extract OTLP spans' client sample rate from TraceState. ([#6312](https://github.com/getsentry/relay/pull/6312)) - Raise the size limit for the flags context to 128 KiB. ([#6310](https://github.com/getsentry/relay/pull/6310)) +- Add support for more inbound filters for logs, trace metrics and spans. ([#6306](https://github.com/getsentry/relay/pull/6306)) - Raise the size limit for logs to 2 MiB. ([#6316](https://github.com/getsentry/relay/pull/6316)) - Include the environment in the cron check-in routing key so a monitor's environments no longer share a single Kafka partition. ([#6331](https://github.com/getsentry/relay/pull/6331)) diff --git a/relay-filter/src/interface.rs b/relay-filter/src/interface.rs index b0636b6f287..2fe465c3579 100644 --- a/relay-filter/src/interface.rs +++ b/relay-filter/src/interface.rs @@ -196,26 +196,6 @@ impl Filterable for Span { } } -impl Filterable for SpanV2 { - fn release(&self) -> Option<&str> { - self.attributes - .value()? - .get_value(SENTRY__RELEASE)? - .as_str() - } - - fn transaction(&self) -> Option<&str> { - self.attributes - .value()? - .get_value(SENTRY__SEGMENT__NAME)? - .as_str() - } - - fn user_agent(&self) -> UserAgent<'_> { - user_agent_from_attributes(&self.attributes) - } -} - impl Filterable for SessionUpdate { fn ip_addr(&self) -> Option<&str> { self.attributes @@ -256,32 +236,46 @@ impl Filterable for SessionAggregates { } } -impl Filterable for OurLog { - fn release(&self) -> Option<&str> { - self.attributes - .value()? - .get_value(SENTRY__RELEASE)? - .as_str() - } +macro_rules! impl_for_attributes { + ($ty:ty) => { + impl Filterable for $ty { + fn ip_addr(&self) -> Option<&str> { + self.attributes + .value()? + .get_value(CLIENT__ADDRESS)? + .as_str() + } - fn user_agent(&self) -> UserAgent<'_> { - user_agent_from_attributes(&self.attributes) - } -} + fn release(&self) -> Option<&str> { + self.attributes + .value()? + .get_value(SENTRY__RELEASE)? + .as_str() + } -impl Filterable for TraceMetric { - fn release(&self) -> Option<&str> { - self.attributes - .value()? - .get_value(SENTRY__RELEASE)? - .as_str() - } + fn transaction(&self) -> Option<&str> { + self.attributes + .value()? + .get_value(SENTRY__SEGMENT__NAME)? + .as_str() + } - fn user_agent(&self) -> UserAgent<'_> { - user_agent_from_attributes(&self.attributes) - } + fn url(&self) -> Option { + let url = self.attributes.value()?.get_value(URL__FULL)?.as_str()?; + Url::parse(url).ok() + } + + fn user_agent(&self) -> UserAgent<'_> { + user_agent_from_attributes(&self.attributes) + } + } + }; } +impl_for_attributes!(SpanV2); +impl_for_attributes!(OurLog); +impl_for_attributes!(TraceMetric); + fn user_agent_from_attributes(attributes: &relay_protocol::Annotated) -> UserAgent<'_> { let parsed = (|| { let attributes = attributes.value()?; diff --git a/tests/integration/test_ourlogs.py b/tests/integration/test_ourlogs.py index 63e725f3d52..b18089877ab 100644 --- a/tests/integration/test_ourlogs.py +++ b/tests/integration/test_ourlogs.py @@ -937,6 +937,42 @@ def test_browser_name_version_extraction( {}, id="release", ), + pytest.param( + "filtered-transaction", + {"ignoreTransactions": {"isEnabled": True, "patterns": ["*health*"]}}, + { + "attributes": { + "sentry.segment.name": { + "value": "/foo/healthz", + "type": "string", + } + } + }, + id="transaction", + ), + pytest.param( + "localhost", + {"localhost": {"isEnabled": True}}, + { + "attributes": { + "client.address": {"value": "127.0.0.1", "type": "string"} + } + }, + id="localhost-ip", + ), + pytest.param( + "localhost", + {"localhost": {"isEnabled": True}}, + { + "attributes": { + "url.full": { + "value": "http://localhost:8000/foo", + "type": "string", + } + } + }, + id="localhost-url", + ), pytest.param( "legacy-browsers", {"legacyBrowsers": {"isEnabled": True, "options": ["ie9"]}}, @@ -1021,6 +1057,14 @@ def test_filters_are_applied_to_logs( "attributes": { "some_integer": {"value": 123, "type": "integer"}, "sentry.release": {"value": "foobar@1.0", "type": "string"}, + **args.get("attributes", {}), + }, + }, + metadata={ + "version": 2, + "ingest_settings": { + "infer_ip": "never", + "infer_user_agent": "auto", }, }, ) diff --git a/tests/integration/test_spansv2.py b/tests/integration/test_spansv2.py index 656626903f7..32b7a3ed2f9 100644 --- a/tests/integration/test_spansv2.py +++ b/tests/integration/test_spansv2.py @@ -1000,6 +1000,29 @@ def test_spansv2_ds_root_in_different_org( {}, id="transaction", ), + pytest.param( + "localhost", + {"localhost": {"isEnabled": True}}, + { + "attributes": { + "client.address": {"value": "127.0.0.1", "type": "string"} + } + }, + id="localhost-ip", + ), + pytest.param( + "localhost", + {"localhost": {"isEnabled": True}}, + { + "attributes": { + "url.full": { + "value": "http://localhost:8000/foo", + "type": "string", + } + } + }, + id="localhost-url", + ), pytest.param( "legacy-browsers", {"legacyBrowsers": {"isEnabled": True, "options": ["ie9"]}}, @@ -1081,11 +1104,13 @@ def test_spanv2_inbound_filters( "some_integer": {"value": 123, "type": "integer"}, "sentry.release": {"value": "foobar@1.0", "type": "string"}, "sentry.segment.name": {"value": "/foo/healthz", "type": "string"}, + **args.get("attributes", {}), }, }, metadata={ "version": 2, "ingest_settings": { + "infer_ip": "never", "infer_user_agent": "auto", }, }, diff --git a/tests/integration/test_trace_metrics.py b/tests/integration/test_trace_metrics.py index 982c291b196..6cf4fdd1406 100644 --- a/tests/integration/test_trace_metrics.py +++ b/tests/integration/test_trace_metrics.py @@ -1029,6 +1029,42 @@ def test_trace_metric_container_metadata( {}, id="release", ), + pytest.param( + "filtered-transaction", + {"ignoreTransactions": {"isEnabled": True, "patterns": ["*health*"]}}, + { + "attributes": { + "sentry.segment.name": { + "value": "/foo/healthz", + "type": "string", + } + } + }, + id="transaction", + ), + pytest.param( + "localhost", + {"localhost": {"isEnabled": True}}, + { + "attributes": { + "client.address": {"value": "127.0.0.1", "type": "string"} + } + }, + id="localhost-ip", + ), + pytest.param( + "localhost", + {"localhost": {"isEnabled": True}}, + { + "attributes": { + "url.full": { + "value": "http://localhost:8000/foo", + "type": "string", + } + } + }, + id="localhost-url", + ), pytest.param( "legacy-browsers", {"legacyBrowsers": {"isEnabled": True, "options": ["ie9"]}}, @@ -1102,7 +1138,7 @@ def test_filters_are_applied_to_trace_metrics( metadata = { "version": 2, - "ingest_settings": {"infer_ip": "auto", "infer_user_agent": "auto"}, + "ingest_settings": {"infer_ip": "never", "infer_user_agent": "auto"}, } envelope = envelope_with_trace_metrics( @@ -1115,6 +1151,7 @@ def test_filters_are_applied_to_trace_metrics( "attributes": { "http.status_code": {"value": 500, "type": "integer"}, "sentry.release": {"value": "foobar@1.0", "type": "string"}, + **args.get("attributes", {}), }, }, metadata=metadata,