Skip to content

Commit

Permalink
fix: enable parameterized routes instrumentations without any Express…
Browse files Browse the repository at this point in the history
…LayerType spans
  • Loading branch information
shaiMoria committed Dec 4, 2020
1 parent 5a08fbe commit b5624cc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 5 additions & 2 deletions plugins/node/opentelemetry-plugin-express/src/express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,11 @@ export class ExpressPlugin extends BasePlugin<typeof express> {
ExpressLayerType.REQUEST_HANDLER
) {
const parent = plugin._tracer.getCurrentSpan();
if (parent) {
const parentRoute = parent.name.split(' ')[1];
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
const parentSpanName = parent && parent.name;
if (parent && parentSpanName) {
const parentRoute = parentSpanName.split(' ')[1];
if (!route.includes(parentRoute)) {
parent.updateName(`${req.method} ${route}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ describe('Express Plugin', () => {
await tracer.withSpan(rootSpan, async () => {
await httpRequest.get(`http://localhost:${port}/toto/tata`);
rootSpan.end();
// @ts-ignore
assert.strictEqual(rootSpan.name, 'GET /toto/:id');
assert.notStrictEqual(
memoryExporter
Expand Down Expand Up @@ -240,7 +241,7 @@ describe('Express Plugin', () => {
await tracer.withSpan(rootSpan, async () => {
await httpRequest.get(`http://localhost:${port}/toto/tata`);
rootSpan.end();

// @ts-ignore
assert.strictEqual(rootSpan.name, 'GET /toto/:id');

assert.deepStrictEqual(
Expand Down

0 comments on commit b5624cc

Please sign in to comment.