@@ -41,6 +41,7 @@ import * as assert from 'assert';
41
41
import * as koa from 'koa' ;
42
42
import * as http from 'http' ;
43
43
import * as sinon from 'sinon' ;
44
+ import * as semver from 'semver' ;
44
45
import { AddressInfo } from 'net' ;
45
46
import { KoaLayerType , KoaRequestInfo } from '../src/types' ;
46
47
import { AttributeNames } from '../src/enums/AttributeNames' ;
@@ -65,7 +66,13 @@ const httpRequest = {
65
66
} ,
66
67
} ;
67
68
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 ( ) {
69
76
const provider = new NodeTracerProvider ( ) ;
70
77
const memoryExporter = new InMemorySpanExporter ( ) ;
71
78
const spanProcessor = new SimpleSpanProcessor ( memoryExporter ) ;
@@ -77,7 +84,7 @@ describe('Koa Instrumentation', () => {
77
84
let server : http . Server ;
78
85
let port : number ;
79
86
80
- before ( ( ) => {
87
+ before ( function ( ) {
81
88
plugin . enable ( ) ;
82
89
} ) ;
83
90
@@ -141,7 +148,13 @@ describe('Koa Instrumentation', () => {
141
148
yield next ;
142
149
} ;
143
150
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
+
145
158
it ( 'should create a child span for middlewares (string route)' , async ( ) => {
146
159
const rootSpan = tracer . startSpan ( 'rootSpan' ) ;
147
160
const rpcMetadata : RPCMetadata = { type : RPCType . HTTP , span : rootSpan } ;
@@ -585,7 +598,13 @@ describe('Koa Instrumentation', () => {
585
598
} ) ;
586
599
} ) ;
587
600
588
- describe ( 'Using requestHook' , ( ) => {
601
+ describe ( 'Using requestHook' , function ( ) {
602
+ before ( function ( ) {
603
+ if ( ! isrouterCompat ) {
604
+ this . skip ( ) ;
605
+ }
606
+ } ) ;
607
+
589
608
it ( 'should ignore requestHook which throws exception' , async ( ) => {
590
609
const rootSpan = tracer . startSpan ( 'rootSpan' ) ;
591
610
const rpcMetadata = { type : RPCType . HTTP , span : rootSpan } ;
@@ -721,7 +740,8 @@ describe('Koa Instrumentation', () => {
721
740
} ) ;
722
741
} ) ;
723
742
724
- it ( 'should work with ESM usage' , async ( ) => {
743
+ const itFn = isrouterCompat ? it : it . skip ;
744
+ itFn ( 'should work with ESM usage' , async ( ) => {
725
745
await testUtils . runTestFixture ( {
726
746
cwd : __dirname ,
727
747
argv : [ 'fixtures/use-koa.mjs' ] ,
0 commit comments