@@ -144,6 +144,11 @@ describe('Koa Instrumentation', function () {
144
144
throw new Error ( 'I failed!' ) ;
145
145
} ;
146
146
147
+ const generatorMiddleware : ( ) => koa . Middleware = ( ) =>
148
+ function * generatorMiddleware ( next ) {
149
+ yield next ;
150
+ } ;
151
+
147
152
describe ( 'Instrumenting @koa/router calls' , function ( ) {
148
153
before ( function ( ) {
149
154
if ( ! isrouterCompat ) {
@@ -497,6 +502,39 @@ describe('Koa Instrumentation', function () {
497
502
) ;
498
503
} ) ;
499
504
505
+ it ( 'should not instrument generator middleware functions' , async function ( ) {
506
+ if ( typeof ( app as any ) . createAsyncCtxStorageMiddleware !== 'function' ) {
507
+ this . skip ( )
508
+ }
509
+
510
+ const rootSpan = tracer . startSpan ( 'rootSpan' ) ;
511
+ app . use ( ( _ctx , next ) =>
512
+ context . with ( trace . setSpan ( context . active ( ) , rootSpan ) , next )
513
+ ) ;
514
+
515
+ app . use ( generatorMiddleware ( ) ) ;
516
+ app . use ( simpleResponse ( ) ) ;
517
+
518
+ await context . with (
519
+ trace . setSpan ( context . active ( ) , rootSpan ) ,
520
+ async ( ) => {
521
+ await httpRequest . get ( `http://localhost:${ port } ` ) ;
522
+ rootSpan . end ( ) ;
523
+ assert . deepStrictEqual ( memoryExporter . getFinishedSpans ( ) . length , 2 ) ;
524
+
525
+ const simpleResponseSpan = memoryExporter
526
+ . getFinishedSpans ( )
527
+ . find ( span => span . name . includes ( 'simpleResponse' ) ) ;
528
+ assert . notStrictEqual ( simpleResponseSpan , undefined ) ;
529
+
530
+ const exportedRootSpan = memoryExporter
531
+ . getFinishedSpans ( )
532
+ . find ( span => span . name === 'rootSpan' ) ;
533
+ assert . notStrictEqual ( exportedRootSpan , undefined ) ;
534
+ }
535
+ ) ;
536
+ } ) ;
537
+
500
538
it ( 'should not instrument the same middleware more than once' , async ( ) => {
501
539
const sameAsyncMiddleware = asyncMiddleware ( ) ;
502
540
0 commit comments