import * as Sentry from '@sentry/node';
let initialized = false;
function resolveEnvironment() {
    return process.env.VERCEL_ENV ?? process.env.NODE_ENV ?? 'development';
}
/** Initialize Sentry when `SENTRY_DSN` is set. Safe to call repeatedly. */
export function initServerSentry() {
    if (initialized)
        return;
    const dsn = process.env.SENTRY_DSN?.trim();
    if (!dsn)
        return;
    Sentry.init({
        dsn,
        environment: resolveEnvironment(),
        release: process.env.SENTRY_RELEASE?.trim() || undefined,
        tracesSampleRate: 0,
    });
    initialized = true;
}
/** Report a server-side exception when Sentry is configured. Never throws. */
export function captureServerException(err, context) {
    try {
        initServerSentry();
        if (!process.env.SENTRY_DSN?.trim())
            return;
        Sentry.captureException(err, {
            tags: context?.scope ? { scope: context.scope } : undefined,
            extra: context?.extra,
        });
    }
    catch {
        // Observability must never break user requests.
    }
}
//# sourceMappingURL=sentry.js.map