From d227040c4fb4dc99d95794ab0a1a0c4b57d094e4 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Tue, 6 May 2025 16:24:33 +0200 Subject: [PATCH] fix(node): Fix 404 route handling in express 5 --- .../suites/express-v5/tracing/test.ts | 5 +---- .../src/integrations/tracing/express-v5/instrumentation.ts | 6 ++++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/dev-packages/node-integration-tests/suites/express-v5/tracing/test.ts b/dev-packages/node-integration-tests/suites/express-v5/tracing/test.ts index e5e8097564f8..0b76192b6113 100644 --- a/dev-packages/node-integration-tests/suites/express-v5/tracing/test.ts +++ b/dev-packages/node-integration-tests/suites/express-v5/tracing/test.ts @@ -93,8 +93,7 @@ describe('express v5 tracing', () => { const runner = createRunner() .expect({ transaction: { - // FIXME: This is wrong :( - transaction: 'GET /', + transaction: 'GET /does-not-exist', contexts: { trace: { span_id: expect.stringMatching(/[a-f0-9]{16}/), @@ -103,8 +102,6 @@ describe('express v5 tracing', () => { 'http.response.status_code': 404, url: expect.stringMatching(/\/does-not-exist$/), 'http.method': 'GET', - // FIXME: This is wrong :( - 'http.route': '/', 'http.url': expect.stringMatching(/\/does-not-exist$/), 'http.target': '/does-not-exist', }, diff --git a/packages/node/src/integrations/tracing/express-v5/instrumentation.ts b/packages/node/src/integrations/tracing/express-v5/instrumentation.ts index c6070550c996..bc810341db35 100644 --- a/packages/node/src/integrations/tracing/express-v5/instrumentation.ts +++ b/packages/node/src/integrations/tracing/express-v5/instrumentation.ts @@ -164,16 +164,18 @@ export class ExpressInstrumentationV5 extends InstrumentationBase 0 ? route : undefined; + const attributes: Attributes = { // eslint-disable-next-line deprecation/deprecation - [SEMATTRS_HTTP_ROUTE]: route.length > 0 ? route : '/', + [SEMATTRS_HTTP_ROUTE]: actualRoute, }; const metadata = getLayerMetadata(route, layer, layerPath); const type = metadata.attributes[AttributeNames.EXPRESS_TYPE] as ExpressLayerType; const rpcMetadata = getRPCMetadata(context.active()); if (rpcMetadata?.type === RPCType.HTTP) { - rpcMetadata.route = route || '/'; + rpcMetadata.route = actualRoute; } // verify against the config if the layer should be ignored