11import { AttributeValue , SpanKind } from '@opentelemetry/api' ;
22import { Span as OtelSpan } from '@opentelemetry/sdk-trace-base' ;
33import { SemanticAttributes } from '@opentelemetry/semantic-conventions' ;
4+ import { TransactionSource } from '@sentry/types' ;
45
56interface SpanDescription {
67 op : string | undefined ;
78 description : string ;
9+ source : TransactionSource ;
810}
911
1012/**
@@ -36,6 +38,7 @@ export function parseSpanDescription(otelSpan: OtelSpan): SpanDescription {
3638 return {
3739 op : 'rpc' ,
3840 description : name ,
41+ source : 'route' ,
3942 } ;
4043 }
4144
@@ -45,16 +48,17 @@ export function parseSpanDescription(otelSpan: OtelSpan): SpanDescription {
4548 return {
4649 op : 'message' ,
4750 description : name ,
51+ source : 'route' ,
4852 } ;
4953 }
5054
5155 // If faas.trigger exists then this is a function as a service span.
5256 const faasTrigger = attributes [ SemanticAttributes . FAAS_TRIGGER ] ;
5357 if ( faasTrigger ) {
54- return { op : faasTrigger . toString ( ) , description : name } ;
58+ return { op : faasTrigger . toString ( ) , description : name , source : 'route' } ;
5559 }
5660
57- return { op : undefined , description : name } ;
61+ return { op : undefined , description : name , source : 'custom' } ;
5862}
5963
6064function descriptionForDbSystem ( otelSpan : OtelSpan , _dbSystem : AttributeValue ) : SpanDescription {
@@ -65,7 +69,7 @@ function descriptionForDbSystem(otelSpan: OtelSpan, _dbSystem: AttributeValue):
6569
6670 const description = statement ? statement . toString ( ) : name ;
6771
68- return { op : 'db' , description } ;
72+ return { op : 'db' , description, source : 'task' } ;
6973}
7074
7175function descriptionForHttpMethod ( otelSpan : OtelSpan , httpMethod : AttributeValue ) : SpanDescription {
@@ -82,15 +86,19 @@ function descriptionForHttpMethod(otelSpan: OtelSpan, httpMethod: AttributeValue
8286 break ;
8387 }
8488
89+ const httpTarget = attributes [ SemanticAttributes . HTTP_TARGET ] ;
90+ const httpRoute = attributes [ SemanticAttributes . HTTP_ROUTE ] ;
91+
8592 // Ex. /api/users
86- const httpPath = attributes [ SemanticAttributes . HTTP_ROUTE ] || attributes [ SemanticAttributes . HTTP_TARGET ] ;
93+ const httpPath = httpRoute || httpTarget ;
8794
8895 if ( ! httpPath ) {
89- return { op : opParts . join ( '.' ) , description : name } ;
96+ return { op : opParts . join ( '.' ) , description : name , source : 'custom' } ;
9097 }
9198
9299 // Ex. description="GET /api/users".
93100 const description = `${ httpMethod } ${ httpPath } ` ;
101+ const source : TransactionSource = httpRoute ? 'route' : 'url' ;
94102
95- return { op : opParts . join ( '.' ) , description } ;
103+ return { op : opParts . join ( '.' ) , description, source } ;
96104}
0 commit comments