I wanted one small Node service to send errors to Sentry and nothing else. No traces, no spans. So I wrote tracesSampleRate: 0, a line I've put in more than one setup guide, and moved on. Then I pointed the SDK at a stub ingest and logged what came out. Zero is not off.
TL;DR
- With
tracesSampleRate: 0,@sentry/node11.14.0 still created 103 spans for 52 requests, sentclient_reportenvelopes saying it threw them away, and told every downstream servicesampled=false. - A downstream service with
tracesSampleRate: 1sent 0 spans when the caller hadtracesSampleRate: 0. With the key removed from the caller, it sent 102. - Errors-only means deleting
tracesSampleRateandtracesSampler, and checking thatSENTRY_TRACES_SAMPLE_RATEisn't set in your environment.
The lab
Sentry's own docs say it plainly on the Node tracing page: "Setting it to 0 will not disable tracing, it will simply never send any traces to Sentry." I wanted to see what "not disabled" costs on the wire, so I built the smallest thing that shows it.
Versions from run-0-versions.txt (Node, npm, then the two SDK packages):
v24.22.1
11.21.1
@sentry/node 11.14.0
@sentry/core 11.14.0
Three processes on localhost:
-
stub.json :9999 plays Sentry ingest and logs every envelope item type, plus anyclient_report. On :9998 it plays a downstream API and logs thesentry-traceandbaggageheaders it receives. -
app.json :9997 is the service under test. Every request does onefetchto the downstream API, and/boomthrows and callscaptureException. -
load.jsis a separate process that sends 50GET /ok, oneGET /boom, then reads span counters from/stats. That's 52 incoming requests per run.
The only thing that changes between runs is the tracing config:
const opts = { dsn: 'http://devkey@127.0.0.1:9999/1', clientReportFlushInterval: 1000 };
if (MODE === 'zero') opts.tracesSampleRate = 0;
if (MODE === 'rate01') opts.tracesSampleRate = 0.1;
if (MODE === 'rate1') opts.tracesSampleRate = 1;
if (MODE === 'sampler0') opts.tracesSampler = () => 0;
if (MODE === 'unset_noprop') opts.tracePropagationTargets = [];
I set clientReportFlushInterval: 1000 so client reports land inside a short run. The default is 60 seconds, so in production you'd see one report a minute instead of two per run.
Span counts come from the client hooks:
c.on('spanStart', s => { started++; if (s.isRecording()) recording++; });
What each config put on the wire
| Config | Spans started | Recording | Items at ingest | Downstream sentry-trace flag |
|---|---|---|---|---|
| key not set | 0 | 0 | 1 event | none (51 calls) |
tracesSampleRate: 0 |
103 | 0 | 1 event, 2 client_report |
0 on 51 of 51 |
tracesSampler: () => 0 |
103 | 0 | 1 event, 2 client_report |
0 on 51 of 51 |
tracesSampleRate: 0.1 |
103 | 6 | 1 event, 3 span, 2 client_report |
0 on 48, 1 on 3 |
tracesSampleRate: 1 |
103 | 103 | 1 event, 52 span |
1 on 51 of 51 |
103 is two spans per request (the incoming HTTP server span and the outgoing fetch) for 51 requests, plus the server span for /stats. With the key unset, the hook never fired once.
Here is the zero run, run-2-zero.txt:
{"MODE":"zero","spans_started":103,"spans_recording":0,"spans_ended":51,"rss_mb":118,"N":50,"ms_for_N":190}
## stub saw:
envelope items: {"client_report":2,"event":1}
client_report discards: [{"reason":"sample_rate","category":"span","quantity":22},{"reason":"sample_rate","category":"span","quantity":81}]
22 + 81 = 103. The SDK built every span, decided not to keep it, and then sent a report about it. Nothing is stored as a trace, but the instrumentation runs on every request and your ingest receives extra envelopes it has to answer.
And the run with the key removed, run-1-unset.txt:
{"MODE":"unset","spans_started":0,"spans_recording":0,"spans_ended":0,"rss_mb":114,"N":50,"ms_for_N":161}
## stub saw:
envelope items: {"event":1}
client_report discards: []
One error event, nothing else. That's the errors-only setup I actually wanted.
I also logged wall time for the 50 requests (ms_for_N). It moved between 161 and 193 ms across runs, including the run with no Sentry at all (171 ms). On a loopback test that small, the difference is noise, so I'm not claiming a latency cost from this lab.
The downstream service loses its traces
The sampled=false flag is what changed my mind about zero being harmless. Here is the header the downstream API received from the zero run:
sample baggage: sentry-environment=production,sentry-public_key=devkey,sentry-trace_id=e753752272ee408280dde03c408dbfcb,sentry-sampled=false,sentry-sample_rand=0.9553548709390874,sentry-sample_rate=0
A service that receives sampled=false inherits that decision. To check it, I added service-b.js, a second Sentry-instrumented service with tracesSampleRate: 1 and its own project, and pointed the app at it. Same 50 + 1 requests, three configs on the caller:
## A MODE=unset -> B tracesSampleRate: 1
service B (tracesSampleRate: 1) sent spans: 102; client_report discards: []
## A MODE=zero -> B tracesSampleRate: 1
service B (tracesSampleRate: 1) sent spans: 0; client_report discards: [{"reason":"sample_rate","category":"span","quantity":102}]
## A MODE=unset_noprop -> B tracesSampleRate: 1
service B (tracesSampleRate: 1) sent spans: 102; client_report discards: []
Service B was configured to trace everything and sent nothing, because the caller in front of it said "not sampled". Picture an API gateway where someone turned tracing "off" with a zero, and a team debugging latency in a service behind it. That team gets empty traces, and nothing in their own config explains it. The only hint is a sample_rate discard count in their client reports.
With the key removed, the caller still sends sentry-trace and baggage, but without a sampled flag (sampled flag {"(none)":51} in run-1-unset.txt), so B makes its own decision.
The environment variable trap
tracesSampleRate has an env var, SENTRY_TRACES_SAMPLE_RATE (listed on the Node options page). I ran the key-not-set config again with SENTRY_TRACES_SAMPLE_RATE=0 in the environment, run-8-unset-env-zero.txt:
## MODE=unset SENTRY_TRACES_SAMPLE_RATE=0
{"MODE":"unset","spans_started":103,"spans_recording":0,"spans_ended":51,"rss_mb":118,"N":50,"ms_for_N":192}
## stub saw:
envelope items: {"client_report":2,"event":1}
Identical to the zero run. So you can delete the key from the code and still have tracing on, because someone set the variable to 0 in a deploy template "to be safe". Check printenv | grep SENTRY_TRACES on the box, not only the code.
The errors-only config I use now
// instrument-errors-only.js: load this first (node --require ./instrument-errors-only.js app.js)
const Sentry = require('@sentry/node');
Sentry.init({
dsn: process.env.SENTRY_DSN,
// no tracesSampleRate, no tracesSampler: tracing stays off
tracePropagationTargets: [], // optional: no sentry-trace/baggage on outgoing calls
});
run-10-recipe.txt loads exactly this file through NODE_OPTIONS=--require=./instrument-errors-only.js:
{"MODE":"file","spans_started":0,"spans_recording":0,"spans_ended":0,"rss_mb":115,"N":50,"ms_for_N":185}
## stub saw:
envelope items: {"event":1}
client_report discards: []
error events: [{"message":"checkout failed","trace_id":"ff038e0d31824c7dac48d8df4c23b083"}]
downstream calls: 51, with sentry-trace: 0 (sampled flag {}), with baggage: 0, with traceparent: 0
The error event still carries a trace_id in its trace context, so turning tracing off doesn't strip that field. tracePropagationTargets: [] is the documented way to stop propagation ("If you want to disable trace propagation, you can set this option to []"). Leave it out if other services rely on your trace IDs to join their own errors.
Check your own service with a 17-line stub
The full lab is six small files, but you only need a fake ingest to check your own app. Save this as mini-stub.js:
// mini-stub.js: fake ingest on :9999. Prints item types and client_report discards for every envelope.
const zlib = require('zlib');
require('http').createServer((req, res) => {
const chunks = [];
req.on('data', c => chunks.push(c));
req.on('end', () => {
let buf = Buffer.concat(chunks);
if (req.headers['content-encoding'] === 'gzip') buf = zlib.gunzipSync(buf);
const lines = buf.toString().split('\n');
for (let i = 1; i < lines.length && lines[i]; i += 2) {
const type = JSON.parse(lines[i]).type;
const extra = type === 'client_report' ? ' ' + JSON.stringify(JSON.parse(lines[i + 1]).discarded_events) : '';
console.log(type + extra);
}
res.end('{}');
});
}).listen(9999, () => console.log('listening on :9999'));
Run node mini-stub.js, start your service with SENTRY_DSN=http://key@127.0.0.1:9999/1, send it a few requests and one error, then stop it so the SDK flushes. Here is what it printed for my app with tracesSampleRate: 0 and 5 requests, run-11-mini-stub-zero.txt:
listening on :9999
client_report [{"reason":"sample_rate","category":"span","quantity":12}]
event
client_report [{"reason":"sample_rate","category":"span","quantity":1}]
And with the key removed, run-11-mini-stub-unset.txt:
listening on :9999
event
If you see a client_report line with "category":"span", something in your setup still turns tracing on.
Checklist before you call it errors-only
-
grep -rn "tracesSampleRate\|tracesSampler" .finds nothing in your Sentry init. A0counts as a hit. -
SENTRY_TRACES_SAMPLE_RATEis unset in every environment, including CI and your container platform's variables. - The stub above shows no
client_reportwith"reason":"sample_rate","category":"span"for your service. - Downstream services that do trace still get spans when called through you. A
sampled=falseon their incomingsentry-traceheader means a caller is still at zero. - Before you set
tracePropagationTargets: [], check that no downstream team joins their errors to yours bytrace_id. - You've rerun the stub for each SDK you ship. I only tested plain
@sentry/node11.14.0 on Node 24.22.1. Next.js and the browser SDK weren't part of this lab.
If you run more than one service, is any caller in your stack still set to tracesSampleRate: 0?
Top comments (0)