getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
7.97k stars 1.57k forks source link

Mixing express `requestHandler` with `captureException`. #4152

Closed kochis closed 2 years ago

kochis commented 2 years ago

Package + Version

Version:

6.2.4

Description

We're using the sentry express handler in our code, which is working as expected for uncaught exceptions.

const { Sentry } = require('./sentryClient');
app.use(Sentry.Handlers.requestHandler());
// route definitions 
app.use(Sentry.Handlers.errorHandler());

However, when making one-off calls to captureException elsewhere in the codebase:

const { Sentry } = require('./sentryClient'); // same client in both cases
try {
  // some code
} catch (err) {
  Sentry.captureException(err);
}

we notice those exceptions generally have scope info from other requests attached.

Is it expected that calls to captureException outside of the middleware handler should be decorated with the same the scope info as those handled by the middleware? Should we be passing (or clearing) the scope when calling into captureException?

Can definitely provide more details, and a way to reproduce if needed, but just wanted to first check if there was something obvious we should be doing here.

github-actions[bot] commented 2 years ago

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