diff --git a/package-lock.json b/package-lock.json index a93f49d078..d444c7c8fe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -35217,6 +35217,7 @@ "@opentelemetry/api": "^1.3.0", "@opentelemetry/context-async-hooks": "^1.8.0", "@opentelemetry/contrib-test-utils": "^0.35.0", + "@opentelemetry/instrumentation-http": "^0.45.1", "@opentelemetry/sdk-trace-base": "^1.8.0", "@opentelemetry/sdk-trace-node": "^1.8.0", "@types/mocha": "7.0.2", @@ -43713,6 +43714,7 @@ "@opentelemetry/contrib-test-utils": "^0.35.0", "@opentelemetry/core": "^1.8.0", "@opentelemetry/instrumentation": "^0.45.1", + "@opentelemetry/instrumentation-http": "^0.45.1", "@opentelemetry/sdk-trace-base": "^1.8.0", "@opentelemetry/sdk-trace-node": "^1.8.0", "@opentelemetry/semantic-conventions": "^1.0.0", diff --git a/plugins/node/opentelemetry-instrumentation-koa/package.json b/plugins/node/opentelemetry-instrumentation-koa/package.json index 7c5d9ca62a..ae327ebb13 100644 --- a/plugins/node/opentelemetry-instrumentation-koa/package.json +++ b/plugins/node/opentelemetry-instrumentation-koa/package.json @@ -50,6 +50,7 @@ "@opentelemetry/api": "^1.3.0", "@opentelemetry/context-async-hooks": "^1.8.0", "@opentelemetry/contrib-test-utils": "^0.35.0", + "@opentelemetry/instrumentation-http": "^0.45.1", "@opentelemetry/sdk-trace-base": "^1.8.0", "@opentelemetry/sdk-trace-node": "^1.8.0", "@types/mocha": "7.0.2", diff --git a/plugins/node/opentelemetry-instrumentation-koa/test/fixtures/use-koa.mjs b/plugins/node/opentelemetry-instrumentation-koa/test/fixtures/use-koa.mjs index 361f2bbeb5..e98c7d6ef5 100644 --- a/plugins/node/opentelemetry-instrumentation-koa/test/fixtures/use-koa.mjs +++ b/plugins/node/opentelemetry-instrumentation-koa/test/fixtures/use-koa.mjs @@ -19,12 +19,14 @@ import { createTestNodeSdk } from '@opentelemetry/contrib-test-utils'; +import { HttpInstrumentation } from '@opentelemetry/instrumentation-http'; import { KoaInstrumentation } from '../../build/src/index.js'; const sdk = createTestNodeSdk({ serviceName: 'use-koa', instrumentations: [ - new KoaInstrumentation() + new KoaInstrumentation(), + new HttpInstrumentation() ] }) sdk.start(); @@ -35,7 +37,7 @@ import * as http from 'http'; const app = new Koa(); -app.use(async function simpleResponse(ctx, next) { +app.use(async function simpleMiddleware(ctx, next) { await next(); }); diff --git a/plugins/node/opentelemetry-instrumentation-koa/test/koa.test.ts b/plugins/node/opentelemetry-instrumentation-koa/test/koa.test.ts index e2c3d4edf7..c3916114de 100644 --- a/plugins/node/opentelemetry-instrumentation-koa/test/koa.test.ts +++ b/plugins/node/opentelemetry-instrumentation-koa/test/koa.test.ts @@ -15,7 +15,7 @@ */ import * as KoaRouter from '@koa/router'; -import { context, trace, Span } from '@opentelemetry/api'; +import { context, trace, Span, SpanKind } from '@opentelemetry/api'; import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node'; import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks'; import * as testUtils from '@opentelemetry/contrib-test-utils'; @@ -724,11 +724,21 @@ describe('Koa Instrumentation', () => { assert.ifError(err); }, checkCollector: (collector: testUtils.TestCollector) => { + // use-koa.mjs creates a Koa app with a 'GET /post/:id' endpoint and + // a `simpleMiddleware`, then makes a single 'GET /post/0' request. We + // expect to see spans like this: + // span 'GET /post/:id' + // `- span 'middleware - simpleResponse' + // `- span 'router - /post/:id' const spans = collector.sortedSpans; - - console.log(JSON.stringify(spans, null, 2)); - - // TODO + assert.strictEqual(spans[0].name, 'GET /post/:id'); + assert.strictEqual(spans[0].kind, SpanKind.CLIENT); + assert.strictEqual(spans[1].name, 'middleware - simpleMiddleware'); + assert.strictEqual(spans[1].kind, SpanKind.SERVER); + assert.strictEqual(spans[1].parentSpanId, spans[0].spanId); + assert.strictEqual(spans[2].name, 'router - /post/:id'); + assert.strictEqual(spans[2].kind, SpanKind.SERVER); + assert.strictEqual(spans[2].parentSpanId, spans[1].spanId); }, }); });