All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.build.npm.cjs.integrations.spotlight.js.map Maven / Gradle / Ivy

The newest version!
{"version":3,"file":"spotlight.js","sources":["../../../../src/integrations/spotlight.ts"],"sourcesContent":["import { getNativeImplementation } from '@sentry-internal/browser-utils';\nimport type { Client, Envelope, Event, IntegrationFn } from '@sentry/core';\nimport { defineIntegration, logger, serializeEnvelope } from '@sentry/core';\nimport { DEBUG_BUILD } from '../debug-build';\nimport type { WINDOW } from '../helpers';\n\nexport type SpotlightConnectionOptions = {\n  /**\n   * Set this if the Spotlight Sidecar is not running on localhost:8969\n   * By default, the Url is set to http://localhost:8969/stream\n   */\n  sidecarUrl?: string;\n};\n\nexport const INTEGRATION_NAME = 'SpotlightBrowser';\n\nconst _spotlightIntegration = ((options: Partial = {}) => {\n  const sidecarUrl = options.sidecarUrl || 'http://localhost:8969/stream';\n\n  return {\n    name: INTEGRATION_NAME,\n    setup: () => {\n      DEBUG_BUILD && logger.log('Using Sidecar URL', sidecarUrl);\n    },\n    // We don't want to send interaction transactions/root spans created from\n    // clicks within Spotlight to Sentry. Neither do we want them to be sent to\n    // spotlight.\n    processEvent: event => (isSpotlightInteraction(event) ? null : event),\n    afterAllSetup: (client: Client) => {\n      setupSidecarForwarding(client, sidecarUrl);\n    },\n  };\n}) satisfies IntegrationFn;\n\nfunction setupSidecarForwarding(client: Client, sidecarUrl: string): void {\n  const makeFetch: typeof WINDOW.fetch | undefined = getNativeImplementation('fetch');\n  let failCount = 0;\n\n  client.on('beforeEnvelope', (envelope: Envelope) => {\n    if (failCount > 3) {\n      logger.warn('[Spotlight] Disabled Sentry -> Spotlight integration due to too many failed requests:', failCount);\n      return;\n    }\n\n    makeFetch(sidecarUrl, {\n      method: 'POST',\n      body: serializeEnvelope(envelope),\n      headers: {\n        'Content-Type': 'application/x-sentry-envelope',\n      },\n      mode: 'cors',\n    }).then(\n      res => {\n        if (res.status >= 200 && res.status < 400) {\n          // Reset failed requests counter on success\n          failCount = 0;\n        }\n      },\n      err => {\n        failCount++;\n        logger.error(\n          \"Sentry SDK can't connect to Sidecar is it running? See: https://spotlightjs.com/sidecar/npx/\",\n          err,\n        );\n      },\n    );\n  });\n}\n\n/**\n * Use this integration to send errors and transactions to Spotlight.\n *\n * Learn more about spotlight at https://spotlightjs.com\n */\nexport const spotlightBrowserIntegration = defineIntegration(_spotlightIntegration);\n\n/**\n * Flags if the event is a transaction created from an interaction with the spotlight UI.\n */\nexport function isSpotlightInteraction(event: Event): boolean {\n  return Boolean(\n    event.type === 'transaction' &&\n      event.spans &&\n      event.contexts &&\n      event.contexts.trace &&\n      event.contexts.trace.op === 'ui.action.click' &&\n      event.spans.some(({ description }) => description && description.includes('#sentry-spotlight')),\n  );\n}\n"],"names":["DEBUG_BUILD","logger","getNativeImplementation","serializeEnvelope","defineIntegration"],"mappings":";;;;;;AAcO,MAAM,gBAAiB,GAAE;;AAEhC,MAAM,qBAAA,IAAyB,CAAC,OAAO,GAAwC,EAAE,KAAK;AACtF,EAAE,MAAM,UAAW,GAAE,OAAO,CAAC,UAAA,IAAc,8BAA8B;;AAEzE,EAAE,OAAO;AACT,IAAI,IAAI,EAAE,gBAAgB;AAC1B,IAAI,KAAK,EAAE,MAAM;AACjB,MAAMA,sBAAA,IAAeC,WAAM,CAAC,GAAG,CAAC,mBAAmB,EAAE,UAAU,CAAC;AAChE,KAAK;AACL;AACA;AACA;AACA,IAAI,YAAY,EAAE,KAAM,KAAI,sBAAsB,CAAC,KAAK,CAAE,GAAE,IAAK,GAAE,KAAK,CAAC;AACzE,IAAI,aAAa,EAAE,CAAC,MAAM,KAAa;AACvC,MAAM,sBAAsB,CAAC,MAAM,EAAE,UAAU,CAAC;AAChD,KAAK;AACL,GAAG;AACH,CAAC,CAAE;;AAEH,SAAS,sBAAsB,CAAC,MAAM,EAAU,UAAU,EAAgB;AAC1E,EAAE,MAAM,SAAS,GAAoCC,oCAAuB,CAAC,OAAO,CAAC;AACrF,EAAE,IAAI,SAAU,GA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