diff --git a/package-lock.json b/package-lock.json index 03be175022..f50df50692 100644 --- a/package-lock.json +++ b/package-lock.json @@ -37509,6 +37509,7 @@ "koa": "2.13.1", "nyc": "15.1.0", "rimraf": "5.0.10", + "semver": "7.6.3", "sinon": "15.2.0", "test-all-versions": "6.1.0", "typescript": "4.4.4" @@ -48092,6 +48093,7 @@ "koa": "2.13.1", "nyc": "15.1.0", "rimraf": "5.0.10", + "semver": "7.6.3", "sinon": "15.2.0", "test-all-versions": "6.1.0", "typescript": "4.4.4" diff --git a/plugins/node/opentelemetry-instrumentation-koa/.tav.yml b/plugins/node/opentelemetry-instrumentation-koa/.tav.yml index 973c1fb861..d329351f69 100644 --- a/plugins/node/opentelemetry-instrumentation-koa/.tav.yml +++ b/plugins/node/opentelemetry-instrumentation-koa/.tav.yml @@ -1,8 +1,14 @@ "@koa/router": - versions: - include: ">=8.0.0" - mode: latest-minors - commands: npm run test + jobs: + - versions: + include: ">=8.0.0 <13" + mode: latest-minors + commands: npm run test + - versions: + include: ">=13 <14" + mode: latest-minors + node: '>=18' + commands: npm run test koa: # Testing ^2.7.0 covers at least 97% of the downloaded koa versions diff --git a/plugins/node/opentelemetry-instrumentation-koa/package.json b/plugins/node/opentelemetry-instrumentation-koa/package.json index 1c26caa48d..7a75a46804 100644 --- a/plugins/node/opentelemetry-instrumentation-koa/package.json +++ b/plugins/node/opentelemetry-instrumentation-koa/package.json @@ -60,6 +60,7 @@ "koa": "2.13.1", "nyc": "15.1.0", "rimraf": "5.0.10", + "semver": "7.6.3", "sinon": "15.2.0", "test-all-versions": "6.1.0", "typescript": "4.4.4" diff --git a/plugins/node/opentelemetry-instrumentation-koa/test/koa.test.ts b/plugins/node/opentelemetry-instrumentation-koa/test/koa.test.ts index a40cd033c1..c1b894a026 100644 --- a/plugins/node/opentelemetry-instrumentation-koa/test/koa.test.ts +++ b/plugins/node/opentelemetry-instrumentation-koa/test/koa.test.ts @@ -41,6 +41,7 @@ import * as assert from 'assert'; import * as koa from 'koa'; import * as http from 'http'; import * as sinon from 'sinon'; +import * as semver from 'semver'; import { AddressInfo } from 'net'; import { KoaLayerType, KoaRequestInfo } from '../src/types'; import { AttributeNames } from '../src/enums/AttributeNames'; @@ -65,7 +66,13 @@ const httpRequest = { }, }; -describe('Koa Instrumentation', () => { +const LIB_VERSION = require('@koa/router/package.json').version; +const NODE_VERSION = process.version; +const isrouterCompat = + semver.lt(LIB_VERSION, '13.0.0') || + (semver.gte(LIB_VERSION, '13.0.0') && semver.gte(NODE_VERSION, '18.0.0')); + +describe('Koa Instrumentation', function () { const provider = new NodeTracerProvider(); const memoryExporter = new InMemorySpanExporter(); const spanProcessor = new SimpleSpanProcessor(memoryExporter); @@ -77,7 +84,7 @@ describe('Koa Instrumentation', () => { let server: http.Server; let port: number; - before(() => { + before(function () { plugin.enable(); }); @@ -141,7 +148,13 @@ describe('Koa Instrumentation', () => { yield next; }; - describe('Instrumenting @koa/router calls', () => { + describe('Instrumenting @koa/router calls', function () { + before(function () { + if (!isrouterCompat) { + this.skip(); + } + }); + it('should create a child span for middlewares (string route)', async () => { const rootSpan = tracer.startSpan('rootSpan'); const rpcMetadata: RPCMetadata = { type: RPCType.HTTP, span: rootSpan }; @@ -585,7 +598,13 @@ describe('Koa Instrumentation', () => { }); }); - describe('Using requestHook', () => { + describe('Using requestHook', function () { + before(function () { + if (!isrouterCompat) { + this.skip(); + } + }); + it('should ignore requestHook which throws exception', async () => { const rootSpan = tracer.startSpan('rootSpan'); const rpcMetadata = { type: RPCType.HTTP, span: rootSpan }; @@ -721,7 +740,8 @@ describe('Koa Instrumentation', () => { }); }); - it('should work with ESM usage', async () => { + const itFn = isrouterCompat ? it : it.skip; + itFn('should work with ESM usage', async () => { await testUtils.runTestFixture({ cwd: __dirname, argv: ['fixtures/use-koa.mjs'],