From b35cbf685d848d6945358bab41effae6cbaa76b6 Mon Sep 17 00:00:00 2001 From: Onur Temizkan Date: Tue, 17 Oct 2023 10:46:24 +0100 Subject: [PATCH] Clean up worker transport. --- packages/remix/src/index.client.tsx | 4 ++-- packages/remix/src/worker/transport.ts | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/remix/src/index.client.tsx b/packages/remix/src/index.client.tsx index a593f2033014..fa9f596f3db6 100644 --- a/packages/remix/src/index.client.tsx +++ b/packages/remix/src/index.client.tsx @@ -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'; @@ -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); diff --git a/packages/remix/src/worker/transport.ts b/packages/remix/src/worker/transport.ts index 0043be033c63..810a828214d3 100644 --- a/packages/remix/src/worker/transport.ts +++ b/packages/remix/src/worker/transport.ts @@ -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; context?: Record; 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 { const requestOptions: RequestInit = { body: request.body, @@ -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); }