diff --git a/plugins/node/opentelemetry-plugin-express/src/express.ts b/plugins/node/opentelemetry-plugin-express/src/express.ts index 3fc106363b..d5d66cefd3 100644 --- a/plugins/node/opentelemetry-plugin-express/src/express.ts +++ b/plugins/node/opentelemetry-plugin-express/src/express.ts @@ -187,6 +187,16 @@ export class ExpressPlugin extends BasePlugin { if (plugin._tracer.getCurrentSpan() === undefined) { return original.apply(this, arguments); } + // Rename the root http span once we reach the request handler + if ( + metadata.attributes[AttributeNames.EXPRESS_TYPE] === + ExpressLayerType.REQUEST_HANDLER + ) { + const parent = plugin._tracer.getCurrentSpan(); + if (parent) { + parent.updateName(`${req.method} ${route}`); + } + } const span = plugin._tracer.startSpan(metadata.name, { attributes: Object.assign(attributes, metadata.attributes), }); diff --git a/plugins/node/opentelemetry-plugin-express/test/express.test.ts b/plugins/node/opentelemetry-plugin-express/test/express.test.ts index a1004a7d55..81f4d3259c 100644 --- a/plugins/node/opentelemetry-plugin-express/test/express.test.ts +++ b/plugins/node/opentelemetry-plugin-express/test/express.test.ts @@ -132,7 +132,7 @@ describe('Express Plugin', () => { ); const exportedRootSpan = memoryExporter .getFinishedSpans() - .find(span => span.name === 'rootSpan'); + .find(span => span.name === 'GET /toto/:id'); assert.notStrictEqual(exportedRootSpan, undefined); }); server.close();