Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious: does this.skip() not work in async test functions?

Copy link
Member

@pichlermarc pichlermarc Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.skip() does unfortunately not work when using a lambda function. I've started using

it('does thing', function() {
...
});

in all new tests for that reason. Unfortunately we lambdas it across all tests in both repos, so it'd be very difficult to change it everywhere.

await testUtils.runTestFixture({
cwd: __dirname,
argv: ['fixtures/use-koa.mjs'],
Expand Down