Skip to content

Commit 51016ab

Browse files
authored
feat(otlp): Attach sentry.origin attribute to otlp spans (#5294)
Modelled after #5190, and for the same reason - so that we can internally tell how many spans are ingested via OTLP vs other means. (It is hidden by the many snapshot changes, but the actual change is a one-liner in `relay-spans/src/otel_to_sentry_v2.rs`.) Fixes ENG-5768.
1 parent 4493fe5 commit 51016ab

File tree

6 files changed

+86
-13
lines changed

6 files changed

+86
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
**Features**:
66

77
- Only apply non-destructive PII rules to log bodies by default. ([#5272](https://github.com/getsentry/relay/pull/5272))
8+
- Add `sentry.origin` attribute to OTLP spans. ([#5294](https://github.com/getsentry/relay/pull/5294))
89

910
**Breaking Changes**:
1011

relay-server/src/services/processor/span.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ mod tests {
246246
"instrumentation.scope_key": "scope_value",
247247
"instrumentation.version": "0.0.1",
248248
"resource.resource_key": "resource_value",
249+
"sentry.origin": "auto.otlp.spans",
249250
"span_key": "span_value"
250251
},
251252
"exclusive_time": 0.0,

relay-spans/src/otel_to_sentry.rs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ mod tests {
154154
"instrumentation.version": "123.42",
155155
"plugin.name": "fastify -> @fastify/multipart",
156156
"resource.service.name": 42,
157+
"sentry.origin": "auto.otlp.spans",
157158
"sentry.parentSampled": true,
158159
"sentry.sample_rate": 1,
159160
"sentry.status.message": "test"
@@ -199,7 +200,8 @@ mod tests {
199200
"status": "ok",
200201
"description": "middleware - fastify -> @fastify/multipart",
201202
"data": {
202-
"sentry.name": "middleware - fastify -> @fastify/multipart"
203+
"sentry.name": "middleware - fastify -> @fastify/multipart",
204+
"sentry.origin": "auto.otlp.spans"
203205
},
204206
"links": [],
205207
"kind": "internal"
@@ -234,7 +236,8 @@ mod tests {
234236
"status": "ok",
235237
"description": "middleware - fastify -> @fastify/multipart",
236238
"data": {
237-
"sentry.name": "middleware - fastify -> @fastify/multipart"
239+
"sentry.name": "middleware - fastify -> @fastify/multipart",
240+
"sentry.origin": "auto.otlp.spans"
238241
},
239242
"links": [],
240243
"kind": "internal"
@@ -299,7 +302,8 @@ mod tests {
299302
"sentry.name": "database query",
300303
"db.name": "database",
301304
"db.statement": "SELECT \"table\".\"col\" FROM \"table\" WHERE \"table\".\"col\" = %s",
302-
"db.type": "sql"
305+
"db.type": "sql",
306+
"sentry.origin": "auto.otlp.spans"
303307
},
304308
"links": [],
305309
"kind": "client"
@@ -363,7 +367,8 @@ mod tests {
363367
"sentry.name": "database query",
364368
"db.name": "database",
365369
"db.statement": "SELECT \"table\".\"col\" FROM \"table\" WHERE \"table\".\"col\" = %s",
366-
"db.type": "sql"
370+
"db.type": "sql",
371+
"sentry.origin": "auto.otlp.spans"
367372
},
368373
"links": [],
369374
"kind": "client"
@@ -414,6 +419,7 @@ mod tests {
414419
"data": {
415420
"sentry.name": "http client request",
416421
"http.request.method": "GET",
422+
"sentry.origin": "auto.otlp.spans",
417423
"url.path": "/api/search?q=foobar"
418424
},
419425
"links": [],
@@ -483,7 +489,8 @@ mod tests {
483489
"data": {
484490
"sentry.name": "cmd.run",
485491
"process.args": "[\"node\",\"--require\",\"preflight.cjs\"]",
486-
"process.info": "[41]"
492+
"process.info": "[41]",
493+
"sentry.origin": "auto.otlp.spans"
487494
},
488495
"links": []
489496
}
@@ -645,6 +652,7 @@ mod tests {
645652
"sentry.sdk.name": "sentry.php",
646653
"sentry.name": "myname",
647654
"sentry.metrics_summary.some_metric": "[]",
655+
"sentry.origin": "auto.otlp.spans",
648656
"sentry.status.message": "foo"
649657
},
650658
"links": [],
@@ -677,7 +685,9 @@ mod tests {
677685
"trace_id": "89143b0763095bd9c9955e8175d1fb23",
678686
"is_remote": true,
679687
"status": "ok",
680-
"data": {},
688+
"data": {
689+
"sentry.origin": "auto.otlp.spans"
690+
},
681691
"links": []
682692
}
683693
"#);
@@ -707,7 +717,9 @@ mod tests {
707717
"trace_id": "89143b0763095bd9c9955e8175d1fb23",
708718
"is_remote": false,
709719
"status": "ok",
710-
"data": {},
720+
"data": {
721+
"sentry.origin": "auto.otlp.spans"
722+
},
711723
"links": []
712724
}
713725
"#);
@@ -737,7 +749,9 @@ mod tests {
737749
"trace_id": "89143b0763095bd9c9955e8175d1fb23",
738750
"is_remote": false,
739751
"status": "ok",
740-
"data": {},
752+
"data": {
753+
"sentry.origin": "auto.otlp.spans"
754+
},
741755
"links": [],
742756
"kind": "client"
743757
}
@@ -797,7 +811,9 @@ mod tests {
797811
"trace_id": "3c79f60c11214eb38604f4ae0781bfb2",
798812
"is_remote": false,
799813
"status": "ok",
800-
"data": {},
814+
"data": {
815+
"sentry.origin": "auto.otlp.spans"
816+
},
801817
"links": [
802818
{
803819
"trace_id": "4c79f60c11214eb38604f4ae0781bfb2",
@@ -839,6 +855,7 @@ mod tests {
839855
"is_remote": false,
840856
"status": "internal_error",
841857
"data": {
858+
"sentry.origin": "auto.otlp.spans",
842859
"sentry.status.message": "2 is the error status code"
843860
},
844861
"links": []

relay-spans/src/otel_to_sentry_v2.rs

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use opentelemetry_proto::tonic::common::v1::InstrumentationScope;
33
use opentelemetry_proto::tonic::resource::v1::Resource;
44
use opentelemetry_proto::tonic::trace::v1::span::Link as OtelLink;
55
use opentelemetry_proto::tonic::trace::v1::span::SpanKind as OtelSpanKind;
6+
use relay_conventions::ORIGIN;
67
use relay_conventions::STATUS_MESSAGE;
78
use relay_event_schema::protocol::{Attributes, SpanKind};
89
use relay_otel::otel_value_to_attribute;
@@ -64,6 +65,8 @@ pub fn otel_to_sentry_span(
6465

6566
relay_otel::otel_scope_into_attributes(&mut sentry_attributes, resource, scope);
6667

68+
sentry_attributes.insert(ORIGIN, "auto.otlp.spans".to_owned());
69+
6770
let mut name = if name.is_empty() { None } else { Some(name) };
6871
for (key, value) in attributes.into_iter().flat_map(|attribute| {
6972
let value = attribute.value?.value?;
@@ -302,6 +305,10 @@ mod tests {
302305
"type": "double",
303306
"value": 1000.0
304307
},
308+
"sentry.origin": {
309+
"type": "string",
310+
"value": "auto.otlp.spans"
311+
},
305312
"sentry.parentSampled": {
306313
"type": "boolean",
307314
"value": true
@@ -357,6 +364,10 @@ mod tests {
357364
"sentry.exclusive_time": {
358365
"type": "double",
359366
"value": 3200.0
367+
},
368+
"sentry.origin": {
369+
"type": "string",
370+
"value": "auto.otlp.spans"
360371
}
361372
}
362373
}
@@ -421,6 +432,10 @@ mod tests {
421432
"db.type": {
422433
"type": "string",
423434
"value": "sql"
435+
},
436+
"sentry.origin": {
437+
"type": "string",
438+
"value": "auto.otlp.spans"
424439
}
425440
}
426441
}
@@ -495,6 +510,10 @@ mod tests {
495510
"sentry.description": {
496511
"type": "string",
497512
"value": "index view query"
513+
},
514+
"sentry.origin": {
515+
"type": "string",
516+
"value": "auto.otlp.spans"
498517
}
499518
}
500519
}
@@ -546,6 +565,10 @@ mod tests {
546565
"type": "string",
547566
"value": "GET"
548567
},
568+
"sentry.origin": {
569+
"type": "string",
570+
"value": "auto.otlp.spans"
571+
},
549572
"url.path": {
550573
"type": "string",
551574
"value": "/api/search?q=foobar"
@@ -723,6 +746,10 @@ mod tests {
723746
"type": "string",
724747
"value": "myop"
725748
},
749+
"sentry.origin": {
750+
"type": "string",
751+
"value": "auto.otlp.spans"
752+
},
726753
"sentry.platform": {
727754
"type": "string",
728755
"value": "php"
@@ -779,7 +806,12 @@ mod tests {
779806
"start_timestamp": 123.0,
780807
"end_timestamp": 123.5,
781808
"links": [],
782-
"attributes": {}
809+
"attributes": {
810+
"sentry.origin": {
811+
"type": "string",
812+
"value": "auto.otlp.spans"
813+
}
814+
}
783815
}
784816
"#);
785817
}
@@ -807,7 +839,12 @@ mod tests {
807839
"start_timestamp": 123.0,
808840
"end_timestamp": 123.5,
809841
"links": [],
810-
"attributes": {}
842+
"attributes": {
843+
"sentry.origin": {
844+
"type": "string",
845+
"value": "auto.otlp.spans"
846+
}
847+
}
811848
}
812849
"#);
813850
}
@@ -836,7 +873,12 @@ mod tests {
836873
"start_timestamp": 123.0,
837874
"end_timestamp": 123.5,
838875
"links": [],
839-
"attributes": {}
876+
"attributes": {
877+
"sentry.origin": {
878+
"type": "string",
879+
"value": "auto.otlp.spans"
880+
}
881+
}
840882
}
841883
"#);
842884
}
@@ -917,7 +959,12 @@ mod tests {
917959
}
918960
}
919961
],
920-
"attributes": {}
962+
"attributes": {
963+
"sentry.origin": {
964+
"type": "string",
965+
"value": "auto.otlp.spans"
966+
}
967+
}
921968
}
922969
"#);
923970
}
@@ -945,6 +992,10 @@ mod tests {
945992
"end_timestamp": 0.0,
946993
"links": [],
947994
"attributes": {
995+
"sentry.origin": {
996+
"type": "string",
997+
"value": "auto.otlp.spans"
998+
},
948999
"sentry.status.message": {
9491000
"type": "string",
9501001
"value": "2 is the error status code"

tests/integration/test_spans.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,7 @@ def test_span_ingestion(
758758
"sentry.exclusive_time": {"type": "double", "value": 500.0},
759759
"sentry.is_segment": {"type": "boolean", "value": True},
760760
"sentry.op": {"type": "string", "value": "default"},
761+
"sentry.origin": {"type": "string", "value": "auto.otlp.spans"},
761762
"sentry.segment.id": {"type": "string", "value": "d342abb1214ca182"},
762763
"sentry.status": {"type": "string", "value": "ok"},
763764
"user_agent.original": {
@@ -826,6 +827,7 @@ def test_span_ingestion(
826827
},
827828
"sentry.exclusive_time": {"type": "double", "value": 500.0},
828829
"sentry.op": {"type": "string", "value": "default"},
830+
"sentry.origin": {"type": "string", "value": "auto.otlp.spans"},
829831
"sentry.status": {"type": "string", "value": "ok"},
830832
"ui.component_name": {"type": "string", "value": "MyComponent"},
831833
"user_agent.original": {

tests/integration/test_spansv2_otel.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def test_span_ingestion(
9797
"type": "string",
9898
"value": time_within(ts, expect_resolution="ns"),
9999
},
100+
"sentry.origin": {"type": "string", "value": "auto.otlp.spans"},
100101
"ui.component_name": {"type": "string", "value": "MyComponent"},
101102
},
102103
"downsampled_retention_days": 90,

0 commit comments

Comments
 (0)