"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.__ΩISentryOptions = void 0;
exports.isSentryInstalled = isSentryInstalled;
exports.installSentry = installSentry;
exports.flushSentry = flushSentry;
const tslib_1 = require("tslib");
function __assignType(fn, args) {
    fn.__type = args;
    return fn;
}
const Sentry = tslib_1.__importStar(require("@sentry/node"));
const helpers_1 = require("../helpers");
const helpers_2 = require("./otel/helpers");
const SentryState = {
    installed: false
};
function isSentryInstalled() {
    return SentryState.installed;
}
isSentryInstalled.__type = ['isSentryInstalled', 'P"/!'];
const __ΩISentryOptions = ['dsn', 'ISentryOptions', 'P"&4!Mw"y'];
exports.__ΩISentryOptions = __ΩISentryOptions;
function installSentry(options) {
    const { dsn, ...sentryOptions } = options;
    const pkgJson = (0, helpers_1.getPackageJson)();
    Sentry.init({
        dsn: dsn,
        environment: process.env.APP_ENV,
        maxBreadcrumbs: 0,
        release: pkgJson?.name?.replace(/^@.+?\//, '') + '@' + pkgJson?.version,
        skipOpenTelemetrySetup: true,
        integrations: __assignType(integrations => integrations.filter(__assignType(integration => {
            return !['Http', 'NodeFetch'].includes(integration.name);
        }, ['integration', '', 'P"2!"/"'])), ['integrations', '', 'P"2!"/"']),
        ...sentryOptions
    });
    if ((0, helpers_2.isTracingInstalled)()) {
        Sentry.addEventProcessor(__assignType(event => {
            const spanCtx = (0, helpers_2.getTraceContext)();
            if (spanCtx) {
                event.contexts = {
                    ...event.contexts,
                    trace: {
                        trace_id: spanCtx.traceId,
                        span_id: spanCtx.spanId
                    }
                };
            }
            return event;
        }, ['event', '', 'P"2!"/"']));
    }
    SentryState.installed = true;
}
installSentry.__type = [() => __ΩISentryOptions, 'options', 'installSentry', 'Pn!2""/#'];
async function flushSentry() {
    if (isSentryInstalled()) {
        await Sentry.flush(5);
    }
}
flushSentry.__type = ['flushSentry', 'P"/!'];
//# sourceMappingURL=sentry.js.map