Repository navigation
Load Sentry tracing only when traces are sampled - #1997
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A CPU profile of the live Cloud backend (60 s, 2026-12-05 21:37 UTC) puts about 22 % of its busy CPU time in Sentry and OpenTelemetry code: span attributes, SQL sanitising, uuid generation, span start logging. That happens on every request and every Prisma/pg query. Yet only 0.5 % of HTTP requests are sampled, and the spans were over quota anyway.
The cause:
instrument.tsalways passes atracesSampler, even when the rates are 0. With any sampler,@sentry/node11 adds its tracing integrations (getDefaultIntegrations→hasSpansEnabled(options) ? getTracingIntegrations() : []). Unsampled spans are still built.Changes
common/sentry-sampler.ts:tracingRatesFromEnv()returns the rates, ornullwhen both are 0.instrument.ts: passestracesSampleronly when there is something to sample. Error reporting is unchanged: DSN, scrubbers,httpIntegrationwith no request bodies.docker-compose.cloud.yml: the Cloud defaultSENTRY_TRACES_SAMPLE_RATEgoes from0.005to0. A rate in.envturns tracing back on for an investigation.docs/operations/observability.md: explains that any rate above 0 loads the instrumentation for every request.Type
Testing
sentry-sampler.spec.ts,tracingRatesFromEnv): returns null for unset, 0, empty, invalid or out-of-range rates; MCP gets a fifth of the HTTP rate by default; MCP alone can be traced.prisma generate:npx tsc --noEmit -p tsconfig.json: clean.npx eslinton the changed files: clean.npx jest --maxWorkers=4 src/common/sentry: 18 passed.node_modules/@sentry/node(11.16.0) that tracing integrations depend onhasSpansEnabled(options). No backend code callsstartSpan/getActiveSpan.Checklist
npm test): full suite in CICloud: errors still go to Sentry; no performance traces unless a rate is set in
.env.Self-hosted: the default rate was already 0, so a self-hosted instance with a DSN now also skips the tracing instrumentation it never used. No database migration. No change under
ee/.After the deploy I will compare backend CPU and /mcp latency at the same hours.
Related Issues
Daily check 2026-12-05 (backend slow at peak hours).