Skip to content

Commit e0c0d9d

Browse files
authored
fix(node): Fix 404 route handling in express 5 (#16211)
Closes #16210
1 parent b74f300 commit e0c0d9d

File tree

2 files changed

+5
-6
lines changed
  • dev-packages/node-integration-tests/suites/express-v5/tracing
  • packages/node/src/integrations/tracing/express-v5

2 files changed

+5
-6
lines changed

dev-packages/node-integration-tests/suites/express-v5/tracing/test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ describe('express v5 tracing', () => {
9393
const runner = createRunner()
9494
.expect({
9595
transaction: {
96-
// FIXME: This is wrong :(
97-
transaction: 'GET /',
96+
transaction: 'GET /does-not-exist',
9897
contexts: {
9998
trace: {
10099
span_id: expect.stringMatching(/[a-f0-9]{16}/),
@@ -103,8 +102,6 @@ describe('express v5 tracing', () => {
103102
'http.response.status_code': 404,
104103
url: expect.stringMatching(/\/does-not-exist$/),
105104
'http.method': 'GET',
106-
// FIXME: This is wrong :(
107-
'http.route': '/',
108105
'http.url': expect.stringMatching(/\/does-not-exist$/),
109106
'http.target': '/does-not-exist',
110107
},

packages/node/src/integrations/tracing/express-v5/instrumentation.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,18 @@ export class ExpressInstrumentationV5 extends InstrumentationBase<ExpressInstrum
164164
// remove duplicate slashes to normalize route
165165
.replace(/\/{2,}/g, '/');
166166

167+
const actualRoute = route.length > 0 ? route : undefined;
168+
167169
const attributes: Attributes = {
168170
// eslint-disable-next-line deprecation/deprecation
169-
[SEMATTRS_HTTP_ROUTE]: route.length > 0 ? route : '/',
171+
[SEMATTRS_HTTP_ROUTE]: actualRoute,
170172
};
171173
const metadata = getLayerMetadata(route, layer, layerPath);
172174
const type = metadata.attributes[AttributeNames.EXPRESS_TYPE] as ExpressLayerType;
173175

174176
const rpcMetadata = getRPCMetadata(context.active());
175177
if (rpcMetadata?.type === RPCType.HTTP) {
176-
rpcMetadata.route = route || '/';
178+
rpcMetadata.route = actualRoute;
177179
}
178180

179181
// verify against the config if the layer should be ignored

0 commit comments

Comments
 (0)