Skip to content

Commit

Permalink
feat: reduce root span cardinality in express plugin
Browse files Browse the repository at this point in the history
Signed-off-by: George Gooden <george@gecgooden.com>
  • Loading branch information
gecgooden committed Aug 19, 2020
1 parent 58cd219 commit 7b82ec1
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 @@ -130,7 +130,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 7b82ec1

Please sign in to comment.