diff --git a/relay-event-normalization/src/event.rs b/relay-event-normalization/src/event.rs index 43cb8784fb8..16620b78a4e 100644 --- a/relay-event-normalization/src/event.rs +++ b/relay-event-normalization/src/event.rs @@ -30,7 +30,7 @@ use uuid::Uuid; use crate::normalize::request; use crate::span::ai::enrich_ai_event_data; -use crate::span::tag_extraction::extract_span_tags_from_event; +use crate::span::tag_extraction::{extract_segment_name_from_event, extract_span_tags_from_event}; use crate::utils::{self, MAX_DURATION_MOBILE_MS, get_event_user_tag}; use crate::{ BorrowedSpanOpDefaults, BreakdownsConfig, CombinedMeasurementsConfig, GeoIpLookup, MaxChars, @@ -347,6 +347,7 @@ fn normalize(event: &mut Event, meta: &mut Meta, config: &NormalizationConfig) { config.max_tag_value_length, config.span_allowed_hosts, ); + extract_segment_name_from_event(event); } if let Some(context) = event.context_mut::() { diff --git a/relay-event-normalization/src/normalize/span/tag_extraction.rs b/relay-event-normalization/src/normalize/span/tag_extraction.rs index 8cf8f7607ee..92a331ff51c 100644 --- a/relay-event-normalization/src/normalize/span/tag_extraction.rs +++ b/relay-event-normalization/src/normalize/span/tag_extraction.rs @@ -59,6 +59,30 @@ impl std::fmt::Display for RenderBlockingStatus { } } +/// Extracts the `transaction` field and writes it into child spans +/// as `data.segment_name`. +pub(crate) fn extract_segment_name_from_event(event: &mut Event) { + let Some(transaction) = event.transaction.value() else { + return; + }; + + let Some(spans) = event.spans.value_mut() else { + return; + }; + + for span in spans { + let Some(span) = span.value_mut() else { + continue; + }; + + let data = span.data.get_or_insert_with(Default::default); + + if data.segment_name.is_empty() { + data.segment_name = Annotated::new(transaction.clone()); + } + } +} + /// Wrapper for [`extract_span_tags`]. /// /// Tags longer than `max_tag_value_size` bytes will be truncated. diff --git a/relay-spans/src/v1_to_v2.rs b/relay-spans/src/v1_to_v2.rs index 0359ac998d8..60a17b622e5 100644 --- a/relay-spans/src/v1_to_v2.rs +++ b/relay-spans/src/v1_to_v2.rs @@ -476,7 +476,7 @@ mod tests { .attributes .value() .unwrap() - .get_value("sentry.segment.name") + .get_value(SENTRY__SEGMENT__NAME) .and_then(Value::as_str), Some("hi") ); diff --git a/tests/integration/test_ai.py b/tests/integration/test_ai.py index 8622a134cc8..092c9da9e4d 100644 --- a/tests/integration/test_ai.py +++ b/tests/integration/test_ai.py @@ -429,6 +429,7 @@ def test_ai_spans_example_transaction( "sentry.sdk.name": {"type": "string", "value": "raven-node"}, "sentry.sdk.version": {"type": "string", "value": "2.6.3"}, "sentry.segment.id": {"type": "string", "value": "657cf984a6a4e59b"}, + "sentry.segment.name": {"type": "string", "value": "main"}, "sentry.status": {"type": "string", "value": "ok"}, "sentry.trace.status": {"type": "string", "value": "ok"}, "sentry.transaction": {"type": "string", "value": "main"}, @@ -543,6 +544,7 @@ def test_ai_spans_example_transaction( "sentry.sdk.name": {"type": "string", "value": "raven-node"}, "sentry.sdk.version": {"type": "string", "value": "2.6.3"}, "sentry.segment.id": {"type": "string", "value": "657cf984a6a4e59b"}, + "sentry.segment.name": {"type": "string", "value": "main"}, "sentry.status": {"type": "string", "value": "ok"}, "sentry.trace.status": {"type": "string", "value": "ok"}, "sentry.transaction": {"type": "string", "value": "main"}, @@ -646,6 +648,7 @@ def test_ai_spans_example_transaction( "sentry.sdk.name": {"type": "string", "value": "raven-node"}, "sentry.sdk.version": {"type": "string", "value": "2.6.3"}, "sentry.segment.id": {"type": "string", "value": "657cf984a6a4e59b"}, + "sentry.segment.name": {"type": "string", "value": "main"}, "sentry.status": {"type": "string", "value": "ok"}, "sentry.status_code": {"type": "string", "value": "200"}, "sentry.trace.status": {"type": "string", "value": "ok"}, @@ -729,6 +732,7 @@ def test_ai_spans_example_transaction( "sentry.sdk.name": {"type": "string", "value": "raven-node"}, "sentry.sdk.version": {"type": "string", "value": "2.6.3"}, "sentry.segment.id": {"type": "string", "value": "657cf984a6a4e59b"}, + "sentry.segment.name": {"type": "string", "value": "main"}, "sentry.status": {"type": "string", "value": "ok"}, "sentry.trace.status": {"type": "string", "value": "ok"}, "sentry.transaction": {"type": "string", "value": "main"}, @@ -795,6 +799,7 @@ def test_ai_spans_example_transaction( "sentry.sdk.name": {"type": "string", "value": "raven-node"}, "sentry.sdk.version": {"type": "string", "value": "2.6.3"}, "sentry.segment.id": {"type": "string", "value": "657cf984a6a4e59b"}, + "sentry.segment.name": {"type": "string", "value": "main"}, "sentry.status": {"type": "string", "value": "ok"}, "sentry.status_code": {"type": "string", "value": "200"}, "sentry.trace.status": {"type": "string", "value": "ok"}, @@ -871,6 +876,7 @@ def test_ai_spans_example_transaction( "sentry.sdk.name": {"type": "string", "value": "raven-node"}, "sentry.sdk.version": {"type": "string", "value": "2.6.3"}, "sentry.segment.id": {"type": "string", "value": "657cf984a6a4e59b"}, + "sentry.segment.name": {"type": "string", "value": "main"}, "sentry.status": {"type": "string", "value": "ok"}, "sentry.trace.status": {"type": "string", "value": "ok"}, "sentry.transaction": {"type": "string", "value": "main"}, @@ -937,6 +943,7 @@ def test_ai_spans_example_transaction( "sentry.sdk.name": {"type": "string", "value": "raven-node"}, "sentry.sdk.version": {"type": "string", "value": "2.6.3"}, "sentry.segment.id": {"type": "string", "value": "657cf984a6a4e59b"}, + "sentry.segment.name": {"type": "string", "value": "main"}, "sentry.status": {"type": "string", "value": "ok"}, "sentry.status_code": {"type": "string", "value": "200"}, "sentry.trace.status": {"type": "string", "value": "ok"}, @@ -1043,6 +1050,7 @@ def test_ai_spans_example_transaction( "sentry.sdk.name": {"type": "string", "value": "raven-node"}, "sentry.sdk.version": {"type": "string", "value": "2.6.3"}, "sentry.segment.id": {"type": "string", "value": "657cf984a6a4e59b"}, + "sentry.segment.name": {"type": "string", "value": "main"}, "sentry.status": {"type": "string", "value": "ok"}, "sentry.trace.status": {"type": "string", "value": "ok"}, "sentry.transaction": {"type": "string", "value": "main"}, @@ -1143,6 +1151,7 @@ def test_ai_spans_example_transaction( "sentry.sdk.name": {"type": "string", "value": "raven-node"}, "sentry.sdk.version": {"type": "string", "value": "2.6.3"}, "sentry.segment.id": {"type": "string", "value": "657cf984a6a4e59b"}, + "sentry.segment.name": {"type": "string", "value": "main"}, "sentry.status": {"type": "string", "value": "ok"}, "sentry.status_code": {"type": "string", "value": "200"}, "sentry.trace.status": {"type": "string", "value": "ok"}, diff --git a/tests/integration/test_span_links.py b/tests/integration/test_span_links.py index 63eb39b9217..3d0851fc73b 100644 --- a/tests/integration/test_span_links.py +++ b/tests/integration/test_span_links.py @@ -99,6 +99,7 @@ def test_event_with_span_link_in_transaction(relay, mini_sentry): "start_timestamp": 1624366926.0, "timestamp": 1624366927.0, "sentry_tags": mock.ANY, + "data": {"sentry.segment.name": "/users"}, "links": [ { "trace_id": "4c79f60c11214eb38604f4ae0781bfb2", diff --git a/tests/integration/test_spans.py b/tests/integration/test_spans.py index 9a4bcb6b891..dc46b8b9541 100644 --- a/tests/integration/test_spans.py +++ b/tests/integration/test_spans.py @@ -139,6 +139,7 @@ def test_span_extraction( "sentry.sdk.name": {"type": "string", "value": "raven-node"}, "sentry.sdk.version": {"type": "string", "value": "2.6.3"}, "sentry.status": {"type": "string", "value": "ok"}, + "sentry.segment.name": {"type": "string", "value": "hi"}, "sentry.trace.status": {"type": "string", "value": "ok"}, "sentry.transaction": {"type": "string", "value": "hi"}, "sentry.transaction.op": {"type": "string", "value": "hi"},