Skip to content

Commit bf8117e

Browse files
authored
chore(instr-koa): update instrumentation-koa tests (open-telemetry#2566)
1 parent 97ebd4f commit bf8117e

File tree

4 files changed

+38
-9
lines changed

4 files changed

+38
-9
lines changed

package-lock.json

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/node/opentelemetry-instrumentation-koa/.tav.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
"@koa/router":
2-
versions:
3-
include: ">=8.0.0"
4-
mode: latest-minors
5-
commands: npm run test
2+
jobs:
3+
- versions:
4+
include: ">=8.0.0 <13"
5+
mode: latest-minors
6+
commands: npm run test
7+
- versions:
8+
include: ">=13 <14"
9+
mode: latest-minors
10+
node: '>=18'
11+
commands: npm run test
612

713
koa:
814
# Testing ^2.7.0 covers at least 97% of the downloaded koa versions

plugins/node/opentelemetry-instrumentation-koa/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"koa": "2.13.1",
6161
"nyc": "15.1.0",
6262
"rimraf": "5.0.10",
63+
"semver": "7.6.3",
6364
"sinon": "15.2.0",
6465
"test-all-versions": "6.1.0",
6566
"typescript": "4.4.4"

plugins/node/opentelemetry-instrumentation-koa/test/koa.test.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import * as assert from 'assert';
4141
import * as koa from 'koa';
4242
import * as http from 'http';
4343
import * as sinon from 'sinon';
44+
import * as semver from 'semver';
4445
import { AddressInfo } from 'net';
4546
import { KoaLayerType, KoaRequestInfo } from '../src/types';
4647
import { 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

Comments
 (0)