UNPKG

@sentry/browser

Version:
44 lines (43 loc) • 1.48 kB
let _sentry_core = require("@sentry/core"); let _sentry_browser_utils = require("@sentry/browser-utils"); // src/transports/fetch.ts const DEFAULT_BROWSER_TRANSPORT_BUFFER_SIZE = 40; /** * Creates a Transport that uses the Fetch API to send events to Sentry. */ function makeFetchTransport(options, nativeFetch = (0, _sentry_browser_utils.getNativeImplementation)("fetch")) { let pendingBodySize = 0; let pendingCount = 0; async function makeRequest(request) { const requestSize = request.body.length; pendingBodySize += requestSize; pendingCount++; const requestOptions = { body: request.body, method: "POST", referrerPolicy: "strict-origin", headers: options.headers, keepalive: pendingBodySize <= 6e4 && pendingCount < 15, ...options.fetchOptions }; try { const response = await nativeFetch(options.url, requestOptions); return { statusCode: response.status, headers: { "x-sentry-rate-limits": response.headers.get("X-Sentry-Rate-Limits"), "retry-after": response.headers.get("Retry-After") } }; } catch (e) { (0, _sentry_browser_utils.clearCachedImplementation)("fetch"); throw e; } finally { pendingBodySize -= requestSize; pendingCount--; } } return (0, _sentry_core.createTransport)(options, makeRequest, (0, _sentry_core.makePromiseBuffer)(options.bufferSize || DEFAULT_BROWSER_TRANSPORT_BUFFER_SIZE)); } exports.makeFetchTransport = makeFetchTransport; //# sourceMappingURL=fetch.js.map