Skip to content

Commit e59b49b

Browse files
authored
fix(spans): Propagate profiler_id to all spans (#3784)
1 parent 8b5557a commit e59b49b

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
- Aggregate metrics before rate limiting. ([#3746](https://github.com/getsentry/relay/pull/3746))
1414
- Make sure outcomes for dropped profiles are consistent between indexed and non-indexed categories. ([#3767](https://github.com/getsentry/relay/pull/3767))
1515
- Add web vitals support for mobile browsers. ([#3762](https://github.com/getsentry/relay/pull/3762))
16-
- Accept profiler_id in the profile context. ([#3714](https://github.com/getsentry/relay/pull/3714))
16+
- Ingest profiler_id in the profile context and in spans. ([#3714](https://github.com/getsentry/relay/pull/3714), [#3784](https://github.com/getsentry/relay/pull/3784))
1717
- Support extrapolation of metrics extracted from sampled data, as long as the sample rate is set in the DynamicSamplingContext. ([#3753](https://github.com/getsentry/relay/pull/3753))
1818

1919
## 24.6.0

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

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ use once_cell::sync::Lazy;
1010
use regex::Regex;
1111
use relay_base_schema::metrics::{DurationUnit, InformationUnit, MetricUnit};
1212
use relay_event_schema::protocol::{
13-
AppContext, BrowserContext, Event, Measurement, OsContext, Span, Timestamp, TraceContext,
13+
AppContext, BrowserContext, Event, Measurement, OsContext, ProfileContext, Span, Timestamp,
14+
TraceContext,
1415
};
1516
use relay_protocol::{Annotated, Value};
1617
use sqlparser::ast::Visit;
@@ -81,6 +82,7 @@ pub enum SpanTagKey {
8182
TraceStatus,
8283
MessagingDestinationName,
8384
MessagingMessageId,
85+
ProfilerId,
8486
}
8587

8688
impl SpanTagKey {
@@ -132,6 +134,8 @@ impl SpanTagKey {
132134
SpanTagKey::TraceStatus => "trace.status",
133135
SpanTagKey::MessagingDestinationName => "messaging.destination.name",
134136
SpanTagKey::MessagingMessageId => "messaging.message.id",
137+
138+
SpanTagKey::ProfilerId => "profiler_id",
135139
}
136140
}
137141
}
@@ -325,6 +329,13 @@ fn extract_shared_tags(event: &Event) -> BTreeMap<SpanTagKey, String> {
325329
tags.insert(SpanTagKey::BrowserName, browser_name.into());
326330
}
327331

332+
if let Some(profiler_id) = event
333+
.context::<ProfileContext>()
334+
.and_then(|profile_context| profile_context.profiler_id.value())
335+
{
336+
tags.insert(SpanTagKey::ProfilerId, profiler_id.to_string());
337+
}
338+
328339
tags.insert(SpanTagKey::SdkName, event.sdk_name().into());
329340
tags.insert(SpanTagKey::SdkVersion, event.sdk_version().into());
330341
tags.insert(
@@ -2377,6 +2388,51 @@ LIMIT 1
23772388
assert_eq!(tags.get(&SpanTagKey::Domain), None);
23782389
}
23792390

2391+
#[test]
2392+
fn extract_profiler_id_into_sentry_tags() {
2393+
let json = r#"
2394+
{
2395+
"type": "transaction",
2396+
"platform": "javascript",
2397+
"start_timestamp": "2021-04-26T07:59:01+0100",
2398+
"timestamp": "2021-04-26T08:00:00+0100",
2399+
"transaction": "foo",
2400+
"contexts": {
2401+
"profile": {
2402+
"profiler_id": "ff62a8b040f340bda5d830223def1d81"
2403+
}
2404+
},
2405+
"spans": [
2406+
{
2407+
"op": "before_first_display",
2408+
"span_id": "bd429c44b67a3eb1",
2409+
"start_timestamp": 1597976300.0000000,
2410+
"timestamp": 1597976302.0000000,
2411+
"trace_id": "ff62a8b040f340bda5d830223def1d81"
2412+
}
2413+
]
2414+
}
2415+
"#;
2416+
2417+
let mut event = Annotated::<Event>::from_json(json).unwrap();
2418+
2419+
normalize_event(
2420+
&mut event,
2421+
&NormalizationConfig {
2422+
enrich_spans: true,
2423+
..Default::default()
2424+
},
2425+
);
2426+
2427+
let spans = get_value!(event.spans!);
2428+
let span = &spans[0];
2429+
2430+
assert_eq!(
2431+
get_value!(span.sentry_tags["profiler_id"]!),
2432+
"ff62a8b040f340bda5d830223def1d81",
2433+
);
2434+
}
2435+
23802436
#[test]
23812437
fn extract_user_into_sentry_tags() {
23822438
let json = r#"

0 commit comments

Comments
 (0)