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): Normalize INP spans further #4298

Merged
merged 9 commits into from
Nov 27, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

- Remove metrics summaries. ([#4278](https://github.com/getsentry/relay/pull/4278), [#4279](https://github.com/getsentry/relay/pull/4279))
- Use async `redis` for `projectconfig`. ([#4284](https://github.com/getsentry/relay/pull/4284))
- Promote some `span.data` fields to the top level. ([#4298](https://github.com/getsentry/relay/pull/4298))

## 24.11.0

Expand Down
10 changes: 10 additions & 0 deletions relay-event-schema/src/protocol/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,14 @@ pub struct SpanData {
#[metastructure(field = "user.roles")]
pub user_roles: Annotated<Array<String>>,

/// Exclusive Time
#[metastructure(field = "sentry.exclusive_time")]
pub exclusive_time: Annotated<Value>,

/// Profile ID
#[metastructure(field = "profile_id")]
pub profile_id: Annotated<Value>,

/// Replay ID
#[metastructure(field = "sentry.replay.id", legacy_alias = "replay_id")]
pub replay_id: Annotated<Value>,
Expand Down Expand Up @@ -868,6 +876,8 @@ mod tests {
user_id: ~,
user_name: ~,
user_roles: ~,
exclusive_time: ~,
profile_id: ~,
replay_id: ~,
sdk_name: ~,
sdk_version: ~,
Expand Down
2 changes: 2 additions & 0 deletions relay-event-schema/src/protocol/span/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ mod tests {
user_id: ~,
user_name: ~,
user_roles: ~,
exclusive_time: ~,
profile_id: ~,
replay_id: ~,
sdk_name: "sentry.php",
sdk_version: "1.2.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ expression: "(&event.value().unwrap().spans, metrics.project_metrics)"
user_id: ~,
user_name: ~,
user_roles: ~,
exclusive_time: ~,
profile_id: ~,
replay_id: ~,
sdk_name: ~,
sdk_version: ~,
Expand Down Expand Up @@ -478,6 +480,8 @@ expression: "(&event.value().unwrap().spans, metrics.project_metrics)"
user_id: ~,
user_name: ~,
user_roles: ~,
exclusive_time: ~,
profile_id: ~,
replay_id: ~,
sdk_name: ~,
sdk_version: ~,
Expand Down Expand Up @@ -599,6 +603,8 @@ expression: "(&event.value().unwrap().spans, metrics.project_metrics)"
user_id: ~,
user_name: ~,
user_roles: ~,
exclusive_time: ~,
profile_id: ~,
replay_id: ~,
sdk_name: ~,
sdk_version: ~,
Expand Down Expand Up @@ -771,6 +777,8 @@ expression: "(&event.value().unwrap().spans, metrics.project_metrics)"
user_id: ~,
user_name: ~,
user_roles: ~,
exclusive_time: ~,
profile_id: ~,
replay_id: ~,
sdk_name: ~,
sdk_version: ~,
Expand Down Expand Up @@ -892,6 +900,8 @@ expression: "(&event.value().unwrap().spans, metrics.project_metrics)"
user_id: ~,
user_name: ~,
user_roles: ~,
exclusive_time: ~,
profile_id: ~,
replay_id: ~,
sdk_name: ~,
sdk_version: ~,
Expand Down
126 changes: 123 additions & 3 deletions relay-server/src/services/processor/span/processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ use relay_event_normalization::{
};
use relay_event_schema::processor::{process_value, ProcessingAction, ProcessingState};
use relay_event_schema::protocol::{
BrowserContext, IpAddr, Measurement, Measurements, Span, SpanData,
BrowserContext, EventId, IpAddr, Measurement, Measurements, Span, SpanData,
};
use relay_log::protocol::{Attachment, AttachmentType};
use relay_metrics::{FractionUnit, MetricNamespace, MetricUnit, UnixTimestamp};
use relay_pii::PiiProcessor;
use relay_protocol::{Annotated, Empty};
use relay_protocol::{Annotated, Empty, Value};
use relay_quotas::DataCategory;
use relay_spans::otel_trace::Span as OtelSpan;
use thiserror::Error;
Expand Down Expand Up @@ -590,6 +590,8 @@ fn normalize(

populate_ua_fields(span, user_agent.as_deref(), client_hints.as_deref());

promote_span_data_fields(span);

if let Annotated(Some(ref mut measurement_values), ref mut meta) = span.measurements {
normalize_measurements(
measurement_values,
Expand Down Expand Up @@ -671,6 +673,31 @@ fn populate_ua_fields(
}
}

/// Promotes some fields from span.data as there are predefined places for certain fields.
fn promote_span_data_fields(span: &mut Span) {
// INP spans sets some top level span attributes inside span.data so make sure to pull
// them out to the top level before further processing.
if let Some(data) = span.data.value_mut() {
if let Some(exclusive_time) = match data.exclusive_time.value() {
Some(Value::I64(exclusive_time)) => Some(*exclusive_time as f64),
Some(Value::U64(exclusive_time)) => Some(*exclusive_time as f64),
Some(Value::F64(exclusive_time)) => Some(*exclusive_time),
_ => None,
} {
span.exclusive_time = exclusive_time.into();
data.exclusive_time.set_value(None);
}

if let Some(profile_id) = match data.profile_id.value() {
Some(Value::String(profile_id)) => profile_id.parse().map(EventId).ok(),
_ => None,
} {
span.profile_id = profile_id.into();
data.profile_id.set_value(None);
}
}
}

fn scrub(
annotated_span: &mut Annotated<Span>,
project_config: &ProjectConfig,
Expand Down Expand Up @@ -771,7 +798,7 @@ mod tests {
use once_cell::sync::Lazy;
use relay_base_schema::project::ProjectId;
use relay_event_schema::protocol::{
Context, ContextInner, SpanId, Timestamp, TraceContext, TraceId,
Context, ContextInner, EventId, SpanId, Timestamp, TraceContext, TraceId,
};
use relay_event_schema::protocol::{Contexts, Event, Span};
use relay_protocol::get_value;
Expand Down Expand Up @@ -1266,4 +1293,97 @@ mod tests {
);
assert_eq!(get_value!(span.data.user_geo_city!), "Boxford");
}

#[test]
fn exclusive_time_inside_span_data_i64() {
let mut span = Annotated::from_json(
r#"{
"start_timestamp": 0,
"timestamp": 1,
"trace_id": "922dda2462ea4ac2b6a4b339bee90863",
"span_id": "922dda2462ea4ac2",
"data": {
"sentry.exclusive_time": 123
}
}"#,
)
.unwrap();

normalize(&mut span, normalize_config()).unwrap();

let data = get_value!(span.data!);
assert_eq!(data.exclusive_time, Annotated::empty());
assert_eq!(*get_value!(span.exclusive_time!), 123.0);
}

#[test]
fn exclusive_time_inside_span_data_f64() {
let mut span = Annotated::from_json(
r#"{
"start_timestamp": 0,
"timestamp": 1,
"trace_id": "922dda2462ea4ac2b6a4b339bee90863",
"span_id": "922dda2462ea4ac2",
"data": {
"sentry.exclusive_time": 123.0
}
}"#,
)
.unwrap();

normalize(&mut span, normalize_config()).unwrap();

let data = get_value!(span.data!);
assert_eq!(data.exclusive_time, Annotated::empty());
assert_eq!(*get_value!(span.exclusive_time!), 123.0);
}

#[test]
fn normalize_inp_spans() {
let mut span = Annotated::from_json(
r#"{
"data": {
"sentry.origin": "auto.http.browser.inp",
"sentry.op": "ui.interaction.click",
"release": "frontend@0735d75a05afe8d34bb0950f17c332eb32988862",
"environment": "prod",
"profile_id": "480ffcc911174ade9106b40ffbd822f5",
"replay_id": "f39c5eb6539f4e49b9ad2b95226bc120",
"transaction": "/replays",
"user_agent.original": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
"sentry.exclusive_time": 128.0
},
"description": "div.app-3diuwe.e88zkai6 > span.app-ksj0rb.e88zkai4",
"op": "ui.interaction.click",
"parent_span_id": "88457c3c28f4c0c6",
"span_id": "be0e95480798a2a9",
"start_timestamp": 1732635523.5048,
"timestamp": 1732635523.6328,
"trace_id": "bdaf4823d1c74068af238879e31e1be9",
"origin": "auto.http.browser.inp",
"exclusive_time": 128,
"measurements": {
"inp": {
"value": 128,
"unit": "millisecond"
}
},
"segment_id": "88457c3c28f4c0c6"
}"#,
)
.unwrap();

normalize(&mut span, normalize_config()).unwrap();

let data = get_value!(span.data!);

assert_eq!(data.exclusive_time, Annotated::empty());
assert_eq!(*get_value!(span.exclusive_time!), 128.0);

assert_eq!(data.profile_id, Annotated::empty());
assert_eq!(
get_value!(span.profile_id!),
&EventId("480ffcc911174ade9106b40ffbd822f5".parse().unwrap())
);
}
}
2 changes: 2 additions & 0 deletions relay-spans/src/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,8 @@ mod tests {
user_id: ~,
user_name: ~,
user_roles: ~,
exclusive_time: ~,
profile_id: ~,
replay_id: ~,
sdk_name: "sentry.php",
sdk_version: ~,
Expand Down