Object.defineProperty(exports, '__esModule', { value: true }); const tracing = require('@sentry-internal/tracing'); const core = require('@sentry/core'); const utils = require('@sentry/utils'); const INTEGRATION_NAME = 'WinterCGFetch'; const HAS_CLIENT_MAP = new WeakMap(); const _winterCGFetch = ((options = {}) => { const breadcrumbs = options.breadcrumbs === undefined ? true : options.breadcrumbs; const shouldCreateSpanForRequest = options.shouldCreateSpanForRequest; const _createSpanUrlMap = new utils.LRUMap(100); const _headersUrlMap = new utils.LRUMap(100); const spans = {}; /** Decides whether to attach trace data to the outgoing fetch request */ function _shouldAttachTraceData(url) { const client = core.getClient(); if (!client) { return false; } const clientOptions = client.getOptions(); if (clientOptions.tracePropagationTargets === undefined) { return true; } const cachedDecision = _headersUrlMap.get(url); if (cachedDecision !== undefined) { return cachedDecision; } const decision = utils.stringMatchesSomePattern(url, clientOptions.tracePropagationTargets); _headersUrlMap.set(url, decision); return decision; } /** Helper that wraps shouldCreateSpanForRequest option */ function _shouldCreateSpan(url) { if (shouldCreateSpanForRequest === undefined) { return true; } const cachedDecision = _createSpanUrlMap.get(url); if (cachedDecision !== undefined) { return cachedDecision; } const decision = shouldCreateSpanForRequest(url); _createSpanUrlMap.set(url, decision); return decision; } return { name: INTEGRATION_NAME, // TODO v8: Remove this again // eslint-disable-next-line @typescript-eslint/no-empty-function setupOnce() { utils.addFetchInstrumentationHandler(handlerData => { const client = core.getClient(); if (!client || !HAS_CLIENT_MAP.get(client)) { return; } if (core.isSentryRequestUrl(handlerData.fetchData.url, client)) { return; } tracing.instrumentFetchRequest( handlerData, _shouldCreateSpan, _shouldAttachTraceData, spans, 'auto.http.wintercg_fetch', ); if (breadcrumbs) { createBreadcrumb(handlerData); } }); }, setup(client) { HAS_CLIENT_MAP.set(client, true); }, }; }) ; const winterCGFetchIntegration = core.defineIntegration(_winterCGFetch); /** * Creates spans and attaches tracing headers to fetch requests on WinterCG runtimes. * * @deprecated Use `winterCGFetchIntegration()` instead. */ // eslint-disable-next-line deprecation/deprecation const WinterCGFetch = core.convertIntegrationFnToClass( INTEGRATION_NAME, winterCGFetchIntegration, ) ; // eslint-disable-next-line deprecation/deprecation function createBreadcrumb(handlerData) { const { startTimestamp, endTimestamp } = handlerData; // We only capture complete fetch requests if (!endTimestamp) { return; } if (handlerData.error) { const data = handlerData.fetchData; const hint = { data: handlerData.error, input: handlerData.args, startTimestamp, endTimestamp, }; core.addBreadcrumb( { category: 'fetch', data, level: 'error', type: 'http', }, hint, ); } else { const data = { ...handlerData.fetchData, status_code: handlerData.response && handlerData.response.status, }; const hint = { input: handlerData.args, response: handlerData.response, startTimestamp, endTimestamp, }; core.addBreadcrumb( { category: 'fetch', data, type: 'http', }, hint, ); } } exports.WinterCGFetch = WinterCGFetch; exports.winterCGFetchIntegration = winterCGFetchIntegration; //# sourceMappingURL=wintercg-fetch.js.map