@@ -41,6 +41,7 @@ import * as assert from 'assert';
4141import * as koa from 'koa' ;
4242import * as http from 'http' ;
4343import * as sinon from 'sinon' ;
44+ import * as semver from 'semver' ;
4445import { AddressInfo } from 'net' ;
4546import { KoaLayerType , KoaRequestInfo } from '../src/types' ;
4647import { AttributeNames } from '../src/enums/AttributeNames' ;
@@ -65,7 +66,13 @@ const httpRequest = {
6566 } ,
6667} ;
6768
68- describe ( 'Koa Instrumentation' , ( ) => {
69+ const LIB_VERSION = require ( '@koa/router/package.json' ) . version ;
70+ const NODE_VERSION = process . version ;
71+ const isrouterCompat =
72+ semver . lt ( LIB_VERSION , '13.0.0' ) ||
73+ ( semver . gte ( LIB_VERSION , '13.0.0' ) && semver . gte ( NODE_VERSION , '18.0.0' ) ) ;
74+
75+ describe ( 'Koa Instrumentation' , function ( ) {
6976 const provider = new NodeTracerProvider ( ) ;
7077 const memoryExporter = new InMemorySpanExporter ( ) ;
7178 const spanProcessor = new SimpleSpanProcessor ( memoryExporter ) ;
@@ -77,7 +84,7 @@ describe('Koa Instrumentation', () => {
7784 let server : http . Server ;
7885 let port : number ;
7986
80- before ( ( ) => {
87+ before ( function ( ) {
8188 plugin . enable ( ) ;
8289 } ) ;
8390
@@ -141,7 +148,13 @@ describe('Koa Instrumentation', () => {
141148 yield next ;
142149 } ;
143150
144- describe ( 'Instrumenting @koa/router calls' , ( ) => {
151+ describe ( 'Instrumenting @koa/router calls' , function ( ) {
152+ before ( function ( ) {
153+ if ( ! isrouterCompat ) {
154+ this . skip ( ) ;
155+ }
156+ } ) ;
157+
145158 it ( 'should create a child span for middlewares (string route)' , async ( ) => {
146159 const rootSpan = tracer . startSpan ( 'rootSpan' ) ;
147160 const rpcMetadata : RPCMetadata = { type : RPCType . HTTP , span : rootSpan } ;
@@ -585,7 +598,13 @@ describe('Koa Instrumentation', () => {
585598 } ) ;
586599 } ) ;
587600
588- describe ( 'Using requestHook' , ( ) => {
601+ describe ( 'Using requestHook' , function ( ) {
602+ before ( function ( ) {
603+ if ( ! isrouterCompat ) {
604+ this . skip ( ) ;
605+ }
606+ } ) ;
607+
589608 it ( 'should ignore requestHook which throws exception' , async ( ) => {
590609 const rootSpan = tracer . startSpan ( 'rootSpan' ) ;
591610 const rpcMetadata = { type : RPCType . HTTP , span : rootSpan } ;
@@ -721,7 +740,8 @@ describe('Koa Instrumentation', () => {
721740 } ) ;
722741 } ) ;
723742
724- it ( 'should work with ESM usage' , async ( ) => {
743+ const itFn = isrouterCompat ? it : it . skip ;
744+ itFn ( 'should work with ESM usage' , async ( ) => {
725745 await testUtils . runTestFixture ( {
726746 cwd : __dirname ,
727747 argv : [ 'fixtures/use-koa.mjs' ] ,
0 commit comments