-
Notifications
You must be signed in to change notification settings - Fork 233
Description
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