1 |
- {"version":3,"file":"index.js","sources":["../../../src/transports/index.ts"],"sourcesContent":["import { createTransport } from '@sentry/core';\nimport type { BaseTransportOptions, Transport, TransportMakeRequestResponse, TransportRequest } from '@sentry/types';\nimport { SentryError } from '@sentry/utils';\n\nexport interface VercelEdgeTransportOptions extends BaseTransportOptions {\n /** Fetch API init parameters. */\n fetchOptions?: RequestInit;\n /** Custom headers for the transport. */\n headers?: { [key: string]: string };\n}\n\nconst DEFAULT_TRANSPORT_BUFFER_SIZE = 30;\n\n/**\n * This is a modified promise buffer that collects tasks until drain is called.\n * We need this in the edge runtime because edge function invocations may not share I/O objects, like fetch requests\n * and responses, and the normal PromiseBuffer inherently buffers stuff inbetween incoming requests.\n *\n * A limitation we need to be aware of is that DEFAULT_TRANSPORT_BUFFER_SIZE is the maximum amount of payloads the\n * SDK can send for a given edge function invocation.\n */\nexport class IsolatedPromiseBuffer {\n // We just have this field because the promise buffer interface requires it.\n // If we ever remove it from the interface we should also remove it here.\n public $: Array<PromiseLike<TransportMakeRequestResponse>>;\n\n private _taskProducers: (() => PromiseLike<TransportMakeRequestResponse>)[];\n\n private readonly _bufferSize: number;\n\n public constructor(_bufferSize = DEFAULT_TRANSPORT_BUFFER_SIZE) {\n this.$ = [];\n this._taskProducers = [];\n this._bufferSize = _bufferSize;\n }\n\n /**\n * @inheritdoc\n */\n public add(taskProducer: () => PromiseLike<TransportMakeRequestResponse>): PromiseLike<void> {\n if (this._taskProducers.length >= this._bufferSize) {\n return Promise.reject(new SentryError('Not adding Promise because buffer limit was reached.'));\n }\n\n this._taskProducers.push(taskProducer);\n return Promise.resolve();\n }\n\n /**\n * @inheritdoc\n */\n public drain(timeout?: number): PromiseLike<boolean> {\n const oldTaskProducers = [...this._taskProducers];\n this._taskProducers = [];\n\n return new Promise(resolve => {\n const timer = setTimeout(() => {\n if (timeout && timeout > 0) {\n resolve(false);\n }\n }, timeout);\n\n // This cannot reject\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n Promise.all(\n oldTaskProducers.map(taskProducer =>\n taskProducer().then(null, () => {\n // catch all failed requests\n }),\n ),\n ).then(() => {\n // resolve to true if all fetch requests settled\n clearTimeout(timer);\n resolve(true);\n });\n });\n }\n}\n\n/**\n * Creates a Transport that uses the Edge Runtimes native fetch API to send events to Sentry.\n */\nexport function makeEdgeTransport(options: VercelEdgeTransportOptions): Transport {\n function makeRequest(request: TransportRequest): PromiseLike<TransportMakeRequestResponse> {\n const requestOptions: RequestInit = {\n body: request.body,\n method: 'POST',\n headers: options.headers,\n ...options.fetchOptions,\n };\n\n return fetch(options.url, requestOptions).then(response => {\n return {\n statusCode: response.status,\n headers: {\n 'x-sentry-rate-limits': response.headers.get('X-Sentry-Rate-Limits'),\n 'retry-after': response.headers.get('Retry-After'),\n },\n };\n });\n }\n\n return createTransport(options, makeRequest, new IsolatedPromiseBuffer(options.bufferSize));\n}\n"],"names":[],"mappings":";;;AAWA,MAAM,6BAAA,GAAgC,EAAE,CAAA;AACxC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,qBAAsB,CAAA;AACnC;AACA;;AAOA,GAAS,WAAW,CAAC,WAAY,GAAE,6BAA6B,EAAE;AAClE,IAAI,IAAI,CAAC,CAAE,GAAE,EAAE,CAAA;AACf,IAAI,IAAI,CAAC,cAAe,GAAE,EAAE,CAAA;AAC5B,IAAI,IAAI,CAAC,WAAY,GAAE,WAAW,CAAA;AAClC,GAAE;AACF;AACA;AACA;AACA;AACA,GAAS,GAAG,CAAC,YAAY,EAAsE;AAC/F,IAAI,IAAI,IAAI,CAAC,cAAc,CAAC,MAAA,IAAU,IAAI,CAAC,WAAW,EAAE;AACxD,MAAM,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,WAAW,CAAC,sDAAsD,CAAC,CAAC,CAAA;AACpG,KAAI;AACJ;AACA,IAAI,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;AAC1C,IAAI,OAAO,OAAO,CAAC,OAA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