UNPKG

@sentry/browser

Version:
71 lines (61 loc) 2.13 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) { // Reset failed requests counter on success 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