@@ -5,6 +5,8 @@ require('../setup/tap')
5
5
const { expect } = require ( 'chai' )
6
6
const msgpack = require ( '@msgpack/msgpack' )
7
7
const id = require ( '../../src/id' )
8
+ const proxyquire = require ( 'proxyquire' )
9
+ const sinon = require ( 'sinon' )
8
10
9
11
function randString ( length ) {
10
12
return Array . from ( { length } , ( ) => {
@@ -23,7 +25,7 @@ describe('encode', () => {
23
25
logger = {
24
26
debug : sinon . stub ( )
25
27
}
26
- const { AgentEncoder } = proxyquire ( '../src/encode/0.4' , {
28
+ const { AgentEncoder } = proxyquire ( '../../ src/encode/0.4' , {
27
29
'../log' : logger
28
30
} )
29
31
writer = { flush : sinon . spy ( ) }
@@ -474,8 +476,15 @@ describe('encode', () => {
474
476
} )
475
477
476
478
describe ( 'with configuration' , ( ) => {
479
+ let logger
480
+
477
481
beforeEach ( ( ) => {
478
- const { AgentEncoder } = proxyquire ( '../src/encode/0.4' , {
482
+ // Create a sinon spy for log.debug
483
+ logger = {
484
+ debug : sinon . spy ( )
485
+ }
486
+
487
+ const { AgentEncoder } = proxyquire ( '../../src/encode/0.4' , {
479
488
'../log' : logger
480
489
} )
481
490
writer = { flush : sinon . spy ( ) , _config : { trace : { nativeSpanEvents : true } } }
@@ -565,5 +574,71 @@ describe('encode', () => {
565
574
566
575
expect ( trace [ 0 ] . span_events ) . to . deep . equal ( formattedTopLevelEvent )
567
576
} )
577
+
578
+ it ( 'should call log.debug only once for the same unsupported key' , ( ) => {
579
+ const topLevelEvents = [
580
+ {
581
+ name : 'Event 1' ,
582
+ time_unix_nano : 1000000 ,
583
+ attributes : { unsupported_key : { some : 'object' } , other_key : 'valid' }
584
+ } ,
585
+ {
586
+ name : 'Event 2' ,
587
+ time_unix_nano : 2000000 ,
588
+ attributes : { unsupported_key : { another : 'object' } }
589
+ } ,
590
+ {
591
+ name : 'Event 3' ,
592
+ time_unix_nano : 3000000 ,
593
+ attributes : { unsupported_key : { yet : 'another object' } }
594
+ } ,
595
+ {
596
+ name : 'Event 4' ,
597
+ time_unix_nano : 4000000 ,
598
+ attributes : { unsupported_key : { different : 'structure' } }
599
+ }
600
+ ]
601
+
602
+ data [ 0 ] . span_events = topLevelEvents
603
+
604
+ encoder . encode ( data )
605
+
606
+ // Assert that log.debug was called only once for 'unsupported_key'
607
+ sinon . assert . calledOnce ( logger . debug )
608
+ sinon . assert . calledWith (
609
+ logger . debug ,
610
+ sinon . match ( / E n c o u n t e r e d u n s u p p o r t e d d a t a t y p e f o r s p a n e v e n t v 0 \. 4 e n c o d i n g , k e y : u n s u p p o r t e d _ k e y / )
611
+ )
612
+ } )
613
+
614
+ it ( 'should call log.debug once per unique unsupported key' , ( ) => {
615
+ const topLevelEvents = [
616
+ {
617
+ name : 'Event 1' ,
618
+ time_unix_nano : 1000000 ,
619
+ attributes : { unsupported_key1 : { some : 'object' } , unsupported_key2 : { another : 'object' } }
620
+ } ,
621
+ {
622
+ name : 'Event 2' ,
623
+ time_unix_nano : 2000000 ,
624
+ attributes : { unsupported_key1 : { different : 'structure' } , unsupported_key3 : { more : 'objects' } }
625
+ } ,
626
+ {
627
+ name : 'Event 3' ,
628
+ time_unix_nano : 3000000 ,
629
+ attributes : { unsupported_key2 : { yet : 'another object' } , unsupported_key3 : { extra : 'data' } }
630
+ }
631
+ ]
632
+
633
+ data [ 0 ] . span_events = topLevelEvents
634
+
635
+ encoder . encode ( data )
636
+
637
+ // Assert that log.debug was called once for each unique unsupported key
638
+ expect ( logger . debug . callCount ) . to . equal ( 3 )
639
+ expect ( logger . debug . getCall ( 0 ) . args [ 0 ] ) . to . match ( / u n s u p p o r t e d _ k e y 1 / )
640
+ expect ( logger . debug . getCall ( 1 ) . args [ 0 ] ) . to . match ( / u n s u p p o r t e d _ k e y 2 / )
641
+ expect ( logger . debug . getCall ( 2 ) . args [ 0 ] ) . to . match ( / u n s u p p o r t e d _ k e y 3 / )
642
+ } )
568
643
} )
569
644
} )
0 commit comments