Skip to content

Commit

Permalink
Clean up worker transport.
Browse files Browse the repository at this point in the history
  • Loading branch information
onurtemizkan committed Nov 17, 2023
1 parent 16a13c0 commit 7ab4e23
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/remix/src/index.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { ServerRuntimeClientOptions } from '@sentry/core';
import { configureScope, getCurrentHub, getIntegrationsToSetup, initAndBind, ServerRuntimeClient } from '@sentry/core';
import { createStackParser, logger, nodeStackLineParser, stackParserFromStackParserOptions } from '@sentry/utils';

import { makeCloudflareTransport } from './worker/transport';
import { makeWorkerTransport } from './worker/transport';

export { captureRemixServerException } from './utils/instrumentServer';
export { ErrorBoundary, withErrorBoundary } from '@sentry/react';
Expand Down Expand Up @@ -46,7 +46,7 @@ export function workerInit(options: RemixOptions): void {
...options,
stackParser: stackParserFromStackParserOptions(options.stackParser || nodeStackParser),
integrations: getIntegrationsToSetup(options),
transport: options.transport || makeCloudflareTransport,
transport: options.transport || makeWorkerTransport,
};

initAndBind(ServerRuntimeClient, clientOptions);
Expand Down
8 changes: 5 additions & 3 deletions packages/remix/src/worker/transport.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { createTransport } from '@sentry/core';
import type { BaseTransportOptions, Transport, TransportMakeRequestResponse, TransportRequest } from '@sentry/types';

export type CloudflareWorkersTransportOptions = BaseTransportOptions & {
export type WorkersTransportOptions = BaseTransportOptions & {
headers?: Record<string, string>;
context?: Record<string, any>;
fetcher?: typeof fetch;
};

/**
* Creates a Transport that uses the Cloudflare Workers' fetch API to send events to Sentry.
* Creates a Transport that uses the Cloudflare Workers' or Shopify Oxygen's fetch API to send events to Sentry.
*/
export function makeCloudflareTransport(options: CloudflareWorkersTransportOptions): Transport {
export function makeWorkerTransport(options: WorkersTransportOptions): Transport {
function makeRequest(request: TransportRequest): PromiseLike<TransportMakeRequestResponse> {
const requestOptions: RequestInit = {
body: request.body,
Expand All @@ -28,6 +28,8 @@ export function makeCloudflareTransport(options: CloudflareWorkersTransportOptio
};
});

// If we're in a Cloudflare Worker, wait for the fetch to complete
// before returning. This ensures that the Worker doesn't shut down
if (options.context && options.context.waitUntil) {
options.context.waitUntil(fetchRequest);
}
Expand Down

0 comments on commit 7ab4e23

Please sign in to comment.