@@ -23,6 +23,8 @@ import {
23
23
TraceFlags ,
24
24
} from '@opentelemetry/api' ;
25
25
import {
26
+ DEFAULT_ATTRIBUTE_COUNT_LIMIT ,
27
+ DEFAULT_ATTRIBUTE_VALUE_LENGTH_LIMIT ,
26
28
hrTime ,
27
29
hrTimeDuration ,
28
30
hrTimeToMilliseconds ,
@@ -486,6 +488,38 @@ describe('Span', () => {
486
488
} ) ;
487
489
} ) ;
488
490
491
+ describe ( 'when span "attributeCountLimit" set to the default value and general "attributeCountLimit" option defined' , ( ) => {
492
+ const tracer = new BasicTracerProvider ( {
493
+ generalLimits : {
494
+ // Setting count limit
495
+ attributeCountLimit : 10 ,
496
+ } ,
497
+ spanLimits : {
498
+ attributeCountLimit : DEFAULT_ATTRIBUTE_COUNT_LIMIT ,
499
+ }
500
+ } ) . getTracer ( 'default' ) ;
501
+
502
+ const span = new Span (
503
+ tracer ,
504
+ ROOT_CONTEXT ,
505
+ name ,
506
+ spanContext ,
507
+ SpanKind . CLIENT
508
+ ) ;
509
+ for ( let i = 0 ; i < 150 ; i ++ ) {
510
+ span . setAttribute ( 'foo' + i , 'bar' + i ) ;
511
+ }
512
+ span . end ( ) ;
513
+
514
+ it ( 'should remove / drop all remaining values after the number of values exceeds the span limit' , ( ) => {
515
+ assert . strictEqual ( Object . keys ( span . attributes ) . length , DEFAULT_ATTRIBUTE_COUNT_LIMIT ) ;
516
+ assert . strictEqual ( span . attributes [ 'foo0' ] , 'bar0' ) ;
517
+ assert . strictEqual ( span . attributes [ 'foo10' ] , 'bar10' ) ;
518
+ assert . strictEqual ( span . attributes [ 'foo127' ] , 'bar127' ) ;
519
+ assert . strictEqual ( span . attributes [ 'foo128' ] , undefined ) ;
520
+ } ) ;
521
+ } ) ;
522
+
489
523
describe ( 'when "attributeValueLengthLimit" option defined' , ( ) => {
490
524
const tracer = new BasicTracerProvider ( {
491
525
generalLimits : {
@@ -528,6 +562,44 @@ describe('Span', () => {
528
562
assert . strictEqual ( span . attributes [ 'attr-non-string' ] , true ) ;
529
563
} ) ;
530
564
} ) ;
565
+
566
+ describe ( 'when span "attributeValueLengthLimit" set to the default value and general "attributeValueLengthLimit" option defined' , ( ) => {
567
+ const tracer = new BasicTracerProvider ( {
568
+ generalLimits : {
569
+ // Setting attribute value length limit
570
+ attributeValueLengthLimit : 10 ,
571
+ } ,
572
+ spanLimits : {
573
+ // Setting attribute value length limit
574
+ attributeValueLengthLimit : DEFAULT_ATTRIBUTE_VALUE_LENGTH_LIMIT ,
575
+ } ,
576
+ } ) . getTracer ( 'default' ) ;
577
+
578
+ const span = new Span (
579
+ tracer ,
580
+ ROOT_CONTEXT ,
581
+ name ,
582
+ spanContext ,
583
+ SpanKind . CLIENT
584
+ ) ;
585
+
586
+ it ( 'should not truncate value' , ( ) => {
587
+ span . setAttribute ( 'attr-with-more-length' , 'abcdefghijklmn' ) ;
588
+ assert . strictEqual ( span . attributes [ 'attr-with-more-length' ] , 'abcdefghijklmn' ) ;
589
+ } ) ;
590
+
591
+ it ( 'should not truncate value of arrays' , ( ) => {
592
+ span . setAttribute ( 'attr-array-of-strings' , [ 'abcdefghijklmn' , 'abc' , 'abcde' , '' ] ) ;
593
+ span . setAttribute ( 'attr-array-of-bool' , [ true , false ] ) ;
594
+ assert . deepStrictEqual ( span . attributes [ 'attr-array-of-strings' ] , [ 'abcdefghijklmn' , 'abc' , 'abcde' , '' ] ) ;
595
+ assert . deepStrictEqual ( span . attributes [ 'attr-array-of-bool' ] , [ true , false ] ) ;
596
+ } ) ;
597
+
598
+ it ( 'should return same value for non-string values' , ( ) => {
599
+ span . setAttribute ( 'attr-non-string' , true ) ;
600
+ assert . strictEqual ( span . attributes [ 'attr-non-string' ] , true ) ;
601
+ } ) ;
602
+ } ) ;
531
603
} ) ;
532
604
} ) ;
533
605
0 commit comments