Skip to content

Commit

Permalink
feat(spans): Extracts messaging operation name and operation type att…
Browse files Browse the repository at this point in the history
…ribute and tags span metrics (#4506)

Extracts `messaging.operation.name` and `messaging.operation.type`
attributes from messaging/queue span payloads, and also tags span
duration metrics + `messaging.message.receive.latency` metric with these
new attributes.

`messaging.operation.name` and `messaging.operation.type` are specified
as required attributes from OTEL which we will be using to update the
Queues product in Sentry.
Both attributes are expected to be low cardinality strings.

#skip-changelog
  • Loading branch information
edwardgou-sentry authored Feb 20, 2025
1 parent e62fe02 commit 54c91e1
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 7 deletions.
12 changes: 12 additions & 0 deletions relay-dynamic-config/src/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,12 @@ pub fn hardcoded_span_metrics() -> Vec<(GroupKey, Vec<MetricSpec>, Vec<TagMappin
Tag::with_key("messaging.destination.name")
.from_field("span.sentry_tags.messaging.destination.name")
.always(),
Tag::with_key("messaging.operation.name")
.from_field("span.sentry_tags.messaging.operation.name")
.always(),
Tag::with_key("messaging.operation.type")
.from_field("span.sentry_tags.messaging.operation.type")
.always(),
],
},
],
Expand All @@ -939,6 +945,12 @@ pub fn hardcoded_span_metrics() -> Vec<(GroupKey, Vec<MetricSpec>, Vec<TagMappin
Tag::with_key("messaging.destination.name")
.from_field("span.sentry_tags.messaging.destination.name")
.when(is_queue_op.clone()),
Tag::with_key("messaging.operation.name")
.from_field("span.sentry_tags.messaging.operation.name")
.when(is_queue_op.clone()),
Tag::with_key("messaging.operation.type")
.from_field("span.sentry_tags.messaging.operation.type")
.when(is_queue_op.clone()),
Tag::with_key("trace.status")
.from_field("span.sentry_tags.trace.status")
.when(is_queue_op.clone()),
Expand Down
44 changes: 41 additions & 3 deletions relay-event-normalization/src/normalize/span/tag_extraction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,16 +443,22 @@ fn extract_segment_measurements(event: &Event) -> BTreeMap<String, Measurement>
struct SegmentTags {
messaging_destination_name: Annotated<String>,
messaging_message_id: Annotated<String>,
messaging_operation_name: Annotated<String>,
messaging_operation_type: Annotated<String>,
}

impl SegmentTags {
fn copy_into(&self, tags: &mut SentryTags) {
let Self {
messaging_destination_name,
messaging_message_id,
messaging_operation_name,
messaging_operation_type,
} = self.clone();
tags.messaging_destination_name = messaging_destination_name;
tags.messaging_message_id = messaging_message_id;
tags.messaging_operation_name = messaging_operation_name;
tags.messaging_operation_type = messaging_operation_type;
}
}

Expand All @@ -466,6 +472,8 @@ fn extract_segment_tags(event: &Event) -> SegmentTags {
if let Some(data) = trace_context.data.value() {
tags.messaging_destination_name = data.messaging_destination_name.clone();
tags.messaging_message_id = data.messaging_message_id.clone();
tags.messaging_operation_name = data.messaging_operation_name.clone();
tags.messaging_operation_type = data.messaging_operation_type.clone();
}
}
}
Expand Down Expand Up @@ -677,6 +685,20 @@ pub fn extract_tags(
{
span_tags.messaging_message_id = message_id.to_owned().into();
}
if let Some(operation_name) = span
.data
.value()
.and_then(|data| data.messaging_operation_name.as_str())
{
span_tags.messaging_operation_name = operation_name.to_owned().into();
}
if let Some(operation_type) = span
.data
.value()
.and_then(|data| data.messaging_operation_type.as_str())
{
span_tags.messaging_operation_type = operation_type.to_owned().into();
}
}

if let Some(scrubbed_desc) = scrubbed_description {
Expand Down Expand Up @@ -2142,7 +2164,9 @@ LIMIT 1
"data": {
"messaging.destination.name": "default",
"messaging.message.id": "abc123",
"messaging.message.body.size": 100
"messaging.message.body.size": 100,
"messaging.operation.name": "publish",
"messaging.operation.type": "create"
}
}
"#;
Expand All @@ -2160,6 +2184,14 @@ LIMIT 1
tags.messaging_message_id.value(),
Some(&"abc123".to_string())
);
assert_eq!(
tags.messaging_operation_name.value(),
Some(&"publish".to_string())
);
assert_eq!(
tags.messaging_operation_type.value(),
Some(&"create".to_string())
);
}

#[test]
Expand All @@ -2180,7 +2212,9 @@ LIMIT 1
"messaging.message.id": "abc123",
"messaging.message.receive.latency": 456,
"messaging.message.body.size": 100,
"messaging.message.retry.count": 3
"messaging.message.retry.count": 3,
"messaging.operation.name": "publish",
"messaging.operation.type": "create"
}
}
}
Expand All @@ -2200,6 +2234,8 @@ LIMIT 1
let measurements = segment_span.value().unwrap().measurements.value().unwrap();

