@sentry/browser
@sentry/node
raven-js
raven-node
_(raven for node)_4.2.1
When using @sentry/browser
with Koa (as described at https://sentry.io/for/koa/) tracked error don't include any information about node. Issues only include tags for level
and transaction
. I expected to see the context runtime
attributes and some from os
and device
.
@jansauer we are still missing some docs on Koa (I'll add them soon). In the meantime, can you test it out locally?
app.on('error', (err, ctx) => {
Sentry.withScope(scope => {
scope.addEventProcessor(async (event) => parseRequest(event, ctx.request))
Sentry.captureException(err);
});
});
You can also see how parsing is implemented here https://github.com/getsentry/sentry-javascript/blob/414647c57da47570fece1b907ae9747320331f8d/packages/node/src/handlers.ts#L148-L212 as Koa may use some other attributes than express (although afair, it's mostly consistent).
(requires version 4.2.2, as we exported helper function there to make it easier for developers).
@kamilogorek 馃憤 Works perfectly.
Just had to adopt the parseRequest
call and update to the new version.
if(process.env.SENTRY_URL) {
app.on('error', (err, ctx) => {
Sentry.withScope(scope => {
scope.addEventProcessor(async (event) => Sentry.Handlers.parseRequest(event, ctx.request))
Sentry.captureException(err);
});
});
}
Hi @kamilogorek ,
With your approach, only errors from Koa app will have the request context attached. Any other captureMessage
/captureError
/captureEvent
calls internally would not have the context.
I came up with something that mimics the Express middleware behavior. Could you help to double check whether everything make sense?
async function sentryRequestHandler(ctx: Koa.Context, next: () => Promise<any>) {
const hub = Sentry.getCurrentHub();
const scope = hub.pushScope();
scope.addEventProcessor(async (event, hint) => parseRequest(event, ctx.request));
try {
await next();
} finally {
hub.popScope();
}
}
I couldn't use withScope
since next
need to be await on.
@gregwym this should work just fine, although I'm not sure about Koa's internals tbh.
I'd try to create a very barebone app with this handler and try to send some requests to make sure it preserves correct order of push/pop scope calls when async await
is introduced.
@gregwym did your solution work with context on breadcrumbs? I'm trying it out...
Update: haven't gotten this to work. So confused right now.
@vpontis yes it works for BREADCRUMBS.
For most of the times, our Sentry captures the correct request context. There are like 1% of requests' context are miss matched, tho I have not figure out what's the pattern yet.
@gregwym I'm getting an issue where I'm seeing the breadcrumbs for all requests that are happening on the server, not only the breadcrumbs for the request that threw the error.
Does your code snippet fix that problem for you?
(I tried it and it didn't work, but it's possible I did something wrong...)
@vpontis our breadcrumbs includes few lines of log from the system bootstrap at the beginning, then the rest are request context related.
Most helpful comment
Hi @kamilogorek ,
With your approach, only errors from Koa app will have the request context attached. Any other
captureMessage
/captureError
/captureEvent
calls internally would not have the context.I came up with something that mimics the Express middleware behavior. Could you help to double check whether everything make sense?
I couldn't use
withScope
sincenext
need to be await on.