UNPKG

@sentry/browser

Version:
58 lines (55 loc) 1.92 kB
import { defineIntegration, debug, serializeEnvelope } from '@sentry/core/browser'; import { getNativeImplementation } from '@sentry-internal/browser-utils'; import { DEBUG_BUILD } from '../debug-build.js'; const INTEGRATION_NAME = "SpotlightBrowser"; const SPOTLIGHT_IGNORE_SPANS = [{ op: "ui.interaction.click", name: "#sentry-spotlight" }]; const _spotlightIntegration = ((options = {}) => { const sidecarUrl = options.sidecarUrl || "http://localhost:8969/stream"; return { name: INTEGRATION_NAME, setup: () => { DEBUG_BUILD && debug.log("Using Sidecar URL", sidecarUrl); }, beforeSetup(client) { const opts = client.getOptions(); opts.ignoreSpans = [...opts.ignoreSpans || [], ...SPOTLIGHT_IGNORE_SPANS]; }, afterAllSetup: (client) => { setupSidecarForwarding(client, sidecarUrl); } }; }); function setupSidecarForwarding(client, sidecarUrl) { const makeFetch = getNativeImplementation("fetch"); let failCount = 0; client.on("beforeEnvelope", (envelope) => { if (failCount > 3) { debug.warn("[Spotlight] Disabled Sentry -> Spotlight integration due to too many failed requests:", failCount); return; } makeFetch(sidecarUrl, { method: "POST", body: serializeEnvelope(envelope), headers: { "Content-Type": "application/x-sentry-envelope" }, mode: "cors" }).then( (res) => { if (res.status >= 200 && res.status < 400) { failCount = 0; } }, (err) => { failCount++; debug.error( "Sentry SDK can't connect to Sidecar is it running? See: https://spotlightjs.com/sidecar/npx/", err ); } ); }); } const spotlightBrowserIntegration = defineIntegration(_spotlightIntegration); export { INTEGRATION_NAME, SPOTLIGHT_IGNORE_SPANS, spotlightBrowserIntegration }; //# sourceMappingURL=spotlight.js.map