@@ -37,8 +37,8 @@ const expectSpansInStore = (inMemSpanStore: InMemoryDispatcher, expectedCount: n
3737 const versionTagValue = receivedSpan . tags ( ) [ 'version' ] ;
3838 expect ( versionTagValue ) . eq ( '1.1' ) ;
3939 expect ( receivedSpan . serviceName ( ) ) . eq ( dummyServiceName ) ;
40- expect ( isUndefined ( receivedSpan . context ( ) . traceId ( ) ) ) . eq ( false ) ;
41- expect ( isUndefined ( receivedSpan . context ( ) . spanId ( ) ) ) . eq ( false ) ;
40+ expect ( isUndefined ( receivedSpan . context ( ) . traceId ) ) . eq ( false ) ;
41+ expect ( isUndefined ( receivedSpan . context ( ) . spanId ) ) . eq ( false ) ;
4242 } ) ;
4343} ;
4444
@@ -62,7 +62,7 @@ describe('Tracer tests', () => {
6262 expectSpansInStore ( inMemSpanStore , 1 ) ;
6363 const receivedSpan = inMemSpanStore . spans ( ) [ 0 ] ;
6464 expect ( receivedSpan . operationName ( ) ) . eq ( dummyOperation ) ;
65- expect ( isUndefined ( receivedSpan . context ( ) . parentSpanId ( ) ) ) . eq ( true ) ;
65+ expect ( isUndefined ( receivedSpan . context ( ) . parentSpanId ) ) . eq ( true ) ;
6666 } ) ;
6767
6868 it ( 'should start and dispatch server and client spans' , ( ) => {
@@ -77,6 +77,9 @@ describe('Tracer tests', () => {
7777 startClientSpanFields . childOf = serverSpan . context ( ) ;
7878 startClientSpanFields . tags = { 'span.kind' : 'client' } ;
7979 const clientSpan = tracer . startSpan ( downstreamOperation , startClientSpanFields ) ;
80+ clientSpan . log ( {
81+ eventCode : 100
82+ } ) ;
8083
8184 expect ( serverSpan . isFinished ( ) ) . eq ( false ) ;
8285 expect ( inMemSpanStore . spans ( ) . length ) . equal ( 0 ) ;
@@ -85,16 +88,21 @@ describe('Tracer tests', () => {
8588
8689 expectSpansInStore ( inMemSpanStore , 2 ) ;
8790
88- expect ( inMemSpanStore . spans ( ) . map ( span => span . operationName ( ) ) ) . includes ( downstreamOperation ) ;
89- expect ( inMemSpanStore . spans ( ) . map ( span => span . operationName ( ) ) ) . includes ( dummyOperation ) ;
90-
9191 const receivedClientSpan = findSpan ( inMemSpanStore , 'client' ) ;
9292 const receivedServerSpan = findSpan ( inMemSpanStore , 'server' ) ;
9393
94+ expect ( receivedClientSpan . operationName ( ) ) . eq ( downstreamOperation ) ;
95+ expect ( receivedServerSpan . operationName ( ) ) . eq ( dummyOperation ) ;
9496 expect ( receivedClientSpan . duration ( ) <= receivedServerSpan . duration ( ) ) . eq ( true ) ;
95- expect ( receivedClientSpan . context ( ) . parentSpanId ( ) ) . eq ( receivedServerSpan . context ( ) . spanId ( ) ) ;
96- expect ( isUndefined ( receivedServerSpan . context ( ) . parentSpanId ( ) ) ) . eq ( true ) ;
97- expect ( receivedServerSpan . context ( ) . traceId ( ) ) . eq ( receivedClientSpan . context ( ) . traceId ( ) ) ;
97+ expect ( receivedClientSpan . context ( ) . parentSpanId ) . eq ( receivedServerSpan . context ( ) . spanId ) ;
98+ expect ( isUndefined ( receivedServerSpan . context ( ) . parentSpanId ) ) . eq ( true ) ;
99+ expect ( receivedServerSpan . context ( ) . traceId ) . eq ( receivedClientSpan . context ( ) . traceId ) ;
100+
101+ expect ( receivedClientSpan . logs ( ) . length ) . eq ( 1 ) ;
102+ receivedClientSpan . logs ( ) . forEach ( log => {
103+ expect ( log . keyValuePairs [ 'eventCode' ] ) . eq ( 100 ) ;
104+ expect ( log . timestamp <= ( Date . now ( ) * 1000 ) ) . eq ( true ) ;
105+ } )
98106 } ) ;
99107
100108 it ( 'should inject the span in the carrier' , ( ) => {
@@ -111,7 +119,7 @@ describe('Tracer tests', () => {
111119 const tracer = new Tracer ( dummyServiceName , inMemSpanStore , commonTags ) ;
112120 const carrier = { 'Trace-ID' : 'a' , 'Span-ID' : 'b' , 'Parent-ID' : 'c' , 'Baggage-myKey' : 'myVal' } ;
113121 const spanContext = tracer . extract ( opentracing . FORMAT_TEXT_MAP , carrier ) ;
114- expect ( JSON . stringify ( spanContext ) ) . eq ( '{"_traceId ":"a","_spanId ":"b","_parentSpanId ":"c","_baggage ":{"myKey":"myVal"}}' ) ;
122+ expect ( JSON . stringify ( spanContext ) ) . eq ( '{"traceId ":"a","spanId ":"b","parentSpanId ":"c","baggage ":{"myKey":"myVal"}}' ) ;
115123 } ) ;
116124 } ) ;
117125} ) ;
0 commit comments