mirror of
https://github.com/mauricioabh/arbpulse.git
synced 2026-07-27 15:47:43 +00:00
a5c83ee026
Spans are now created and exported to Sentry only when SENTRY_TRACING is enabled (default off), keeping 24/7 operation within the free-tier span quota. Error monitoring stays always-on. Includes OpenSpec change gate-sentry-spans (proposal, design, specs, tasks). Co-authored-by: Cursor <cursoragent@cursor.com>
2.9 KiB
2.9 KiB
Context
src/instrumentation/otel.ts builds a tracer that, when SENTRY_DSN is set, registers a NodeTracerProvider with SentrySpanProcessor/SentryPropagator, so every withSpan(...) call on the hot path creates and exports a span to Sentry. src/instrumentation/sentry.ts sets tracesSampleRate unconditionally. Running 24/7 on a VPS multiplies span volume against Sentry's free-tier quota (5M spans/month), while error events stay small. We want tracing to remain a debugging option but be off by default.
Goals / Non-Goals
Goals:
- Add a single boolean env var (
SENTRY_TRACING, defaultfalse) that turns span creation/export on or off. - Default behavior emits zero spans and zero hot-path span allocation.
- Preserve error monitoring exactly as-is regardless of the flag.
- No dependency changes; no API/wire changes.
Non-Goals:
- Removing OpenTelemetry or the
withSpanabstraction. - Making
tracesSampleRateitself env-configurable (kept as current 0.1 prod / 1 dev when enabled). - Changing which operations are wrapped.
Decisions
- Boolean gate over sample-rate gate. A boolean
SENTRY_TRACINGthat makes the tracer a no-op avoids hot-path span allocation entirely when off (aligns with the "no unnecessary alloc on the hot path" convention). AtracesSampleRate=0approach would still register the provider and create spans that are dropped later — more overhead. Alternative considered and rejected. - Gate lives in
otel.tsinit.initOpenTelemetry()returns the no-optrace.getTracer("arbpulse")unless bothSENTRY_DSNandSENTRY_TRACINGare truthy. This keepswithSpan's signature and all call sites unchanged; itscatchstill callsSentry.captureException, so errors are captured even with a no-op span. - Conditional
tracesSampleRateinsentry.ts. Only settracesSampleRatewhen tracing is enabled; omit it otherwise so Sentry performance is fully off. A shared helperisTracingEnabled()reads the flag so both files agree. - Parsing. Reuse the existing truthy convention (
"1"or"true", case-insensitive) used byconfig.ts'sbool()for consistency; implement locally in the instrumentation module since it initializes beforeconfigimport.
Risks / Trade-offs
- [Someone enables tracing in prod and hits the quota] → Documented in
.env.example/README that it is off by default and why; enabling is an explicit opt-in. - [Flag read in two files could drift] → Centralize in one
isTracingEnabled()helper exported from the instrumentation layer. - [No-op tracer still wraps hot path in a promise] → Accepted:
withSpanremains async as today; the change only removes span export, matching prior behavior whenSENTRY_DSNwas unset.
Migration Plan
- Deploy with
SENTRY_TRACINGunset → tracing off (safe default), errors still reported. - To debug, set
SENTRY_TRACING=true(withSENTRY_DSN) temporarily; unset to roll back. No data migration.