@@ -16,7 +16,12 @@ import {
16
16
} from '@opentelemetry/semantic-conventions' ;
17
17
18
18
import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core' ;
19
- import { descriptionForHttpMethod , getSanitizedUrl , parseSpanDescription } from '../../src/utils/parseSpanDescription' ;
19
+ import {
20
+ descriptionForHttpMethod ,
21
+ getOriginalName ,
22
+ getSanitizedUrl ,
23
+ parseSpanDescription ,
24
+ } from '../../src/utils/parseSpanDescription' ;
20
25
21
26
describe ( 'parseSpanDescription' , ( ) => {
22
27
it . each ( [
@@ -97,6 +102,22 @@ describe('parseSpanDescription', () => {
97
102
source : 'custom' ,
98
103
} ,
99
104
] ,
105
+ [
106
+ 'works with db system and custom source and custom name' ,
107
+ {
108
+ [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'custom' ,
109
+ [ SEMATTRS_DB_SYSTEM ] : 'mysql' ,
110
+ [ SEMATTRS_DB_STATEMENT ] : 'SELECT * from users' ,
111
+ [ '_sentry_span_name_set_by_user' ] : 'custom name' ,
112
+ } ,
113
+ 'test name' ,
114
+ SpanKind . CLIENT ,
115
+ {
116
+ description : 'custom name' ,
117
+ op : 'db' ,
118
+ source : 'custom' ,
119
+ } ,
120
+ ] ,
100
121
[
101
122
'works with db system without statement' ,
102
123
{
@@ -137,6 +158,21 @@ describe('parseSpanDescription', () => {
137
158
source : 'custom' ,
138
159
} ,
139
160
] ,
161
+ [
162
+ 'works with rpc service and custom source and custom name' ,
163
+ {
164
+ [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'custom' ,
165
+ [ SEMATTRS_RPC_SERVICE ] : 'rpc-test-service' ,
166
+ [ '_sentry_span_name_set_by_user' ] : 'custom name' ,
167
+ } ,
168
+ 'test name' ,
169
+ undefined ,
170
+ {
171
+ description : 'custom name' ,
172
+ op : 'rpc' ,
173
+ source : 'custom' ,
174
+ } ,
175
+ ] ,
140
176
[
141
177
'works with messaging system' ,
142
178
{
@@ -164,6 +200,21 @@ describe('parseSpanDescription', () => {
164
200
source : 'custom' ,
165
201
} ,
166
202
] ,
203
+ [
204
+ 'works with messaging system and custom source and custom name' ,
205
+ {
206
+ [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'custom' ,
207
+ [ SEMATTRS_MESSAGING_SYSTEM ] : 'test-messaging-system' ,
208
+ [ '_sentry_span_name_set_by_user' ] : 'custom name' ,
209
+ } ,
210
+ 'test name' ,
211
+ undefined ,
212
+ {
213
+ description : 'custom name' ,
214
+ op : 'message' ,
215
+ source : 'custom' ,
216
+ } ,
217
+ ] ,
167
218
[
168
219
'works with faas trigger' ,
169
220
{
@@ -191,6 +242,21 @@ describe('parseSpanDescription', () => {
191
242
source : 'custom' ,
192
243
} ,
193
244
] ,
245
+ [
246
+ 'works with faas trigger and custom source and custom name' ,
247
+ {
248
+ [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'custom' ,
249
+ [ SEMATTRS_FAAS_TRIGGER ] : 'test-faas-trigger' ,
250
+ [ '_sentry_span_name_set_by_user' ] : 'custom name' ,
251
+ } ,
252
+ 'test name' ,
253
+ undefined ,
254
+ {
255
+ description : 'custom name' ,
256
+ op : 'test-faas-trigger' ,
257
+ source : 'custom' ,
258
+ } ,
259
+ ] ,
194
260
] ) ( '%s' , ( _ , attributes , name , kind , expected ) => {
195
261
const actual = parseSpanDescription ( { attributes, kind, name } as unknown as Span ) ;
196
262
expect ( actual ) . toEqual ( expected ) ;
@@ -309,7 +375,7 @@ describe('descriptionForHttpMethod', () => {
309
375
} ,
310
376
] ,
311
377
[
312
- "doesn't overwrite name with source custom" ,
378
+ "doesn't overwrite span name with source custom" ,
313
379
'GET' ,
314
380
{
315
381
[ SEMATTRS_HTTP_METHOD ] : 'GET' ,
@@ -329,6 +395,28 @@ describe('descriptionForHttpMethod', () => {
329
395
source : 'custom' ,
330
396
} ,
331
397
] ,
398
+ [
399
+ 'takes user-passed span name (with source custom)' ,
400
+ 'GET' ,
401
+ {
402
+ [ SEMATTRS_HTTP_METHOD ] : 'GET' ,
403
+ [ SEMATTRS_HTTP_URL ] : 'https://www.example.com/my-path/123' ,
404
+ [ SEMATTRS_HTTP_TARGET ] : '/my-path/123' ,
405
+ [ ATTR_HTTP_ROUTE ] : '/my-path/:id' ,
406
+ [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'custom' ,
407
+ [ '_sentry_span_name_set_by_user' ] : 'custom name' ,
408
+ } ,
409
+ 'test name' ,
410
+ SpanKind . CLIENT ,
411
+ {
412
+ op : 'http.client' ,
413
+ description : 'custom name' ,
414
+ data : {
415
+ url : 'https://www.example.com/my-path/123' ,
416
+ } ,
417
+ source : 'custom' ,
418
+ } ,
419
+ ] ,
332
420
] ) ( '%s' , ( _ , httpMethod , attributes , name , kind , expected ) => {
333
421
const actual = descriptionForHttpMethod ( { attributes, kind, name } , httpMethod ) ;
334
422
expect ( actual ) . toEqual ( expected ) ;
@@ -482,3 +570,26 @@ describe('getSanitizedUrl', () => {
482
570
expect ( actual ) . toEqual ( expected ) ;
483
571
} ) ;
484
572
} ) ;
573
+
574
+ describe ( 'getOriginalName' , ( ) => {
575
+ it ( 'returns param name if source is not custom' , ( ) => {
576
+ expect ( getOriginalName ( 'base name' , { } ) ) . toBe ( 'base name' ) ;
577
+ } ) ;
578
+
579
+ it ( 'returns param name if `_sentry_span_name_set_by_user` attribute is not set' , ( ) => {
580
+ expect ( getOriginalName ( 'base name' , { [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'custom' } ) ) . toBe ( 'base name' ) ;
581
+ } ) ;
582
+
583
+ it ( 'returns param name if `_sentry_span_name_set_by_user` attribute is not a string' , ( ) => {
584
+ expect ( getOriginalName ( 'base name' , { [ '_sentry_span_name_set_by_user' ] : 123 } ) ) . toBe ( 'base name' ) ;
585
+ } ) ;
586
+
587
+ it ( 'returns `_sentry_span_name_set_by_user` attribute if is a string and source is custom' , ( ) => {
588
+ expect (
589
+ getOriginalName ( 'base name' , {
590
+ [ '_sentry_span_name_set_by_user' ] : 'custom name' ,
591
+ [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'custom' ,
592
+ } ) ,
593
+ ) . toBe ( 'custom name' ) ;
594
+ } ) ;
595
+ } ) ;
0 commit comments