@@ -164,31 +164,48 @@ describe('Span', () => {
164164 expect ( span . timestamp ) . toBeGreaterThan ( 1 ) ;
165165 } ) ;
166166
167- test ( 'finish a scope span without transaction' , ( ) => {
167+ test ( 'finish a span without transaction' , ( ) => {
168168 const spy = jest . spyOn ( hub as any , 'captureEvent' ) ;
169169 const span = new Span ( { } , hub ) ;
170170 span . finish ( ) ;
171171 expect ( spy ) . not . toHaveBeenCalled ( ) ;
172172 } ) ;
173173
174- test ( 'finish a scope span with transaction' , ( ) => {
174+ test ( 'finish a span with transaction' , ( ) => {
175175 const spy = jest . spyOn ( hub as any , 'captureEvent' ) as any ;
176176 const span = new Span ( { transaction : 'test' , sampled : false } , hub ) ;
177177 span . initFinishedSpans ( ) ;
178178 span . finish ( ) ;
179- expect ( spy ) . toHaveBeenCalled ( ) ;
180179 expect ( spy . mock . calls [ 0 ] [ 0 ] . spans ) . toHaveLength ( 0 ) ;
180+ expect ( spy . mock . calls [ 0 ] [ 0 ] . contexts . trace ) . toEqual ( span . getTraceContext ( ) ) ;
181181 } ) ;
182182
183- test ( 'finish a scope span with transaction + child span' , ( ) => {
183+ test ( 'finish a span with transaction + child span' , ( ) => {
184184 const spy = jest . spyOn ( hub as any , 'captureEvent' ) as any ;
185185 const parentSpan = new Span ( { transaction : 'test' , sampled : false } , hub ) ;
186186 parentSpan . initFinishedSpans ( ) ;
187187 const childSpan = parentSpan . child ( ) ;
188188 childSpan . finish ( ) ;
189189 parentSpan . finish ( ) ;
190- expect ( spy ) . toHaveBeenCalled ( ) ;
191190 expect ( spy . mock . calls [ 0 ] [ 0 ] . spans ) . toHaveLength ( 1 ) ;
191+ expect ( spy . mock . calls [ 0 ] [ 0 ] . contexts . trace ) . toEqual ( parentSpan . getTraceContext ( ) ) ;
192+ } ) ;
193+
194+ test ( 'finish a span with another one on the scope shouldnt override contexts.trace' , ( ) => {
195+ const spy = jest . spyOn ( hub as any , 'captureEvent' ) as any ;
196+
197+ const spanOne = new Span ( { transaction : 'testOne' , sampled : false } , hub ) ;
198+ spanOne . initFinishedSpans ( ) ;
199+ const childSpanOne = spanOne . child ( ) ;
200+ childSpanOne . finish ( ) ;
201+ hub . configureScope ( ( scope ) => { scope . setSpan ( spanOne ) } )
202+
203+ const spanTwo = new Span ( { transaction : 'testTwo' , sampled : false } , hub ) ;
204+ spanTwo . initFinishedSpans ( ) ;
205+ spanTwo . finish ( ) ;
206+
207+ expect ( spy . mock . calls [ 0 ] [ 0 ] . spans ) . toHaveLength ( 0 ) ;
208+ expect ( spy . mock . calls [ 0 ] [ 0 ] . contexts . trace ) . toEqual ( spanTwo . getTraceContext ( ) ) ;
192209 } ) ;
193210 } ) ;
194211
0 commit comments