Node with Koa post body not collected

We’re using Sentry on a Koa application on node.
I’ve just realised it’s not collecting the body of POST/PATCH/PUT requests.
In fact the breadcrumbs section only contains the exception and that’s it.

How would we go about fixing this so that more useful data is collected?

@chrisjensen, could you please provide smallest possible reproducible case?

We parse requests body for all type of requests:


Thanks, the code you shared helped me figure it out.

We’re not using app.on, but catching the error in a middleware finally block.
Here’s the code with the line that fixed the capture of request details

function* errors(next) {
  try {
    yield next;
  } finally {
			Raven.captureException(
				err,
				{
					level,
					user,
					// **** This is the line that fixed it *****/
					req: this.request,
				},
				(sendErr, eventId) => {
					if (sendErr) {
						console.error('Failed to send captured exception to Sentry', err);
					}
				}
			);
       }

app.use(errors);

Actually, this still doesn’t completely give the right results. I played around with which property and request object to use. I found that Sentry would complain about an invalid attribute and would not capture the body in some cases.
None of these was a perfect solution. Here’s the outcome I found depending on which one I uncomment:

Raven.captureException(
  err,
  // req: this.request, // Sentry captures body, but flags this as an invalid attribute
  // request: this.req, // No body, no invalid attribute error
  // req: this.req, //No body, no invalid attribute error
  // request: this.request, //No body, no invalid attribute error
);

req: this.request yielded the best result, just has an irritating message saying it’s invalid.
This also results in the url that is captured is not quite right, it’s good enough for debugging though.

Would you be able to provide the smallest possible repro-case for this issue?
Also feel free to open an issue on GitHub, as it sounds like a bug (we have to confirm it first).

I’ve opened a bug on github, which links to a gist with minimum reproducable case.
https://github.com/getsentry/raven-node/issues/375

Thanks, I’ll investigate it. Let’s keep the conversation in there.