assert_eq!(tags.messaging_destination_name.as_str(), Some("default"));
assert_eq!(tags.messaging_operation_name.as_str(), Some("publish"));
assert_eq!(tags.messaging_operation_type.as_str(), Some("create"));

assert_eq!(tags.messaging_message_id.as_str(), Some("abc123"));

Expand Down Expand Up @@ -2245,7 +2281,9 @@ LIMIT 1
"messaging.message.id": "abc123",
"messaging.message.receive.latency": 456,
"messaging.message.body.size": 100,
"messaging.message.retry.count": 3
"messaging.message.retry.count": 3,
"messaging.operation.name": "publish",
"messaging.operation.type": "create"
}
}
},
Expand Down
18 changes: 18 additions & 0 deletions relay-event-schema/src/protocol/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ pub struct SentryTags {
pub messaging_destination_name: Annotated<String>,
#[metastructure(field = "messaging.message.id")]
pub messaging_message_id: Annotated<String>,
#[metastructure(field = "messaging.operation.name")]
pub messaging_operation_name: Annotated<String>,
#[metastructure(field = "messaging.operation.type")]
pub messaging_operation_type: Annotated<String>,
#[metastructure(field = "thread.name")]
pub thread_name: Annotated<String>,
#[metastructure(field = "thread.id")]
Expand Down Expand Up @@ -305,6 +309,8 @@ impl Getter for SentryTags {
"main_thread" => &self.main_thread,
"messaging.destination.name" => &self.messaging_destination_name,
"messaging.message.id" => &self.messaging_message_id,
"messaging.operation.name" => &self.messaging_operation_name,
"messaging.operation.type" => &self.messaging_operation_type,
"mobile" => &self.mobile,
"op" => &self.op,
"os.name" => &self.os_name,
Expand Down Expand Up @@ -624,6 +630,14 @@ pub struct SpanData {
#[metastructure(field = "messaging.message.id")]
pub messaging_message_id: Annotated<String>,

/// Messaging Operation Name
#[metastructure(field = "messaging.operation.name")]
pub messaging_operation_name: Annotated<String>,

/// Messaging Operation Type
#[metastructure(field = "messaging.operation.type")]
pub messaging_operation_type: Annotated<String>,

/// Value of the HTTP User-Agent header sent by the client.
#[metastructure(field = "user_agent.original")]
pub user_agent_original: Annotated<String>,
Expand Down Expand Up @@ -1034,6 +1048,8 @@ mod tests {
"messaging.message.receive.latency": 40,
"messaging.message.body.size": 100,
"messaging.message.id": "abc123",
"messaging.operation.name": "publish",
"messaging.operation.type": "create",
"user_agent.original": "Chrome",
"url.full": "my_url.com",
"client.address": "192.168.0.1"
Expand Down Expand Up @@ -1126,6 +1142,8 @@ mod tests {
100,
),
messaging_message_id: "abc123",
messaging_operation_name: "publish",
messaging_operation_type: "create",
user_agent_original: "Chrome",
url_full: "my_url.com",
client_address: IpAddr(
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 @@ -220,6 +220,8 @@ mod tests {
messaging_message_receive_latency: ~,
messaging_message_body_size: ~,
messaging_message_id: ~,
messaging_operation_name: ~,
messaging_operation_type: ~,
user_agent_original: ~,
url_full: ~,
client_address: ~,
Expand Down
16 changes: 12 additions & 4 deletions relay-server/src/metrics_extraction/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,9 @@ mod tests {
"messaging.message.receive.latency": 100,
"messaging.message.retry.count": 2,
"messaging.message.body.size": 1000,
"messaging.message.id": "abc123"
"messaging.message.id": "abc123",
"messaging.operation.name": "publish",
"messaging.operation.type": "create"
}
},
{
Expand All @@ -1182,7 +1184,9 @@ mod tests {
"messaging.message.receive.latency": 100,
"messaging.message.retry.count": 2,
"messaging.message.body.size": 1000,
"messaging.message.id": "abc123"
"messaging.message.id": "abc123",
"messaging.operation.name": "publish",
"messaging.operation.type": "create"
}
},
{
Expand All @@ -1198,7 +1202,9 @@ mod tests {
"messaging.message.receive.latency": 100,
"messaging.message.retry.count": 2,
"messaging.message.body.size": 1000,
"messaging.message.id": "abc123"
"messaging.message.id": "abc123",
"messaging.operation.name": "publish",
"messaging.operation.type": "create"
}
},
{
Expand All @@ -1214,7 +1220,9 @@ mod tests {
"messaging.message.receive.latency": 100,
"messaging.message.retry.count": 2,
"messaging.message.body.size": 1000,
"messaging.message.id": "abc123"
"messaging.message.id": "abc123",
"messaging.operation.name": "publish",
"messaging.operation.type": "create"
}
},
{
Expand Down
Loading

0 comments on commit 54c91e1

Please sign in to comment.