@@ -640,16 +640,24 @@ describe('ioredis', () => {
640
640
} ;
641
641
instrumentation . setConfig ( config ) ;
642
642
} ) ;
643
- it ( 'should not create child span' , async ( ) => {
643
+ it ( 'should not create child span for query ' , async ( ) => {
644
644
await client . set ( testKeyName , 'data' ) ;
645
645
const result = await client . del ( testKeyName ) ;
646
646
assert . strictEqual ( result , 1 ) ;
647
647
assert . strictEqual ( memoryExporter . getFinishedSpans ( ) . length , 0 ) ;
648
648
} ) ;
649
+
650
+ it ( 'should not create child span for connect' , async ( ) => {
651
+ const lazyClient = new ioredis ( URL , { lazyConnect : true } ) ;
652
+ await lazyClient . connect ( ) ;
653
+ const spans = memoryExporter . getFinishedSpans ( ) ;
654
+ await lazyClient . quit ( ) ;
655
+ assert . strictEqual ( spans . length , 0 ) ;
656
+ } ) ;
649
657
} ) ;
650
658
651
659
describe ( 'Instrumentation with requireParentSpan' , ( ) => {
652
- it ( 'should instrument with requireParentSpan equal false' , async ( ) => {
660
+ it ( 'should instrument queries with requireParentSpan equal false' , async ( ) => {
653
661
const config : IORedisInstrumentationConfig = {
654
662
requireParentSpan : false ,
655
663
} ;
@@ -658,23 +666,48 @@ describe('ioredis', () => {
658
666
await client . set ( testKeyName , 'data' ) ;
659
667
const result = await client . del ( testKeyName ) ;
660
668
assert . strictEqual ( result , 1 ) ;
669
+ const endedSpans = memoryExporter . getFinishedSpans ( ) ;
661
670
671
+ assert . strictEqual ( endedSpans . length , 2 ) ;
672
+ testUtils . assertSpan (
673
+ endedSpans [ 0 ] ,
674
+ SpanKind . CLIENT ,
675
+ {
676
+ ...DEFAULT_ATTRIBUTES ,
677
+ [ SemanticAttributes . DB_STATEMENT ] : `set ${ testKeyName } [1 other arguments]` ,
678
+ } ,
679
+ [ ] ,
680
+ unsetStatus
681
+ ) ;
682
+ } ) ;
683
+
684
+ it ( 'should instrument connect with requireParentSpan equal false' , async ( ) => {
685
+ const config : IORedisInstrumentationConfig = {
686
+ requireParentSpan : false ,
687
+ } ;
688
+ instrumentation . setConfig ( config ) ;
689
+
690
+ const lazyClient = new ioredis ( URL , { lazyConnect : true } ) ;
691
+ await lazyClient . connect ( ) ;
662
692
const endedSpans = memoryExporter . getFinishedSpans ( ) ;
663
693
assert . strictEqual ( endedSpans . length , 2 ) ;
694
+ assert . strictEqual ( endedSpans [ 0 ] . name , 'connect' ) ;
695
+ assert . strictEqual ( endedSpans [ 1 ] . name , 'info' ) ;
664
696
697
+ await lazyClient . quit ( ) ;
665
698
testUtils . assertSpan (
666
699
endedSpans [ 0 ] ,
667
700
SpanKind . CLIENT ,
668
701
{
669
702
...DEFAULT_ATTRIBUTES ,
670
- [ SemanticAttributes . DB_STATEMENT ] : `set ${ testKeyName } [1 other arguments]` ,
703
+ [ SemanticAttributes . DB_STATEMENT ] : 'connect' ,
671
704
} ,
672
705
[ ] ,
673
706
unsetStatus
674
707
) ;
675
708
} ) ;
676
709
677
- it ( 'should not instrument with requireParentSpan equal true' , async ( ) => {
710
+ it ( 'should not instrument queries with requireParentSpan equal true' , async ( ) => {
678
711
const config : IORedisInstrumentationConfig = {
679
712
requireParentSpan : true ,
680
713
} ;
@@ -686,6 +719,20 @@ describe('ioredis', () => {
686
719
687
720
assert . strictEqual ( memoryExporter . getFinishedSpans ( ) . length , 0 ) ;
688
721
} ) ;
722
+
723
+ it ( 'should not instrument connect with requireParentSpan equal true' , async ( ) => {
724
+ const config : IORedisInstrumentationConfig = {
725
+ requireParentSpan : true ,
726
+ } ;
727
+ instrumentation . setConfig ( config ) ;
728
+
729
+ const lazyClient = new ioredis ( URL , { lazyConnect : true } ) ;
730
+ await lazyClient . connect ( ) ;
731
+ const endedSpans = memoryExporter . getFinishedSpans ( ) ;
732
+ assert . strictEqual ( endedSpans . length , 0 ) ;
733
+
734
+ await lazyClient . quit ( ) ;
735
+ } ) ;
689
736
} ) ;
690
737
691
738
describe ( 'Instrumenting with a custom db.statement serializer' , ( ) => {
0 commit comments