@@ -93,6 +93,12 @@ describe('Koa Instrumentation - Core Tests', () => {
9393 await next ( ) ;
9494 } ;
9595
96+ const spanCreateMiddleware : koa . Middleware = async ( ctx , next ) => {
97+ const span = tracer . startSpan ( 'foo' ) ;
98+ span . end ( ) ;
99+ await next ( ) ;
100+ } ;
101+
96102 const asyncMiddleware : koa . Middleware = async ( ctx , next ) => {
97103 const start = Date . now ( ) ;
98104 await next ( ) ;
@@ -106,11 +112,12 @@ describe('Koa Instrumentation - Core Tests', () => {
106112 app . use ( ( ctx , next ) => tracer . withSpan ( rootSpan , next ) ) ;
107113 app . use ( customMiddleware ) ;
108114 app . use ( simpleResponse ) ;
115+ app . use ( spanCreateMiddleware ) ;
109116
110117 await tracer . withSpan ( rootSpan , async ( ) => {
111118 await httpRequest . get ( `http://localhost:${ port } ` ) ;
112119 rootSpan . end ( ) ;
113- assert . deepStrictEqual ( memoryExporter . getFinishedSpans ( ) . length , 5 ) ;
120+ assert . deepStrictEqual ( memoryExporter . getFinishedSpans ( ) . length , 8 ) ;
114121
115122 assert . notStrictEqual (
116123 memoryExporter
@@ -119,6 +126,18 @@ describe('Koa Instrumentation - Core Tests', () => {
119126 undefined
120127 ) ;
121128
129+ const fooParentSpan = memoryExporter
130+ . getFinishedSpans ( )
131+ . find ( span => span . name . includes ( 'spanCreateMiddleware' ) ) ;
132+ assert . notStrictEqual ( fooParentSpan , undefined ) ;
133+
134+ const fooSpan = memoryExporter . getFinishedSpans ( ) . find ( span => 'foo' ) ;
135+ assert . notStrictEqual ( fooSpan , undefined ) ;
136+ assert . strictEqual (
137+ fooSpan ! . parentSpanId ,
138+ fooParentSpan ! . spanContext . spanId
139+ ) ;
140+
122141 const simpleResponseSpan = memoryExporter
123142 . getFinishedSpans ( )
124143 . find ( span => span . name . includes ( 'simpleResponse' ) ) ;
0 commit comments