Repository navigation
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?
Self-hosted/on-premise
Which SDK are you using?
@sentry/node
SDK Version
11.11.0
Framework Version
Express 5.3
Link to Sentry event
No response
Reproduction Example/SDK Setup
Sentry.init({
dsn: '...',
tracesSampleRate: 0, // same result with 0.1 and 1
enableRuntimeChannelInjection: true,
traceLifecycle: 'static',
dataCollection: { databaseQueryData: false },
});(Sentry is initialised before mongoose/mongodb are loaded.)
Steps to Reproduce
- Init Sentry as above, with tracesSampleRate: 0.
- With mongoose (or the mongodb driver), run bulkWrite / updateOne commands whose update documents are several MB each (deeply nested objects), 5 in parallel, in a loop.
- Sample process.memoryUsage().rss and take a CPU profile (--cpu-prof).
- Repeat with integrations: (d) => d.filter((i) => i.name !== 'Mongo').
Expected Result
With tracesSampleRate: 0 (no span can be recorded) and dataCollection.databaseQueryData: false, the Mongo integration should not serialize the command. Memory and CPU should stay close to running without Sentry.
Actual Result
The Mongo integration serializes every MongoDB command, even when the span will not be recorded.
In @sentry/server-utils integrations/mongodb, subscribeV4Command calls getV4SpanAttributes() on every Connection.command. That calls serializeDbStatement(), which runs scrubStatement() over the whole command and then JSON.stringify. This happens before startInactiveSpan({ onlyIfParent: true }), so the work is done even when there is no sampled parent span and the span is dropped. It also ignores dataCollection.databaseQueryData: false.
scrubStatement rebuilds the whole command as Object.entries/map/reduce arrays. On update/bulkWrite commands carrying multi-megabyte documents, each command allocates several copies of its payload.
Measured on a job that bulk-writes multi-MB documents, 5 in parallel (Node 26.13):
| Setup | Peak RSS | Time per round |
|---|---|---|
| Sentry off | 1283 MB | 6.5 s |
| Sentry 11, tracesSampleRate 0 | 3623 MB | 15.7 s |
| Sentry 11, tracesSampleRate 0.1 | 2537 MB | 15.6 s |
| Sentry 11 without the Mongo integration | 1200 MB | 6.5 s |
| Sentry 10.53 (OTel mongodb instrumentation), tracesSampleRate 1 | ~1.1 GB | — |
CPU profile with tracesSampleRate 0: 51% of the time is in scrubStatement (mongodb-span.js), plus 11% in GC.
Additional Context
Same on Node 22 and Node 26, so it isn't the runtime. In production the containers crashed with "Fatal process out of memory" while the JS heap was only 200–300 MB.
Priority
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it.
Metadata
Metadata
Assignees
Projects
- StatusShow more project fieldsNo status
Activity
linear-code commentedon Nov 24, 2026
JS-4151
JPeer264 commentedon Nov 24, 2026
Thanks a lot for writing in. First off, there is a difference between setting
tracesSampleRate: 0and not setting it at all as setting it to 0 enables tracing, but just doesn't send anything. I'm quite surprised by the memory consumption between v10 and v11 of the SDK though, that should be checked out too. I'll check out if we can improve performance and memory allocation there.JPeer264 commentedon Nov 24, 2026
I did some further benchmarks between v10 and v11, and it seems the regression is already fixed with the opened PR
fix(server-utils): Skip MongoDB statement serialization when the span…
github-actions commentedon Nov 25, 2026
A PR closing this issue has just been released 🚀
This issue was referenced by PR #26826, which was included in the 11.18.0 release.