1
1
import { AttributeValue , SpanKind } from '@opentelemetry/api' ;
2
2
import { Span as OtelSpan } from '@opentelemetry/sdk-trace-base' ;
3
3
import { SemanticAttributes } from '@opentelemetry/semantic-conventions' ;
4
+ import { TransactionSource } from '@sentry/types' ;
4
5
5
6
interface SpanDescription {
6
7
op : string | undefined ;
7
8
description : string ;
9
+ source : TransactionSource ;
8
10
}
9
11
10
12
/**
@@ -36,6 +38,7 @@ export function parseSpanDescription(otelSpan: OtelSpan): SpanDescription {
36
38
return {
37
39
op : 'rpc' ,
38
40
description : name ,
41
+ source : 'route' ,
39
42
} ;
40
43
}
41
44
@@ -45,16 +48,17 @@ export function parseSpanDescription(otelSpan: OtelSpan): SpanDescription {
45
48
return {
46
49
op : 'message' ,
47
50
description : name ,
51
+ source : 'route' ,
48
52
} ;
49
53
}
50
54
51
55
// If faas.trigger exists then this is a function as a service span.
52
56
const faasTrigger = attributes [ SemanticAttributes . FAAS_TRIGGER ] ;
53
57
if ( faasTrigger ) {
54
- return { op : faasTrigger . toString ( ) , description : name } ;
58
+ return { op : faasTrigger . toString ( ) , description : name , source : 'route' } ;
55
59
}
56
60
57
- return { op : undefined , description : name } ;
61
+ return { op : undefined , description : name , source : 'custom' } ;
58
62
}
59
63
60
64
function descriptionForDbSystem ( otelSpan : OtelSpan , _dbSystem : AttributeValue ) : SpanDescription {
@@ -65,7 +69,7 @@ function descriptionForDbSystem(otelSpan: OtelSpan, _dbSystem: AttributeValue):
65
69
66
70
const description = statement ? statement . toString ( ) : name ;
67
71
68
- return { op : 'db' , description } ;
72
+ return { op : 'db' , description, source : 'task' } ;
69
73
}
70
74
71
75
function descriptionForHttpMethod ( otelSpan : OtelSpan , httpMethod : AttributeValue ) : SpanDescription {
@@ -82,15 +86,19 @@ function descriptionForHttpMethod(otelSpan: OtelSpan, httpMethod: AttributeValue
82
86
break ;
83
87
}
84
88
89
+ const httpTarget = attributes [ SemanticAttributes . HTTP_TARGET ] ;
90
+ const httpRoute = attributes [ SemanticAttributes . HTTP_ROUTE ] ;
91
+
85
92
// Ex. /api/users
86
- const httpPath = attributes [ SemanticAttributes . HTTP_ROUTE ] || attributes [ SemanticAttributes . HTTP_TARGET ] ;
93
+ const httpPath = httpRoute || httpTarget ;
87
94
88
95
if ( ! httpPath ) {
89
- return { op : opParts . join ( '.' ) , description : name } ;
96
+ return { op : opParts . join ( '.' ) , description : name , source : 'custom' } ;
90
97
}
91
98
92
99
// Ex. description="GET /api/users".
93
100
const description = `${ httpMethod } ${ httpPath } ` ;
101
+ const source : TransactionSource = httpRoute ? 'route' : 'url' ;
94
102
95
- return { op : opParts . join ( '.' ) , description } ;
103
+ return { op : opParts . join ( '.' ) , description, source } ;
96
104
}
0 commit comments