Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 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
15 changes: 6 additions & 9 deletions relay-event-normalization/src/normalize/span/tag_extraction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,10 @@ pub fn extract_tags(
}
if let Some(measurements) = span.measurements.value() {
if span_op.starts_with("ui.interaction.") && measurements.contains_key("inp") {
if let Some(transaction) =
span.data.value().and_then(|data| data.transaction.as_str())
if let Some(transaction) = span
.data
.value()
.and_then(|data| data.segment_name.as_str())
{
span_tags.insert(SpanTagKey::Transaction, transaction.into());
}
Expand Down Expand Up @@ -572,13 +574,8 @@ pub fn extract_tags(
}
}

if let Some(browser_name) = span
.data
.value()
.and_then(|data| data.browser_name.value())
.and_then(|browser_name| browser_name.as_str())
{
span_tags.insert(SpanTagKey::BrowserName, browser_name.into());
if let Some(browser_name) = span.data.value().and_then(|data| data.browser_name.value()) {
span_tags.insert(SpanTagKey::BrowserName, browser_name.clone());
}

span_tags
Expand Down
16 changes: 11 additions & 5 deletions relay-event-schema/src/protocol/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ pub struct SpanData {

/// The client's browser name.
#[metastructure(field = "browser.name")]
pub browser_name: Annotated<Value>,
pub browser_name: Annotated<String>,

/// The source code file name that identifies the code unit as uniquely as possible.
#[metastructure(field = "code.filepath", pii = "maybe")]
Expand Down Expand Up @@ -274,7 +274,8 @@ pub struct SpanData {
/// Origin Transaction name of the span.
///
/// For INP spans, this is the route name where the interaction occurred.
pub transaction: Annotated<String>,
#[metastructure(field = "segment.name", legacy_alias = "transaction")]
pub segment_name: Annotated<String>,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to future key. transaction becomes a legacy alias.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we update the docs too?


/// Name of the UI component (e.g. React).
#[metastructure(field = "ui.component_name")]
Expand All @@ -292,6 +293,10 @@ pub struct SpanData {
#[metastructure(field = "replay_id")]
pub replay_id: Annotated<Value>,

#[metastructure(field = "sdk.name")]
/// The sentry SDK (see [`crate::protocol::ClientSdkInfo`]).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[metastructure(field = "sdk.name")]
/// The sentry SDK (see [`crate::protocol::ClientSdkInfo`]).
/// The sentry SDK (see [`crate::protocol::ClientSdkInfo`]).
#[metastructure(field = "sdk.name")]

pub sdk_name: Annotated<String>,

/// Other fields in `span.data`.
#[metastructure(additional_properties, pii = "true", retain = "true")]
other: Object<Value>,
Expand All @@ -301,7 +306,7 @@ impl Getter for SpanData {
fn get_value(&self, path: &str) -> Option<Val<'_>> {
Some(match path {
"app_start_type" => self.app_start_type.value()?.into(),
"browser\\.name" => self.browser_name.value()?.into(),
"browser\\.name" => self.browser_name.as_str()?.into(),
"code\\.filepath" => self.code_filepath.value()?.into(),
"code\\.function" => self.code_function.value()?.into(),
"code\\.lineno" => self.code_lineno.value()?.into(),
Expand All @@ -327,7 +332,7 @@ impl Getter for SpanData {
"thread\\.name" => self.thread_name.value()?.into(),
"ui\\.component_name" => self.ui_component_name.value()?.into(),
"url\\.scheme" => self.url_scheme.value()?.into(),
"transaction" => self.transaction.as_str()?.into(),
"transaction" => self.segment_name.as_str()?.into(),
_ => {
let escaped = path.replace("\\.", "\0");
let mut path = escaped.split('.').map(|s| s.replace('\0', "."));
Expand Down Expand Up @@ -529,11 +534,12 @@ mod tests {
ai_total_tokens_used: ~,
ai_responses: ~,
thread_name: ~,
transaction: ~,
segment_name: ~,
ui_component_name: ~,
url_scheme: ~,
user: ~,
replay_id: ~,
sdk_name: ~,
other: {
"bar": String(
"3",
Expand Down
53 changes: 43 additions & 10 deletions relay-event-schema/src/protocol/span/convert.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! This module defines bidirectional field mappings between spans and transactions.
use crate::protocol::{Contexts, Event, ProfileContext, Span, TraceContext};
use crate::protocol::{BrowserContext, Contexts, Event, ProfileContext, Span, TraceContext};

use relay_base_schema::events::EventType;
use relay_protocol::Annotated;
Expand Down Expand Up @@ -40,15 +40,18 @@ macro_rules! context_write_path (
);

macro_rules! event_write_path(
($event:expr, contexts browser $context_field:ident) => {
context_write_path!($event, BrowserContext, $context_field)
};
($event:expr, contexts trace $context_field:ident) => {
context_write_path!($event, TraceContext, $context_field)
};
($event:expr, contexts profile $context_field:ident) => {
context_write_path!($event, ProfileContext, $context_field)
};
($event:expr, $path_root:ident $(. $path_segment:ident)*) => {
($event:expr, $path_root:ident $($path_segment:ident)*) => {
{
write_path!($event, $path_root $(. $path_segment:ident)*)
write_path!($event, $path_root $($path_segment)*)
}
};
);
Expand All @@ -63,17 +66,20 @@ macro_rules! context_value (
);

macro_rules! event_value(
($event:expr, contexts browser $context_field:ident) => {
context_value!($event, BrowserContext, $context_field)
};
($event:expr, contexts trace $context_field:ident) => {
context_value!($event, TraceContext, $context_field)
};
($event:expr, contexts profile $context_field:ident) => {
context_value!($event, ProfileContext, $context_field)
};
($event:expr, $path_root:ident $(. $path_segment:ident)*) => {
($event:expr, $path_root:ident $($path_segment:ident)*) => {
{
let value = ($event).$path_root.value();
$(
let value = value.and_then(|value|&value.$path_segment.value());
let value = value.and_then(|value|value.$path_segment.value());
Comment on lines +69 to +82
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turned out I had some unused code branches here that needed to be fixed for deep access.

)*
value
}
Expand Down Expand Up @@ -137,6 +143,7 @@ macro_rules! map_fields {
map_fields!(
span._metrics_summary <=> event._metrics_summary,
span.description <=> event.transaction,
span.data.segment_name <=> event.transaction,
span.measurements <=> event.measurements,
span.platform <=> event.platform,
span.received <=> event.received,
Expand All @@ -153,7 +160,9 @@ map_fields!(
span.trace_id <=> event.contexts.trace.trace_id,
span.profile_id <=> event.contexts.profile.profile_id,
span.data.release <=> event.release,
span.data.environment <=> event.environment
span.data.environment <=> event.environment,
span.data.browser_name <=> event.contexts.browser.name,
span.data.sdk_name <=> event.client_sdk.name
;
span.is_segment <= true,
span.was_transaction <= true
Expand All @@ -165,16 +174,22 @@ map_fields!(
mod tests {
use relay_protocol::Annotated;

use crate::protocol::SpanData;

use super::*;

#[test]
fn roundtrip() {
let event = Annotated::<Event>::from_json(
r#"{
"type": "transaction",
"platform": "php",
"sdk": {"name": "sentry.php"},
"release": "[email protected]",
"environment": "prod",
"transaction": "my 1st transaction",
"contexts": {
"browser": {"name": "Chrome"},
"profile": {"profile_id": "a0aaaaaaaaaaaaaaaaaaaaaaaaaaaaab"},
"trace": {
"trace_id": "4C79F60C11214EB38604F4AE0781BFB2",
Expand Down Expand Up @@ -217,7 +232,7 @@ mod tests {
timestamp: ~,
start_timestamp: ~,
exclusive_time: 123.4,
description: ~,
description: "my 1st transaction",
op: "myop",
span_id: SpanId(
"fa90fdead5f74052",
Expand All @@ -240,7 +255,7 @@ mod tests {
),
data: SpanData {
app_start_type: ~,
browser_name: ~,
browser_name: "Chrome",
code_filepath: ~,
code_lineno: ~,
code_function: ~,
Expand All @@ -266,11 +281,12 @@ mod tests {
ai_total_tokens_used: ~,
ai_responses: ~,
thread_name: ~,
transaction: ~,
segment_name: "my 1st transaction",
ui_component_name: ~,
url_scheme: ~,
user: ~,
replay_id: ~,
sdk_name: "sentry.php",
other: {},
},
sentry_tags: ~,
Expand Down Expand Up @@ -300,7 +316,7 @@ mod tests {
],
},
),
platform: ~,
platform: "php",
was_transaction: true,
other: {},
}
Expand All @@ -310,6 +326,23 @@ mod tests {
assert_eq!(event, roundtripped);
}

#[test]
fn segment_name_takes_precedence() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does it take precedence over?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the test name.

let span = Span {
is_segment: true.into(),
description: "This is the description".to_owned().into(),
data: SpanData {
segment_name: "This is the segment name".to_owned().into(),
..Default::default()
}
.into(),
..Default::default()
};
let event = Event::try_from(&span).unwrap();

assert_eq!(event.transaction.as_str(), Some("This is the segment name"));
}

#[test]
fn no_empty_profile_context() {
let span = Span {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,12 @@ expression: "(&event.value().unwrap().spans, metrics)"
ai_total_tokens_used: ~,
ai_responses: ~,
thread_name: ~,
transaction: ~,
segment_name: ~,
ui_component_name: ~,
url_scheme: ~,
user: ~,
replay_id: ~,
sdk_name: ~,
other: {},
},
sentry_tags: {
Expand Down Expand Up @@ -421,11 +422,12 @@ expression: "(&event.value().unwrap().spans, metrics)"
ai_total_tokens_used: ~,
ai_responses: ~,
thread_name: ~,
transaction: ~,
segment_name: ~,
ui_component_name: ~,
url_scheme: ~,
user: ~,
replay_id: ~,
sdk_name: ~,
other: {},
},
sentry_tags: {
Expand Down
4 changes: 2 additions & 2 deletions relay-server/src/services/processor/span/processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ fn normalize(
.and_then(|v| v.name.value())
{
let data = span.data.value_mut().get_or_insert_with(SpanData::default);
data.browser_name = Annotated::new(browser_name.to_owned().into());
data.browser_name = Annotated::new(browser_name.to_owned());
}

if let Annotated(Some(ref mut measurement_values), ref mut meta) = span.measurements {
Expand All @@ -504,7 +504,7 @@ fn normalize(
.data
.value_mut()
.as_mut()
.map(|data| &mut data.transaction)
.map(|data| &mut data.segment_name)
{
normalize_transaction_name(transaction, &project_config.tx_name_rules);
}
Expand Down