Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/cloudflare/src/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import type { BaseTransportOptions, Transport, TransportMakeRequestResponse, Tra
import { createTransport, SENTRY_BUFFER_FULL_ERROR, suppressTracing } from '@sentry/core';

export interface CloudflareTransportOptions extends BaseTransportOptions {
/** Custom fetch function to use. This allows usage of things like Workers VPC */
fetch?: typeof fetch;
/** Fetch API init parameters. */
fetchOptions?: RequestInit;
}
Expand Down Expand Up @@ -87,7 +89,7 @@ export function makeCloudflareTransport(options: CloudflareTransportOptions): Tr
};

return suppressTracing(() => {
return fetch(options.url, requestOptions).then(response => {
return (options.fetch ?? fetch)(options.url, requestOptions).then(response => {
return {
statusCode: response.status,
headers: {
Expand Down
16 changes: 16 additions & 0 deletions packages/cloudflare/test/transport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,20 @@ describe('IsolatedPromiseBuffer', () => {
expect(task1).toHaveBeenCalled();
expect(task2).toHaveBeenCalled();
});

it('should allow for a custom fetch function to be passed in', async () => {
const customFetch = vi.fn(async () => {
return {
headers: new Headers(),
status: 200,
text: () => Promise.resolve({}),
} as unknown as Response;
});

const transport = makeCloudflareTransport({ ...DEFAULT_EDGE_TRANSPORT_OPTIONS, fetch: customFetch });

await transport.send(ERROR_ENVELOPE);
await transport.flush();
expect(customFetch).toHaveBeenCalledTimes(1);
});
});
Loading