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

fix(spans): Propagate profiler_id to all spans #3784

Merged
merged 4 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
- Aggregate metrics before rate limiting. ([#3746](https://github.com/getsentry/relay/pull/3746))
- Make sure outcomes for dropped profiles are consistent between indexed and non-indexed categories. ([#3767](https://github.com/getsentry/relay/pull/3767))
- Add web vitals support for mobile browsers. ([#3762](https://github.com/getsentry/relay/pull/3762))
- Accept profiler_id in the profile context. ([#3714](https://github.com/getsentry/relay/pull/3714))
- 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))
- 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))

## 24.6.0
Expand Down
58 changes: 57 additions & 1 deletion relay-event-normalization/src/normalize/span/tag_extraction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use once_cell::sync::Lazy;
use regex::Regex;
use relay_base_schema::metrics::{DurationUnit, InformationUnit, MetricUnit};
use relay_event_schema::protocol::{
AppContext, BrowserContext, Event, Measurement, OsContext, Span, Timestamp, TraceContext,
AppContext, BrowserContext, Event, Measurement, OsContext, ProfileContext, Span, Timestamp,
TraceContext,
};
use relay_protocol::{Annotated, Value};
use sqlparser::ast::Visit;
Expand Down Expand Up @@ -81,6 +82,7 @@ pub enum SpanTagKey {
TraceStatus,
MessagingDestinationName,
MessagingMessageId,
ProfilerId,
}

impl SpanTagKey {
Expand Down Expand Up @@ -132,6 +134,8 @@ impl SpanTagKey {
SpanTagKey::TraceStatus => "trace.status",
SpanTagKey::MessagingDestinationName => "messaging.destination.name",
SpanTagKey::MessagingMessageId => "messaging.message.id",

SpanTagKey::ProfilerId => "profiler_id",
}
}
}
Expand Down Expand Up @@ -325,6 +329,13 @@ fn extract_shared_tags(event: &Event) -> BTreeMap<SpanTagKey, String> {
tags.insert(SpanTagKey::BrowserName, browser_name.into());
}

if let Some(profiler_id) = event
.context::<ProfileContext>()
.and_then(|profile_context| profile_context.profiler_id.value())
{
tags.insert(SpanTagKey::ProfilerId, profiler_id.to_string());
}

tags.insert(SpanTagKey::SdkName, event.sdk_name().into());
tags.insert(SpanTagKey::SdkVersion, event.sdk_version().into());
tags.insert(
Expand Down Expand Up @@ -2377,6 +2388,51 @@ LIMIT 1
assert_eq!(tags.get(&SpanTagKey::Domain), None);
}

#[test]
fn extract_profiler_id_into_sentry_tags() {
let json = r#"
{
"type": "transaction",
"platform": "javascript",
"start_timestamp": "2021-04-26T07:59:01+0100",
"timestamp": "2021-04-26T08:00:00+0100",
"transaction": "foo",
"contexts": {
"profile": {
"profiler_id": "ff62a8b040f340bda5d830223def1d81"
}
},
"spans": [
{
"op": "before_first_display",
"span_id": "bd429c44b67a3eb1",
"start_timestamp": 1597976300.0000000,
"timestamp": 1597976302.0000000,
"trace_id": "ff62a8b040f340bda5d830223def1d81"
}
]
}
"#;

let mut event = Annotated::<Event>::from_json(json).unwrap();

normalize_event(
&mut event,
&NormalizationConfig {
enrich_spans: true,
..Default::default()
},
);

let spans = get_value!(event.spans!);
let span = &spans[0];

assert_eq!(
get_value!(span.sentry_tags["profiler_id"]!),
"ff62a8b040f340bda5d830223def1d81",
);
}

#[test]
fn extract_user_into_sentry_tags() {
let json = r#"
Expand Down
Loading