Skip to content

Commit 006539c

Browse files
committed
consider regex route paths
1 parent 1df9019 commit 006539c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

plugins/node/opentelemetry-instrumentation-express/src/utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,16 @@ export function getActualMatchedRoute(req: {
266266
return constructedRoute;
267267
}
268268

269+
// For RegExp routes or route arrays, return the constructed route
270+
// This handles the case where the route is defined using RegExp or an array
271+
if (constructedRoute.includes('/') &&
272+
(constructedRoute.includes(',') ||
273+
constructedRoute.includes('\\') ||
274+
constructedRoute.includes('*') ||
275+
constructedRoute.includes('['))) {
276+
return constructedRoute;
277+
}
278+
269279
// Ensure route starts with '/' if it doesn't already
270280
const normalizedRoute = constructedRoute.startsWith('/')
271281
? constructedRoute

plugins/node/opentelemetry-instrumentation-express/test/express.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ describe('ExpressInstrumentation', () => {
103103

104104
for (const span of spans) {
105105
assert.strictEqual(
106-
span.attributes[SEMATTRS_HTTP_ROUTE],
106+
span.attributes[ATTR_HTTP_ROUTE],
107107
undefined, // none of the spans have the HTTP route attribute
108108
`Span "${span.name}" should not have HTTP route attribute for non-existing route`
109109
);

0 commit comments

Comments
 (0)