Skip to content

Commit

Permalink
chore(instr-koa): update instrumentation-koa tests (#2566)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-luna authored Dec 2, 2024
1 parent 97ebd4f commit bf8117e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
2 changes: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions plugins/node/opentelemetry-instrumentation-koa/.tav.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
30 changes: 25 additions & 5 deletions plugins/node/opentelemetry-instrumentation-koa/test/koa.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand All @@ -77,7 +84,7 @@ describe('Koa Instrumentation', () => {
let server: http.Server;
let port: number;

before(() => {
before(function () {
plugin.enable();
});

Expand Down Expand Up @@ -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 };
Expand Down Expand Up @@ -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 };
Expand Down Expand Up @@ -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'],
Expand Down

0 comments on commit bf8117e

Please sign in to comment.