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 e98c7d6ef5..967e76375b 100644 --- a/plugins/node/opentelemetry-instrumentation-koa/test/fixtures/use-koa.mjs +++ b/plugins/node/opentelemetry-instrumentation-koa/test/fixtures/use-koa.mjs @@ -17,6 +17,7 @@ // Use koa from an ES module: // node --experimental-loader=@opentelemetry/instrumentation/hook.mjs use-koa.mjs +import { promisify } from 'util'; import { createTestNodeSdk } from '@opentelemetry/contrib-test-utils'; import { HttpInstrumentation } from '@opentelemetry/instrumentation-http'; @@ -38,6 +39,11 @@ import * as http from 'http'; const app = new Koa(); app.use(async function simpleMiddleware(ctx, next) { + // Wait a short delay to ensure this "middleware - ..." span clearly starts + // before the "router - ..." span. The test rely on a start-time-based sort + // of the produced spans. If they start in the same millisecond, then tests + // can be flaky. + await promisify(setTimeout)(10); 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 c3916114de..8b38513a70 100644 --- a/plugins/node/opentelemetry-instrumentation-koa/test/koa.test.ts +++ b/plugins/node/opentelemetry-instrumentation-koa/test/koa.test.ts @@ -728,7 +728,7 @@ describe('Koa Instrumentation', () => { // 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 'middleware - simpleMiddleware' // `- span 'router - /post/:id' const spans = collector.sortedSpans; assert.strictEqual(spans[0].name, 'GET /post/:id');