Skip to content

bug: transaction.setDefaultNameFromRequest relies on instrumentation being loaded #2288

@astorm

Description

@astorm

This issue comes from a discuss forum post.

The following program

const apm = require('elastic-apm-node').start({
    serverUrl: 'http://some-apm-server',
    active: true,
    instrument: false,
    logLevel: 'trace',
});

const Koa = require('koa');
const Router = require('koa-router');

const app = new Koa();
const router = new Router();

router.get('/', (ctx, next) => {
    ctx.body = 'hello world';
});

app
    .use(router.routes())
    .use(router.allowedMethods());

app.listen(3000);

Will produce a transaction name of GET unknown route when handling the root URL, despite that URL having a configured route.

$ curl http://localhost:3000/

We would expect a transaction name of GET /

Root Cause

This bug occurs when the following configuration value is set

    instrument: false

which disables automatic instrumentation.

There's a bug in the setDefaultNameFromRequest method of the transaction object. It uses the getPathFromRequest from the ./express-utils module to fetch a request path if no route property is found. If it can't fetch a request path, it assumes an unknown route.

The getPathFromRequest method relies on our express instrumentation being loaded. Specifically, the agent grabs a path value using the symbols.expressMountStack symbol that our instrumentation sets on the request object.

Additionally, the agent does not reach the setDefaultNameFromRequest code path when the instrumentation configuration value is set to true, as the KOA instrumentation will have already called setDefaultTransactionName.

The setDefaultNameFromRequest (probably?) should not rely on this symbol being set as setDefaultNameFromRequest is part of our generic HTTP instrumentation.

Additional Info: PR where instrument configuration's current behavior landed: #1114

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-nodejsMake available for APM Agents project planning.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions