(request: TransportRequest)
| 81 | */ |
| 82 | export function makeCloudflareTransport(options: CloudflareTransportOptions): Transport { |
| 83 | function makeRequest(request: TransportRequest): PromiseLike<TransportMakeRequestResponse> { |
| 84 | const requestOptions: RequestInit = { |
| 85 | body: request.body, |
| 86 | method: 'POST', |
| 87 | headers: options.headers, |
| 88 | ...options.fetchOptions, |
| 89 | }; |
| 90 | |
| 91 | return suppressTracing(() => { |
| 92 | return (options.fetch ?? fetch)(options.url, requestOptions).then(async response => { |
| 93 | // Consume the response body to satisfy Cloudflare Workers' fetch requirements. |
| 94 | // The runtime requires all fetch response bodies to be read or explicitly canceled |
| 95 | // to prevent connection stalls and potential deadlocks. We read the body as text |
| 96 | // even though we don't use the content, as Sentry's response information is in the headers. |
| 97 | // See: https://github.com/getsentry/sentry-javascript/issues/18534 |
| 98 | try { |
| 99 | await response.text(); |
| 100 | } catch { |
| 101 | // no-op |
| 102 | } |
| 103 | |
| 104 | return { |
| 105 | statusCode: response.status, |
| 106 | headers: { |
| 107 | 'x-sentry-rate-limits': response.headers.get('X-Sentry-Rate-Limits'), |
| 108 | 'retry-after': response.headers.get('Retry-After'), |
| 109 | }, |
| 110 | }; |
| 111 | }); |
| 112 | }); |
| 113 | } |
| 114 | |
| 115 | return createTransport(options, makeRequest, new IsolatedPromiseBuffer(options.bufferSize)); |
| 116 | } |
nothing calls this directly
no test coverage detected