Skip to content

Commit 01da87c

Browse files
authored
fix(transaction): Propagate name to child spans (#5959)
1 parent d2455cd commit 01da87c

6 files changed

Lines changed: 38 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
- Emit more precise outcome discard reasons for the Playstation, Minidump, and Attachments endpoints. ([#5950](https://github.com/getsentry/relay/pull/5950))
1414
- Set the name based on the transaction name when converting a transaction into a segment span. ([#5961](https://github.com/getsentry/relay/pull/5961))
15+
- Set the segment name for child spans based on the transaction name. ([#5959](https://github.com/getsentry/relay/pull/5959))
1516

1617
**Internal**:
1718

relay-event-normalization/src/event.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use uuid::Uuid;
3434

3535
use crate::normalize::request;
3636
use crate::span::ai::enrich_ai_event_data;
37-
use crate::span::tag_extraction::extract_span_tags_from_event;
37+
use crate::span::tag_extraction::{extract_segment_name_from_event, extract_span_tags_from_event};
3838
use crate::utils::{self, MAX_DURATION_MOBILE_MS, get_event_user_tag};
3939
use crate::{
4040
BorrowedSpanOpDefaults, BreakdownsConfig, CombinedMeasurementsConfig, GeoIpLookup, MaxChars,
@@ -351,6 +351,7 @@ fn normalize(event: &mut Event, meta: &mut Meta, config: &NormalizationConfig) {
351351
config.max_tag_value_length,
352352
config.span_allowed_hosts,
353353
);
354+
extract_segment_name_from_event(event);
354355
}
355356

356357
if let Some(context) = event.context_mut::<TraceContext>() {

relay-event-normalization/src/normalize/span/tag_extraction.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,30 @@ impl std::fmt::Display for RenderBlockingStatus {
5959
}
6060
}
6161

62+
/// Extracts the `transaction` field and writes it into child spans
63+
/// as `data.segment_name`.
64+
pub(crate) fn extract_segment_name_from_event(event: &mut Event) {
65+
let Some(transaction) = event.transaction.value() else {
66+
return;
67+
};
68+
69+
let Some(spans) = event.spans.value_mut() else {
70+
return;
71+
};
72+
73+
for span in spans {
74+
let Some(span) = span.value_mut() else {
75+
continue;
76+
};
77+
78+
let data = span.data.get_or_insert_with(Default::default);
79+
80+
if data.segment_name.is_empty() {
81+
data.segment_name = Annotated::new(transaction.clone());
82+
}
83+
}
84+
}
85+
6286
/// Wrapper for [`extract_span_tags`].
6387
///
6488
/// Tags longer than `max_tag_value_size` bytes will be truncated.

tests/integration/test_ai.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ def test_ai_spans_example_transaction(
429429
"sentry.sdk.name": {"type": "string", "value": "raven-node"},
430430
"sentry.sdk.version": {"type": "string", "value": "2.6.3"},
431431
"sentry.segment.id": {"type": "string", "value": "657cf984a6a4e59b"},
432+
"sentry.segment.name": {"type": "string", "value": "main"},
432433
"sentry.status": {"type": "string", "value": "ok"},
433434
"sentry.trace.status": {"type": "string", "value": "ok"},
434435
"sentry.transaction": {"type": "string", "value": "main"},
@@ -543,6 +544,7 @@ def test_ai_spans_example_transaction(
543544
"sentry.sdk.name": {"type": "string", "value": "raven-node"},
544545
"sentry.sdk.version": {"type": "string", "value": "2.6.3"},
545546
"sentry.segment.id": {"type": "string", "value": "657cf984a6a4e59b"},
547+
"sentry.segment.name": {"type": "string", "value": "main"},
546548
"sentry.status": {"type": "string", "value": "ok"},
547549
"sentry.trace.status": {"type": "string", "value": "ok"},
548550
"sentry.transaction": {"type": "string", "value": "main"},
@@ -646,6 +648,7 @@ def test_ai_spans_example_transaction(
646648
"sentry.sdk.name": {"type": "string", "value": "raven-node"},
647649
"sentry.sdk.version": {"type": "string", "value": "2.6.3"},
648650
"sentry.segment.id": {"type": "string", "value": "657cf984a6a4e59b"},
651+
"sentry.segment.name": {"type": "string", "value": "main"},
649652
"sentry.status": {"type": "string", "value": "ok"},
650653
"sentry.status_code": {"type": "string", "value": "200"},
651654
"sentry.trace.status": {"type": "string", "value": "ok"},
@@ -729,6 +732,7 @@ def test_ai_spans_example_transaction(
729732
"sentry.sdk.name": {"type": "string", "value": "raven-node"},
730733
"sentry.sdk.version": {"type": "string", "value": "2.6.3"},
731734
"sentry.segment.id": {"type": "string", "value": "657cf984a6a4e59b"},
735+
"sentry.segment.name": {"type": "string", "value": "main"},
732736
"sentry.status": {"type": "string", "value": "ok"},
733737
"sentry.trace.status": {"type": "string", "value": "ok"},
734738
"sentry.transaction": {"type": "string", "value": "main"},
@@ -795,6 +799,7 @@ def test_ai_spans_example_transaction(
795799
"sentry.sdk.name": {"type": "string", "value": "raven-node"},
796800
"sentry.sdk.version": {"type": "string", "value": "2.6.3"},
797801
"sentry.segment.id": {"type": "string", "value": "657cf984a6a4e59b"},
802+
"sentry.segment.name": {"type": "string", "value": "main"},
798803
"sentry.status": {"type": "string", "value": "ok"},
799804
"sentry.status_code": {"type": "string", "value": "200"},
800805
"sentry.trace.status": {"type": "string", "value": "ok"},
@@ -871,6 +876,7 @@ def test_ai_spans_example_transaction(
871876
"sentry.sdk.name": {"type": "string", "value": "raven-node"},
872877
"sentry.sdk.version": {"type": "string", "value": "2.6.3"},
873878
"sentry.segment.id": {"type": "string", "value": "657cf984a6a4e59b"},
879+
"sentry.segment.name": {"type": "string", "value": "main"},
874880
"sentry.status": {"type": "string", "value": "ok"},
875881
"sentry.trace.status": {"type": "string", "value": "ok"},
876882
"sentry.transaction": {"type": "string", "value": "main"},
@@ -937,6 +943,7 @@ def test_ai_spans_example_transaction(
937943
"sentry.sdk.name": {"type": "string", "value": "raven-node"},
938944
"sentry.sdk.version": {"type": "string", "value": "2.6.3"},
939945
"sentry.segment.id": {"type": "string", "value": "657cf984a6a4e59b"},
946+
"sentry.segment.name": {"type": "string", "value": "main"},
940947
"sentry.status": {"type": "string", "value": "ok"},
941948
"sentry.status_code": {"type": "string", "value": "200"},
942949
"sentry.trace.status": {"type": "string", "value": "ok"},
@@ -1043,6 +1050,7 @@ def test_ai_spans_example_transaction(
10431050
"sentry.sdk.name": {"type": "string", "value": "raven-node"},
10441051
"sentry.sdk.version": {"type": "string", "value": "2.6.3"},
10451052
"sentry.segment.id": {"type": "string", "value": "657cf984a6a4e59b"},
1053+
"sentry.segment.name": {"type": "string", "value": "main"},
10461054
"sentry.status": {"type": "string", "value": "ok"},
10471055
"sentry.trace.status": {"type": "string", "value": "ok"},
10481056
"sentry.transaction": {"type": "string", "value": "main"},
@@ -1143,6 +1151,7 @@ def test_ai_spans_example_transaction(
11431151
"sentry.sdk.name": {"type": "string", "value": "raven-node"},
11441152
"sentry.sdk.version": {"type": "string", "value": "2.6.3"},
11451153
"sentry.segment.id": {"type": "string", "value": "657cf984a6a4e59b"},
1154+
"sentry.segment.name": {"type": "string", "value": "main"},
11461155
"sentry.status": {"type": "string", "value": "ok"},
11471156
"sentry.status_code": {"type": "string", "value": "200"},
11481157
"sentry.trace.status": {"type": "string", "value": "ok"},

tests/integration/test_span_links.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def test_event_with_span_link_in_transaction(relay, mini_sentry):
9999
"start_timestamp": 1624366926.0,
100100
"timestamp": 1624366927.0,
101101
"sentry_tags": mock.ANY,
102+
"data": {"sentry.segment.name": "/users"},
102103
"links": [
103104
{
104105
"trace_id": "4c79f60c11214eb38604f4ae0781bfb2",

tests/integration/test_spans.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ def test_span_extraction(
138138
"sentry.sdk.name": {"type": "string", "value": "raven-node"},
139139
"sentry.sdk.version": {"type": "string", "value": "2.6.3"},
140140
"sentry.status": {"type": "string", "value": "ok"},
141+
"sentry.segment.name": {"type": "string", "value": "hi"},
141142
"sentry.trace.status": {"type": "string", "value": "ok"},
142143
"sentry.transaction": {"type": "string", "value": "hi"},
143144
"sentry.transaction.op": {"type": "string", "value": "hi"},

0 commit comments

Comments
 (0)