Skip to content

Commit

Permalink
Merge pull request #176 from gecgooden/express-rename-http-span
Browse files Browse the repository at this point in the history
  • Loading branch information
dyladan authored Oct 30, 2020
2 parents 8ca9f6f + dcf2405 commit 7f96aba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions plugins/node/opentelemetry-plugin-express/src/express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ export class ExpressPlugin extends BasePlugin<typeof express> {
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),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 7f96aba

Please sign in to comment.