@@ -59,7 +59,6 @@ const getData = (url: string, method?: string) =>
59
59
60
60
const customAttributeFunction = ( span : api . Span ) : void => {
61
61
span . setAttribute ( 'span kind' , api . SpanKind . CLIENT ) ;
62
- span . setAttribute ( 'custom' , 'custom-attribute-value' ) ;
63
62
} ;
64
63
65
64
const defaultResource = {
@@ -337,48 +336,51 @@ describe('fetch', () => {
337
336
const keys = Object . keys ( attributes ) ;
338
337
339
338
assert . ok (
340
- attributes [ keys [ 0 ] ] !== '' ,
339
+ attributes [ AttributeNames . COMPONENT ] !== '' ,
341
340
`attributes ${ AttributeNames . COMPONENT } is not defined`
342
341
) ;
343
342
assert . strictEqual (
344
- attributes [ keys [ 1 ] ] ,
343
+ attributes [ HttpAttribute . HTTP_METHOD ] ,
345
344
'GET' ,
346
345
`attributes ${ HttpAttribute . HTTP_METHOD } is wrong`
347
346
) ;
348
347
assert . strictEqual (
349
- attributes [ keys [ 2 ] ] ,
348
+ attributes [ HttpAttribute . HTTP_URL ] ,
350
349
url ,
351
350
`attributes ${ HttpAttribute . HTTP_URL } is wrong`
352
351
) ;
353
352
assert . strictEqual (
354
- attributes [ keys [ 3 ] ] ,
353
+ attributes [ HttpAttribute . HTTP_STATUS_CODE ] ,
355
354
200 ,
356
355
`attributes ${ HttpAttribute . HTTP_STATUS_CODE } is wrong`
357
356
) ;
358
357
assert . ok (
359
- attributes [ keys [ 4 ] ] === 'OK' || attributes [ keys [ 4 ] ] === '' ,
358
+ attributes [ HttpAttribute . HTTP_STATUS_TEXT ] === 'OK' ||
359
+ attributes [ HttpAttribute . HTTP_STATUS_TEXT ] === '' ,
360
360
`attributes ${ HttpAttribute . HTTP_STATUS_TEXT } is wrong`
361
361
) ;
362
362
assert . ok (
363
- ( attributes [ keys [ 5 ] ] as string ) . indexOf ( 'localhost' ) === 0 ,
363
+ ( attributes [ HttpAttribute . HTTP_HOST ] as string ) . indexOf ( 'localhost' ) ===
364
+ 0 ,
364
365
`attributes ${ HttpAttribute . HTTP_HOST } is wrong`
365
366
) ;
366
367
assert . ok (
367
- attributes [ keys [ 6 ] ] === 'http' || attributes [ keys [ 6 ] ] === 'https' ,
368
+ attributes [ HttpAttribute . HTTP_SCHEME ] === 'http' ||
369
+ attributes [ HttpAttribute . HTTP_SCHEME ] === 'https' ,
368
370
`attributes ${ HttpAttribute . HTTP_SCHEME } is wrong`
369
371
) ;
370
372
assert . ok (
371
- attributes [ keys [ 7 ] ] !== '' ,
373
+ attributes [ HttpAttribute . HTTP_USER_AGENT ] !== '' ,
372
374
`attributes ${ HttpAttribute . HTTP_USER_AGENT } is not defined`
373
375
) ;
374
376
assert . ok (
375
- ( attributes [ keys [ 8 ] ] as number ) > 0 ,
377
+ ( attributes [ HttpAttribute . HTTP_RESPONSE_CONTENT_LENGTH ] as number ) > 0 ,
376
378
`attributes ${ HttpAttribute . HTTP_RESPONSE_CONTENT_LENGTH } is <= 0`
377
379
) ;
378
380
379
381
assert . strictEqual ( attributes [ 'span kind' ] , api . SpanKind . CLIENT ) ;
380
382
381
- assert . strictEqual ( keys . length , 9 , 'number of attributes is wrong' ) ;
383
+ assert . strictEqual ( keys . length , 10 , 'number of attributes is wrong' ) ;
382
384
} ) ;
383
385
384
386
it ( 'span should have correct events' , ( ) => {
@@ -610,11 +612,15 @@ describe('fetch', () => {
610
612
describe ( 'when request is NOT successful (wrong url)' , ( ) => {
611
613
beforeEach ( done => {
612
614
const propagateTraceHeaderCorsUrls = badUrl ;
613
- prepareData ( done , badUrl , { propagateTraceHeaderCorsUrls } ) ;
615
+ prepareData ( done , badUrl , {
616
+ propagateTraceHeaderCorsUrls,
617
+ applyCustomAttributesOnSpan : customAttributeFunction ,
618
+ } ) ;
614
619
} ) ;
615
620
afterEach ( ( ) => {
616
621
clearData ( ) ;
617
622
} ) ;
623
+
618
624
it ( 'should create a span with correct root span' , ( ) => {
619
625
const span : tracing . ReadableSpan = exportSpy . args [ 1 ] [ 0 ] [ 0 ] ;
620
626
assert . strictEqual (
@@ -623,6 +629,17 @@ describe('fetch', () => {
623
629
'parent span is not root span'
624
630
) ;
625
631
} ) ;
632
+
633
+ it ( 'should apply custom attributes' , ( ) => {
634
+ const span : tracing . ReadableSpan = exportSpy . args [ 1 ] [ 0 ] [ 0 ] ;
635
+ const attributes = span . attributes ;
636
+
637
+ assert . strictEqual (
638
+ attributes [ 'span kind' ] ,
639
+ api . SpanKind . CLIENT ,
640
+ 'Custom attribute was not applied'
641
+ ) ;
642
+ } ) ;
626
643
} ) ;
627
644
628
645
describe ( 'when request is NOT successful (405)' , ( ) => {
0 commit comments