Repository navigation
Request sessions count errors dropped by ignoreErrors or beforeSend #25605
Description
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/node
SDK Version
11.8.0
Framework Version
Express 5.1.0, Node v25.8.0
Link to Sentry event
n/a, local repro
Reproduction Example/SDK Setup
// node repro.mjs <none|handled|ignoreErrors|beforeSend|express-ignoreErrors>
import http from 'node:http';
import zlib from 'node:zlib';
const scenario = process.argv[2];
const sessions = [];
const events = [];
const sink = http.createServer((req, res) => {
const chunks = [];
req.on('data', (c) => chunks.push(c));
req.on('end', () => {
let body = Buffer.concat(chunks);
if (req.headers['content-encoding'] === 'gzip') body = zlib.gunzipSync(body);
const lines = body.toString().split('\n');
for (let i = 1; i < lines.length; i += 2) {
try {
const type = JSON.parse(lines[i]).type;
if (type === 'sessions') sessions.push(...JSON.parse(lines[i + 1]).aggregates);
if (type === 'event') events.push(type);
} catch {}
}
res.end('{}');
});
});
await new Promise((r) => sink.listen(0, '127.0.0.1', r));
const Sentry = await import('@sentry/node');
Sentry.init({
dsn: `http://key@127.0.0.1:${sink.address().port}/1`,
release: 'demo@1.0.0',
...(scenario === 'ignoreErrors' || scenario === 'express-ignoreErrors' ? { ignoreErrors: ['ExpectedError'] } : {}),
...(scenario === 'beforeSend' ? { beforeSend: () => null } : {}),
});
const express = (await import('express')).default;
const app = express();
app.get('/', (req, res) => {
if (scenario === 'ignoreErrors' || scenario === 'beforeSend') Sentry.captureException(new Error('ExpectedError: not a real problem'));
if (scenario === 'handled') Sentry.captureException(new Error('real problem'));
if (scenario === 'express-ignoreErrors') throw new Error('ExpectedError: not a real problem');
res.send('ok');
});
Sentry.setupExpressErrorHandler(app);
app.use((err, req, res, next) => res.status(500).send('error'));
const server = app.listen(0, '127.0.0.1');
await new Promise((r) => server.once('listening', r));
await fetch(`http://127.0.0.1:${server.address().port}/`).then((r) => r.text());
await Sentry.flush(2000);
await new Promise((r) => setTimeout(r, 300));
const agg = sessions.reduce((a, s) => ({ exited: a.exited + (s.exited || 0), errored: a.errored + (s.errored || 0), crashed: a.crashed + (s.crashed || 0) }), { exited: 0, errored: 0, crashed: 0 });
console.log(`${scenario.padEnd(22)} events sent: ${events.length} request session: ${JSON.stringify(agg)}`);
server.close(); sink.close();
process.exit(0);Steps to Reproduce
npm i @sentry/node express, then node repro.mjs <scenario> for each scenario.
Expected Result
Errors dropped by ignoreErrors or beforeSend shouldn't touch the request session, per the sessions spec.
Actual Result
none events sent: 0 request session: {"exited":1,"errored":0,"crashed":0}
handled events sent: 1 request session: {"exited":0,"errored":1,"crashed":0}
ignoreErrors events sent: 0 request session: {"exited":0,"errored":1,"crashed":0}
beforeSend events sent: 0 request session: {"exited":0,"errored":1,"crashed":0}
express-ignoreErrors events sent: 0 request session: {"exited":0,"errored":0,"crashed":1}
No event goes out, but the session is still marked errored (or crashed, for an ignored error thrown in an Express route).
Additional Context
captureException / captureEvent in server-runtime-client.ts mark the request session before event processors and beforeSend run. #22671 fixed this ordering for the client session but not for request sessions. Moving the update later probably isn't enough by itself though, since the request session is recorded when the response closes and async processors like ContextLines can finish after that.
Metadata
Metadata
Assignees
Projects
- StatusShow more project fieldsNo status
Activity
linear-code commentedon Oct 21, 2026
JS-3979
s1gr1d commentedon Oct 21, 2026
Hi and thanks for writing in!
This is going to be fixed with this PR: #25632