Files
arbpulse/src/instrumentation/sentry.ts
T
Mauricio BarraganandCursor a5c83ee026 feat(observability): gate Sentry tracing spans behind SENTRY_TRACING
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>
2026-07-16 12:54:15 -06:00

33 lines
923 B
TypeScript

import * as Sentry from "@sentry/node";
import { isTracingEnabled } from "./tracing.js";
const dsn = process.env.SENTRY_DSN?.trim();
export function initSentry(): void {
if (!dsn) return;
Sentry.init({
dsn,
environment: process.env.NODE_ENV ?? "development",
integrations: [Sentry.httpIntegration(), Sentry.expressIntegration()],
// Tracing/spans are gated by SENTRY_TRACING (default off) to stay within
// the Sentry free-tier span quota during 24/7 operation. Error monitoring
// is always on.
...(isTracingEnabled()
? { tracesSampleRate: process.env.NODE_ENV === "production" ? 0.1 : 1 }
: {}),
});
process.on("unhandledRejection", (reason) => {
Sentry.captureException(
reason instanceof Error ? reason : new Error(String(reason)),
);
});
process.on("uncaughtException", (error) => {
Sentry.captureException(error);
});
}
export { Sentry };