@sentry/browser
Version:
Official Sentry SDK for browsers
62 lines (61 loc) • 2.41 kB
JavaScript
const require_debug_build = require("../debug-build.js");
let _sentry_core = require("@sentry/core");
let _sentry_browser_utils = require("@sentry/browser-utils");
let _sentry_conventions_attributes = require("@sentry/conventions/attributes");
let _sentry_conventions_op = require("@sentry/conventions/op");
// src/integrations/spotlight.ts
const INTEGRATION_NAME = "SpotlightBrowser";
const SPOTLIGHT_IGNORE_SPANS = [{
op: _sentry_conventions_op.UI_INTERACTION_CLICK,
name: "#sentry-spotlight"
}, {
op: _sentry_conventions_op.UI_INTERACTION_CLICK,
attributes: { [_sentry_conventions_attributes.BROWSER_WEB_VITAL_INP_TARGET]: "#sentry-spotlight" }
}];
const _spotlightIntegration = ((options = {}) => {
const sidecarUrl = options.sidecarUrl || "http://localhost:8969/stream";
return {
name: INTEGRATION_NAME,
setup: () => {
require_debug_build.DEBUG_BUILD && _sentry_core.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 = (0, _sentry_browser_utils.getNativeImplementation)("fetch");
let failCount = 0;
client.on("beforeEnvelope", (envelope) => {
if (failCount > 3) {
_sentry_core.debug.warn("[Spotlight] Disabled Sentry -> Spotlight integration due to too many failed requests:", failCount);
return;
}
makeFetch(sidecarUrl, {
method: "POST",
body: (0, _sentry_core.serializeEnvelope)(envelope),
headers: { "Content-Type": "application/x-sentry-envelope" },
mode: "cors"
}).then((res) => {
if (res.status >= 200 && res.status < 400) failCount = 0;
}, (err) => {
failCount++;
_sentry_core.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 = (0, _sentry_core.defineIntegration)(_spotlightIntegration);
exports.INTEGRATION_NAME = INTEGRATION_NAME;
exports.SPOTLIGHT_IGNORE_SPANS = SPOTLIGHT_IGNORE_SPANS;
exports.spotlightBrowserIntegration = spotlightBrowserIntegration;
//# sourceMappingURL=spotlight.js.map