Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

**Internal**:

- Add the transaction replay id as an attribute to all contained spans. ([#6017](https://github.com/getsentry/relay/pull/6017))
- Always allow `Upload-Defer-Length: 1` on the `/upload` endpoint. ([#5977](https://github.com/getsentry/relay/pull/5977))

## 26.5.0
Expand Down
7 changes: 3 additions & 4 deletions relay-event-normalization/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ fn normalize(event: &mut Event, meta: &mut Meta, config: &NormalizationConfig) {
normalize_breakdowns(event, config.breakdowns_config); // Breakdowns are part of the metric extraction too
normalize_default_attributes(event, meta, config);
normalize_trace_context_tags(event);
normalize_replay_context(event, config.replay_id);

let _ = processor::apply(&mut event.request, |request, _| {
request::normalize_request(request);
Expand Down Expand Up @@ -367,13 +368,11 @@ fn normalize(event: &mut Event, meta: &mut Meta, config: &NormalizationConfig) {
if let Some(context) = event.context_mut::<TraceContext>() {
context.client_sample_rate = Annotated::from(config.client_sample_rate);
}
normalize_replay_context(event, config.replay_id);
}

fn normalize_replay_context(event: &mut Event, replay_id: Option<Uuid>) {
if let Some(contexts) = event.contexts.value_mut()
&& let Some(replay_id) = replay_id
{
if let Some(replay_id) = replay_id {
Comment thread
Dav1dde marked this conversation as resolved.
let contexts = event.contexts.get_or_insert_with(Contexts::default);
contexts.add(ReplayContext {
replay_id: Annotated::new(EventId(replay_id)),
other: Object::default(),
Expand Down
60 changes: 59 additions & 1 deletion relay-event-normalization/src/normalize/span/tag_extraction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use regex::Regex;
use relay_base_schema::metrics::{DurationUnit, InformationUnit, MetricUnit};
use relay_event_schema::protocol::{
AppContext, BrowserContext, DeviceContext, Event, GpuContext, Measurement, MonitorContext,
OsContext, ProfileContext, RuntimeContext, SentryTags, Span, Timestamp, TraceContext,
OsContext, ProfileContext, ReplayContext, RuntimeContext, SentryTags, Span, Timestamp,
TraceContext,
};
use relay_protocol::{Annotated, Empty, FiniteF64, Value};
use relay_spans::name_for_span;
Expand Down Expand Up @@ -182,6 +183,7 @@ struct SharedTags {
os_name: Annotated<String>,
platform: Annotated<String>,
profiler_id: Annotated<String>,
replay_id: Annotated<String>,
release: Annotated<String>,
sdk_name: Annotated<String>,
sdk_version: Annotated<String>,
Expand Down Expand Up @@ -213,6 +215,7 @@ impl SharedTags {
os_name,
platform,
profiler_id,
replay_id,
release,
sdk_name,
sdk_version,
Expand Down Expand Up @@ -254,6 +257,9 @@ impl SharedTags {
if tags.profiler_id.value().is_none() {
tags.profiler_id = profiler_id.clone();
};
if tags.replay_id.value().is_none() {
tags.replay_id = replay_id.clone();
};
if tags.release.value().is_none() {
tags.release = release.clone();
};
Expand Down Expand Up @@ -431,6 +437,13 @@ fn extract_shared_tags(event: &Event) -> SharedTags {
tags.profiler_id = profiler_id.to_string().into();
}

if let Some(replay_id) = event
.context::<ReplayContext>()
.and_then(|replay_context| replay_context.replay_id.value())
{
tags.replay_id = replay_id.to_string().into();
}

tags.sdk_name = event.sdk_name().to_owned().into();
tags.sdk_version = event.sdk_version().to_owned().into();
tags.platform = event.platform.as_str().unwrap_or("other").to_owned().into();
Expand Down Expand Up @@ -3104,6 +3117,51 @@ LIMIT 1
);
}

#[test]
fn extract_replay_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": {
"replay": {
"replay_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.replay_id!),
"ff62a8b040f340bda5d830223def1d81",
);
}

#[test]
fn extract_user_into_sentry_tags() {
let json = r#"
Expand Down
9 changes: 9 additions & 0 deletions tests/integration/test_spans.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def test_span_extraction(
"attributes": {"txn_key": 123},
},
]
event["contexts"]["replay"] = {"replay_id": "4c79f60c11214eb38604f4ae0781bfb2"}
end = datetime.now(timezone.utc) - timedelta(seconds=1)
duration = timedelta(milliseconds=500)
start = end - duration
Expand Down Expand Up @@ -135,6 +136,10 @@ def test_span_extraction(
"sentry.op": {"type": "string", "value": "http"},
"sentry.origin": {"type": "string", "value": "manual"},
"sentry.platform": {"type": "string", "value": "other"},
"sentry.replay_id": {
"type": "string",
"value": "4c79f60c11214eb38604f4ae0781bfb2",
},
"sentry.sdk.name": {"type": "string", "value": "raven-node"},
"sentry.sdk.version": {"type": "string", "value": "2.6.3"},
"sentry.status": {"type": "string", "value": "ok"},
Expand Down Expand Up @@ -216,6 +221,10 @@ def test_span_extraction(
"sentry.op": {"type": "string", "value": "hi"},
"sentry.origin": {"type": "string", "value": "manual"},
"sentry.platform": {"type": "string", "value": "other"},
"sentry.replay_id": {
"type": "string",
"value": "4c79f60c11214eb38604f4ae0781bfb2",
},
"sentry.sdk.name": {"type": "string", "value": "raven-node"},
"sentry.sdk.version": {"type": "string", "value": "2.6.3"},
"sentry.segment.id": {"type": "string", "value": "968cff94913ebb07"},
Expand Down
Loading