import { defineIntegration, debug, serializeEnvelope, suppressTracing } from '@sentry/core'; import { DEBUG_BUILD } from '../debug-build.js'; const INTEGRATION_NAME = "Spotlight"; const _spotlightIntegration = ((options = {}) => { const sidecarUrl = options.sidecarUrl || "http://localhost:8969/stream"; return { name: INTEGRATION_NAME, setup(client) { DEBUG_BUILD && debug.log("[Spotlight] Using Sidecar URL", sidecarUrl); setupSidecarForwarding(client, sidecarUrl); } }; }); const spotlightIntegration = defineIntegration(_spotlightIntegration); function setupSidecarForwarding(client, sidecarUrl) { const parsedUrl = parseSidecarUrl(sidecarUrl); if (!parsedUrl) { return; } let failCount = 0; client.on("beforeEnvelope", (envelope) => { if (failCount > 3) { DEBUG_BUILD && debug.warn("[Spotlight] Disabled Sentry -> Spotlight forwarding due to too many failed requests"); return; } const body = serializeEnvelope(envelope); suppressTracing(() => { fetch(parsedUrl.href, { method: "POST", body, headers: { "Content-Type": "application/x-sentry-envelope" } }).then( (res) => { res.text().catch(() => { }); if (res.status >= 200 && res.status < 400) { failCount = 0; } }, () => { failCount++; DEBUG_BUILD && debug.warn("[Spotlight] Failed to send envelope to Spotlight Sidecar"); } ); }); }); } function parseSidecarUrl(url) { try { return new URL(url); } catch { DEBUG_BUILD && debug.warn(`[Spotlight] Invalid sidecar URL: ${url}`); return void 0; } } export { INTEGRATION_NAME, spotlightIntegration }; //# sourceMappingURL=spotlight.js.map