Skip to content

Commit 4f59717

Browse files
authored
fix(spans): Normalize segment span ID (#3531)
`SpanId` is represented as a string internally, so if we construct it without going through `Annotated::from_value`, lowercase span IDs and uppercase span IDs will be treated as different. This is problematic in `set_segment_attributes`, which compares the span's ID to its segment ID. We should probably represent `SpanId` as `[u8; 8]`, or at least go through `Annotated::from_value` for all Otel types, but this PR should do as a quick fix.
1 parent edbfc52 commit 4f59717

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

relay-spans/src/span.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,12 @@ fn otel_value_to_string(value: OtelValue) -> Option<String> {
6565
}
6666

6767
fn otel_value_to_span_id(value: OtelValue) -> Option<String> {
68-
match value {
69-
OtelValue::StringValue(s) => Some(s),
70-
OtelValue::BytesValue(b) => Some(hex::encode(b)),
71-
_ => None,
72-
}
68+
let decoded = match value {
69+
OtelValue::StringValue(s) => hex::decode(s).ok()?,
70+
OtelValue::BytesValue(b) => b,
71+
_ => None?,
72+
};
73+
Some(hex::encode(decoded))
7374
}
7475

7576
fn otel_value_to_metric_summary(value: AnyValue) -> Option<MetricSummary> {
@@ -191,7 +192,7 @@ pub fn otel_to_sentry_span(otel_span: OtelSpan) -> EventSpan {
191192
segment_id = otel_value_to_span_id(value);
192193
}
193194
"sentry.profile.id" => {
194-
profile_id = otel_value_to_span_id(value);
195+
profile_id = otel_value_to_string(value);
195196
}
196197
other => {
197198
if let Some(metric_name) = other.strip_prefix("sentry.metrics_summary.") {
@@ -521,7 +522,7 @@ mod tests {
521522
{
522523
"key" : "sentry.segment.id",
523524
"value": {
524-
"stringValue": "fa90fdead5f74052"
525+
"stringValue": "FA90FDEAD5F74052"
525526
}
526527
},
527528
{
@@ -691,4 +692,13 @@ mod tests {
691692
}
692693
"###);
693694
}
695+
696+
#[test]
697+
fn uppercase_span_id() {
698+
let input = OtelValue::StringValue("FA90FDEAD5F74052".to_owned());
699+
assert_eq!(
700+
otel_value_to_span_id(input).as_deref(),
701+
Some("fa90fdead5f74052")
702+
);
703+
}
694704
}

0 commit comments

Comments
 (0)