elastic / elastic/apm-agent-nodejs
Koa Instrumentation does not Capture Request Body
- Dominant language
- JavaScript
- Stars
- 594
- Forks
- 244
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 16
Description
Unsure if this is an enhancement request or a bug report, but it looks like our koa instrumentation does _not_ collect the request bodies [as captured by the standard `koa-bodyparser` middleware](https://github.com/koajs/bodyparser). Koa populates `ctx.request.body` with these values, but [we read our request bodies in from the native node `IncomeingMessage/Request` object (i.e. `req.body`)](https://github.com/elastic/apm-agent-nodejs/blob/5303ce58d358f138de1f0c8097029e9e7d220fcb/lib/parsers.js#L140)
You can observe this behavior by running the following small sample program
const Koa = require('koa');
const koaBodyparser = require('koa-bodyparser')
const app = new Koa();
app.use(koaBodyparser())
app.use(async ctx => {
// log the request body
console.log(ctx.request.body)
ctx.body = 'Hello World';
});
const server = app.listen(3000, '0.0.0.0', function(){
console.log(server.address())
});
and posting some form variables.
$ curl -i http://localhost:3000 -d foo=bar
Koa captures the request body, but if you examine the generated transactions, no request body is captured.
Ideally our Koa instrumentation should match our express instrumentation's functionality and capture these values.
Contributor guide
Assessment
This issue has not been assessed yet.