@@ -36,12 +36,12 @@ interface SpanDescription {
36
36
/**
37
37
* Infer the op & description for a set of name, attributes and kind of a span.
38
38
*/
39
- export function inferSpanData ( originalName : string , attributes : SpanAttributes , kind : SpanKind ) : SpanDescription {
39
+ export function inferSpanData ( spanName : string , attributes : SpanAttributes , kind : SpanKind ) : SpanDescription {
40
40
// if http.method exists, this is an http request span
41
41
// eslint-disable-next-line deprecation/deprecation
42
42
const httpMethod = attributes [ ATTR_HTTP_REQUEST_METHOD ] || attributes [ SEMATTRS_HTTP_METHOD ] ;
43
43
if ( httpMethod ) {
44
- return descriptionForHttpMethod ( { attributes, name : originalName , kind } , httpMethod ) ;
44
+ return descriptionForHttpMethod ( { attributes, name : getOriginalName ( spanName , attributes ) , kind } , httpMethod ) ;
45
45
}
46
46
47
47
// eslint-disable-next-line deprecation/deprecation
@@ -53,7 +53,7 @@ export function inferSpanData(originalName: string, attributes: SpanAttributes,
53
53
// If db.type exists then this is a database call span
54
54
// If the Redis DB is used as a cache, the span description should not be changed
55
55
if ( dbSystem && ! opIsCache ) {
56
- return descriptionForDbSystem ( { attributes, name : originalName } ) ;
56
+ return descriptionForDbSystem ( { attributes, name : spanName } ) ;
57
57
}
58
58
59
59
const customSourceOrRoute = attributes [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] === 'custom' ? 'custom' : 'route' ;
@@ -64,7 +64,7 @@ export function inferSpanData(originalName: string, attributes: SpanAttributes,
64
64
if ( rpcService ) {
65
65
return {
66
66
op : 'rpc' ,
67
- description : originalName ,
67
+ description : getOriginalName ( spanName , attributes ) ,
68
68
source : customSourceOrRoute ,
69
69
} ;
70
70
}
@@ -75,7 +75,7 @@ export function inferSpanData(originalName: string, attributes: SpanAttributes,
75
75
if ( messagingSystem ) {
76
76
return {
77
77
op : 'message' ,
78
- description : originalName ,
78
+ description : getOriginalName ( spanName , attributes ) ,
79
79
source : customSourceOrRoute ,
80
80
} ;
81
81
}
@@ -84,10 +84,14 @@ export function inferSpanData(originalName: string, attributes: SpanAttributes,
84
84
// eslint-disable-next-line deprecation/deprecation
85
85
const faasTrigger = attributes [ SEMATTRS_FAAS_TRIGGER ] ;
86
86
if ( faasTrigger ) {
87
- return { op : faasTrigger . toString ( ) , description : originalName , source : customSourceOrRoute } ;
87
+ return {
88
+ op : faasTrigger . toString ( ) ,
89
+ description : getOriginalName ( spanName , attributes ) ,
90
+ source : customSourceOrRoute ,
91
+ } ;
88
92
}
89
93
90
- return { op : undefined , description : originalName , source : 'custom' } ;
94
+ return { op : undefined , description : spanName , source : 'custom' } ;
91
95
}
92
96
93
97
/**
@@ -110,7 +114,7 @@ export function parseSpanDescription(span: AbstractSpan): SpanDescription {
110
114
function descriptionForDbSystem ( { attributes, name } : { attributes : Attributes ; name : string } ) : SpanDescription {
111
115
// if we already set the source to custom, we don't overwrite the span description but just adjust the op
112
116
if ( attributes [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] === 'custom' ) {
113
- return { op : 'db' , description : name , source : 'custom' } ;
117
+ return { op : 'db' , description : getOriginalName ( name , attributes ) , source : 'custom' } ;
114
118
}
115
119
116
120
// Use DB statement (Ex "SELECT * FROM table") if possible as description.
@@ -146,7 +150,7 @@ export function descriptionForHttpMethod(
146
150
const { urlPath, url, query, fragment, hasRoute } = getSanitizedUrl ( attributes , kind ) ;
147
151
148
152
if ( ! urlPath ) {
149
- return { op : opParts . join ( '.' ) , description : name , source : 'custom' } ;
153
+ return { op : opParts . join ( '.' ) , description : getOriginalName ( name , attributes ) , source : 'custom' } ;
150
154
}
151
155
152
156
const graphqlOperationsAttribute = attributes [ SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION ] ;
@@ -192,7 +196,7 @@ export function descriptionForHttpMethod(
192
196
193
197
return {
194
198
op : opParts . join ( '.' ) ,
195
- description : useInferredDescription ? description : name ,
199
+ description : useInferredDescription ? description : getOriginalName ( name , attributes ) ,
196
200
source : useInferredDescription ? source : 'custom' ,
197
201
data,
198
202
} ;
@@ -258,3 +262,11 @@ export function getSanitizedUrl(
258
262
259
263
return { urlPath : undefined , url, query, fragment, hasRoute : false } ;
260
264
}
265
+
266
+ function getOriginalName ( name : string , attributes : Attributes ) : string {
267
+ return attributes [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] === 'custom' &&
268
+ attributes [ '_sentry_span_name_set_by_user' ] &&
269
+ typeof attributes [ '_sentry_span_name_set_by_user' ] === 'string'
270
+ ? attributes [ '_sentry_span_name_set_by_user' ]
271
+ : name ;
272
+ }
0 commit comments