UNPKG

@sentry/browser

Version:
60 lines (59 loc) • 2.15 kB
import { DEBUG_BUILD } from "../debug-build.js"; import { debug, defineIntegration, serializeEnvelope } from "@sentry/core"; import { getNativeImplementation } from "@sentry/browser-utils"; import { BROWSER_WEB_VITAL_INP_TARGET } from "@sentry/conventions/attributes"; import { UI_INTERACTION_CLICK } from "@sentry/conventions/op"; // src/integrations/spotlight.ts const INTEGRATION_NAME = "SpotlightBrowser"; const SPOTLIGHT_IGNORE_SPANS = [{ op: UI_INTERACTION_CLICK, name: "#sentry-spotlight" }, { op: UI_INTERACTION_CLICK, attributes: { [BROWSER_WEB_VITAL_INP_TARGET]: "#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); }); }); } /** * Use this integration to send errors and transactions to Spotlight. * * Learn more about spotlight at https://spotlightjs.com */ const spotlightBrowserIntegration = defineIntegration(_spotlightIntegration); export { INTEGRATION_NAME, SPOTLIGHT_IGNORE_SPANS, spotlightBrowserIntegration }; //# sourceMappingURL=spotlight.js.map