@@ -21,6 +21,7 @@ describe('TextMapPropagator', () => {
21
21
let textMap
22
22
let baggageItems
23
23
let config
24
+ let log
24
25
25
26
const createContext = ( params = { } ) => {
26
27
const trace = { started : [ ] , finished : [ ] , tags : { } }
@@ -40,7 +41,12 @@ describe('TextMapPropagator', () => {
40
41
}
41
42
42
43
beforeEach ( ( ) => {
43
- TextMapPropagator = require ( '../../../src/opentracing/propagation/text_map' )
44
+ log = {
45
+ debug : sinon . spy ( )
46
+ }
47
+ TextMapPropagator = proxyquire ( '../src/opentracing/propagation/text_map' , {
48
+ '../../log' : log
49
+ } )
44
50
config = new Config ( { tagsHeaderMaxLength : 512 } )
45
51
propagator = new TextMapPropagator ( config )
46
52
textMap = {
@@ -782,6 +788,18 @@ describe('TextMapPropagator', () => {
782
788
expect ( first . _links [ 0 ] . attributes . context_headers ) . to . equal ( 'datadog' )
783
789
} )
784
790
791
+ it ( 'should log extraction' , ( ) => {
792
+ const carrier = textMap
793
+
794
+ propagator . extract ( carrier )
795
+
796
+ expect ( log . debug ) . to . have . been . called
797
+ expect ( log . debug . firstCall . args [ 0 ] ( ) ) . to . equal ( [
798
+ 'Extract from carrier (datadog, tracecontext, baggage):' ,
799
+ '{"x-datadog-trace-id":"123","x-datadog-parent-id":"456"}.'
800
+ ] . join ( ' ' ) )
801
+ } )
802
+
785
803
describe ( 'with B3 propagation as multiple headers' , ( ) => {
786
804
beforeEach ( ( ) => {
787
805
config . tracePropagationStyle . extract = [ 'b3multi' ]
@@ -857,6 +875,19 @@ describe('TextMapPropagator', () => {
857
875
858
876
expect ( spanContext ) . to . be . null
859
877
} )
878
+
879
+ it ( 'should log extraction' , ( ) => {
880
+ textMap [ 'x-b3-traceid' ] = '0000000000000123'
881
+ textMap [ 'x-b3-spanid' ] = '0000000000000456'
882
+
883
+ propagator . extract ( textMap )
884
+
885
+ expect ( log . debug ) . to . have . been . called
886
+ expect ( log . debug . firstCall . args [ 0 ] ( ) ) . to . equal ( [
887
+ 'Extract from carrier (b3multi):' ,
888
+ '{"x-b3-traceid":"0000000000000123","x-b3-spanid":"0000000000000456"}.'
889
+ ] . join ( ' ' ) )
890
+ } )
860
891
} )
861
892
862
893
describe ( 'with B3 propagation as a single header' , ( ) => {
@@ -991,6 +1022,17 @@ describe('TextMapPropagator', () => {
991
1022
spanId : id ( '456' , 16 )
992
1023
} ) )
993
1024
} )
1025
+
1026
+ it ( 'should log extraction' , ( ) => {
1027
+ textMap . b3 = '0000000000000123-0000000000000456'
1028
+
1029
+ propagator . extract ( textMap )
1030
+
1031
+ expect ( log . debug ) . to . have . been . called
1032
+ expect ( log . debug . firstCall . args [ 0 ] ( ) ) . to . equal (
1033
+ `Extract from carrier (b3 single header): {"b3":"${ textMap . b3 } "}.`
1034
+ )
1035
+ } )
994
1036
} )
995
1037
996
1038
describe ( 'With traceparent propagation as single header' , ( ) => {
@@ -1119,6 +1161,21 @@ describe('TextMapPropagator', () => {
1119
1161
expect ( carrier [ 'x-datadog-tags' ] ) . to . include ( '_dd.p.dm=-0' )
1120
1162
expect ( spanContext . _trace . tags [ '_dd.p.dm' ] ) . to . eql ( '-0' )
1121
1163
} )
1164
+
1165
+ it ( 'should log extraction' , ( ) => {
1166
+ const traceparent = textMap . traceparent = '00-1111aaaa2222bbbb3333cccc4444dddd-5555eeee6666ffff-01'
1167
+ const tracestate = textMap . tracestate = 'other=bleh,dd=t.foo_bar_baz_:abc_!@#$%^&*()_+`-~;s:2;o:foo;t.dm:-4'
1168
+
1169
+ config . tracePropagationStyle . extract = [ 'tracecontext' ]
1170
+
1171
+ propagator . extract ( textMap )
1172
+
1173
+ expect ( log . debug ) . to . have . been . called
1174
+ expect ( log . debug . firstCall . args [ 0 ] ( ) ) . to . equal ( [
1175
+ 'Extract from carrier (tracecontext):' ,
1176
+ `{"traceparent":"${ traceparent } ","tracestate":"${ tracestate } "}.`
1177
+ ] . join ( ' ' ) )
1178
+ } )
1122
1179
} )
1123
1180
} )
1124
1181
} )
0 commit comments