11import type { Context , Span , SpanOptions , Tracer , TracerProvider } from '@opentelemetry/api' ;
2- import { trace } from '@opentelemetry/api' ;
3- import { startInactiveSpan , startSpanManual } from '@sentry/core' ;
2+ import { SpanKind , trace } from '@opentelemetry/api' ;
3+ import {
4+ SEMANTIC_ATTRIBUTE_SENTRY_OP ,
5+ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ,
6+ startInactiveSpan ,
7+ startSpanManual ,
8+ } from '@sentry/core' ;
49
510/**
611 * Set up a mock OTEL tracer to allow inter-op with OpenTelemetry emitted spans.
@@ -26,11 +31,16 @@ class SentryDenoTraceProvider implements TracerProvider {
2631
2732class SentryDenoTracer implements Tracer {
2833 public startSpan ( name : string , options ?: SpanOptions ) : Span {
34+ // Map OpenTelemetry SpanKind to Sentry operation
35+ const op = this . _mapSpanKindToOp ( options ?. kind ) ;
36+
2937 return startInactiveSpan ( {
3038 name,
3139 ...options ,
3240 attributes : {
3341 ...options ?. attributes ,
42+ [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'manual' ,
43+ [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : op ,
3444 'sentry.deno_tracer' : true ,
3545 } ,
3646 } ) ;
@@ -55,11 +65,16 @@ class SentryDenoTracer implements Tracer {
5565 ) : ReturnType < F > {
5666 const opts = ( typeof options === 'object' && options !== null ? options : { } ) as SpanOptions ;
5767
68+ // Map OpenTelemetry SpanKind to Sentry operation
69+ const op = this . _mapSpanKindToOp ( opts . kind ) ;
70+
5871 const spanOpts = {
5972 name,
6073 ...opts ,
6174 attributes : {
6275 ...opts . attributes ,
76+ [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'manual' ,
77+ [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : op ,
6378 'sentry.deno_tracer' : true ,
6479 } ,
6580 } ;
@@ -77,4 +92,19 @@ class SentryDenoTracer implements Tracer {
7792 // In OTEL the semantic matches `startSpanManual` because spans are not auto-ended
7893 return startSpanManual ( spanOpts , callback ) as ReturnType < F > ;
7994 }
95+
96+ private _mapSpanKindToOp ( kind ?: SpanKind ) : string {
97+ switch ( kind ) {
98+ case SpanKind . CLIENT :
99+ return 'http.client' ;
100+ case SpanKind . SERVER :
101+ return 'http.server' ;
102+ case SpanKind . PRODUCER :
103+ return 'message.produce' ;
104+ case SpanKind . CONSUMER :
105+ return 'message.consume' ;
106+ default :
107+ return 'otel.span' ;
108+ }
109+ }
80110}
0 commit comments