Skip to content

Commit 1aac39b

Browse files
authored
feat(otlp): Derive a sentry.op attribute for V2 spans (#4796)
In support of [Span Field Transition](https://linear.app/getsentry/document/span-field-transition-e0e4b8e59f11), this PR adds a change to how `SpanV2` spans are converted to `Span`. Before, we used to put the `name` field of `SpanV2` into the `op` field of the `Span`. This is _roughly_ correct, but not quite correct. Instead, it does this: 1. If the payload includes a `sentry.op` attribute (as it might, in new SDKs that send `SpanV2` spans that aren't covered under OTel definitions, like `ui.click`), we respect `sentry.op` 2. If the payload did not include a `sentry.op`, derives a simple `sentry.op` from the available attributes 3. If it's not possible to derive `sentry.op`, sets it to `"default"` The logic is copied from the [JavaScript SDK](https://github.com/getsentry/sentry-javascript/blob/master/packages/opentelemetry/src/utils/parseSpanDescription.ts#L41-L94) which already has this logic. N.B. Once this logic is active, SDKs technically don't have to infer the `op`, since Relay will do it. This has two important upstream/downstream implications (but they are negotiable) 1. `sentry.op` will never be blank, and it won't fall back to `name`. It'll be `"default"`. This should be very rare, but that's the fallback for missing transaction ops, so I adopted it here. Another alternative is to fall back to `name`, but I'm trying to avoid mixing those concepts as much as possible 2. We will rely on frontend SDKs to continue sending `sentry.op` for cases where we can't derive it for now The Rust code here is no good, style and logic suggestions would be very welcome!
1 parent e9749eb commit 1aac39b

File tree

4 files changed

+499
-110
lines changed

4 files changed

+499
-110
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
- Set default sdk name for playstation crashes. ([#4802](https://github.com/getsentry/relay/pull/4802))
2626
- Skip large attachments on playstation crashes. ([#4793](https://github.com/getsentry/relay/pull/4793))
2727
- Use the received timestamp as observed nanos for logs. ([#4810](https://github.com/getsentry/relay/pull/4810))
28+
- Derive a `sentry.op` attribute for V2 spans ([#4796](https://github.com/getsentry/relay/pull/4796))
2829

2930
## 25.5.1
3031

relay-spans/src/otel_to_sentry.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use relay_protocol::Error;
99
/// This uses attributes in the OTEL span to populate various fields in the Sentry span.
1010
/// * The Sentry span's `name` field may be set based on `db` or `http` attributes
1111
/// if the OTEL span's `name` is empty.
12+
/// * The Sentry span's `op` field will be inferred based on the OTEL span's `sentry.op` attribute,
13+
/// or other available attributes if `sentry.op` is not provided.
1214
/// * The Sentry span's `description` field may be set based on `db` or `http` attributes
1315
/// if the OTEL span's `sentry.description` attribute is empty.
1416
/// * The Sentry span's `status` field is set based on the OTEL span's `status` field and
@@ -113,7 +115,7 @@ mod tests {
113115
"timestamp": 1697620454.980079,
114116
"start_timestamp": 1697620454.98,
115117
"exclusive_time": 1000.0,
116-
"op": "middleware - fastify -> @fastify/multipart",
118+
"op": "http",
117119
"span_id": "e342abb1214ca181",
118120
"parent_span_id": "0c7a7dea069bf5a6",
119121
"trace_id": "89143b0763095bd9c9955e8175d1fb23",
@@ -163,7 +165,7 @@ mod tests {
163165
"timestamp": 1697620454.980079,
164166
"start_timestamp": 1697620454.98,
165167
"exclusive_time": 3200.0,
166-
"op": "middleware - fastify -> @fastify/multipart",
168+
"op": "default",
167169
"span_id": "e342abb1214ca181",
168170
"parent_span_id": "0c7a7dea069bf5a6",
169171
"trace_id": "89143b0763095bd9c9955e8175d1fb23",
@@ -196,7 +198,7 @@ mod tests {
196198
"timestamp": 1697620454.980079,
197199
"start_timestamp": 1697620454.98,
198200
"exclusive_time": 0.0788,
199-
"op": "middleware - fastify -> @fastify/multipart",
201+
"op": "default",
200202
"span_id": "e342abb1214ca181",
201203
"parent_span_id": "0c7a7dea069bf5a6",
202204
"trace_id": "89143b0763095bd9c9955e8175d1fb23",
@@ -249,7 +251,7 @@ mod tests {
249251
"timestamp": 1697620454.980079,
250252
"start_timestamp": 1697620454.98,
251253
"exclusive_time": 0.0788,
252-
"op": "database query",
254+
"op": "default",
253255
"span_id": "e342abb1214ca181",
254256
"parent_span_id": "0c7a7dea069bf5a6",
255257
"trace_id": "89143b0763095bd9c9955e8175d1fb23",
@@ -312,7 +314,7 @@ mod tests {
312314
"timestamp": 1697620454.980079,
313315
"start_timestamp": 1697620454.98,
314316
"exclusive_time": 0.0788,
315-
"op": "database query",
317+
"op": "default",
316318
"span_id": "e342abb1214ca181",
317319
"parent_span_id": "0c7a7dea069bf5a6",
318320
"trace_id": "89143b0763095bd9c9955e8175d1fb23",
@@ -363,7 +365,7 @@ mod tests {
363365
"timestamp": 1697620454.980079,
364366
"start_timestamp": 1697620454.98,
365367
"exclusive_time": 0.0788,
366-
"op": "http client request",
368+
"op": "http.client",
367369
"span_id": "e342abb1214ca181",
368370
"parent_span_id": "0c7a7dea069bf5a6",
369371
"trace_id": "89143b0763095bd9c9955e8175d1fb23",
@@ -518,7 +520,7 @@ mod tests {
518520
"timestamp": 123.5,
519521
"start_timestamp": 123.0,
520522
"exclusive_time": 500.0,
521-
"op": "myname",
523+
"op": "myop",
522524
"span_id": "fa90fdead5f74052",
523525
"parent_span_id": "fa90fdead5f74051",
524526
"trace_id": "4c79f60c11214eb38604f4ae0781bfb2",
@@ -532,8 +534,7 @@ mod tests {
532534
"sentry.release": "[email protected]",
533535
"sentry.segment.name": "my 1st transaction",
534536
"sentry.sdk.name": "sentry.php",
535-
"sentry.name": "myname",
536-
"sentry.op": "myop"
537+
"sentry.name": "myname"
537538
},
538539
"links": [],
539540
"platform": "php"
@@ -559,6 +560,7 @@ mod tests {
559560
"timestamp": 123.5,
560561
"start_timestamp": 123.0,
561562
"exclusive_time": 500.0,
563+
"op": "default",
562564
"span_id": "e342abb1214ca181",
563565
"parent_span_id": "0c7a7dea069bf5a6",
564566
"trace_id": "89143b0763095bd9c9955e8175d1fb23",
@@ -588,6 +590,7 @@ mod tests {
588590
"timestamp": 123.5,
589591
"start_timestamp": 123.0,
590592
"exclusive_time": 500.0,
593+
"op": "default",
591594
"span_id": "e342abb1214ca181",
592595
"parent_span_id": "0c7a7dea069bf5a6",
593596
"trace_id": "89143b0763095bd9c9955e8175d1fb23",
@@ -617,6 +620,7 @@ mod tests {
617620
"timestamp": 123.5,
618621
"start_timestamp": 123.0,
619622
"exclusive_time": 500.0,
623+
"op": "default",
620624
"span_id": "e342abb1214ca181",
621625
"parent_span_id": "0c7a7dea069bf5a6",
622626
"trace_id": "89143b0763095bd9c9955e8175d1fb23",
@@ -676,6 +680,7 @@ mod tests {
676680
"timestamp": 0.0,
677681
"start_timestamp": 0.0,
678682
"exclusive_time": 0.0,
683+
"op": "default",
679684
"span_id": "e342abb1214ca181",
680685
"trace_id": "3c79f60c11214eb38604f4ae0781bfb2",
681686
"status": "unknown",

0 commit comments

Comments
 (0)