From 1314d5b27e595f4ce4a361b56e49fa123a936612 Mon Sep 17 00:00:00 2001 From: Onur Temizkan Date: Thu, 25 Jul 2024 17:06:28 +0100 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Abhijeet Prasad --- .../src/utils.ts | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/plugins/node/opentelemetry-instrumentation-express/src/utils.ts b/plugins/node/opentelemetry-instrumentation-express/src/utils.ts index da6949cb66..5bbee5fbd8 100644 --- a/plugins/node/opentelemetry-instrumentation-express/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-express/src/utils.ts @@ -54,9 +54,11 @@ export const getRouterPath = (path: string, layer: ExpressLayer): string => { const stackLayer = layer.handle?.stack[0]; if (stackLayer.route?.path) { - path += stackLayer.route.path; - } else if (stackLayer.handle?.stack) { - path = getRouterPath(path, stackLayer); + return `${path}${stackLayer.route.path}`; + } + + if (stackLayer.handle?.stack) { + return getRouterPath(path, stackLayer); } return path; @@ -77,15 +79,8 @@ export const getLayerMetadata = ( name: string; } => { if (layer.name === 'router') { - let extractedRouterPath = ''; - - if (layer.handle?.stack) { - extractedRouterPath = getRouterPath(extractedRouterPath, layer); - } - - if (!extractedRouterPath) { - extractedRouterPath = layerPath || route || '/'; - } + const maybeRouterPath = getRouterPath('', layer); + const extractedRouterPath = maybeRouterPath ? maybeRouterPath : layerPath || route || '/'; return { attributes: {