Skip to content

Commit 6396adc

Browse files
mydeaclaude
andcommitted
fix(server-utils): Keep node:async_hooks out of the edge/browser barrels
The Hydrogen (Oxygen) e2e app `remix-hydrogen` failed to build: its client bundle pulled `@sentry/server-utils/async-context` (`import { AsyncLocalStorage } from 'node:async_hooks'`), which Vite externalizes into an empty stub, throwing `"AsyncLocalStorage" is not exported by "__vite-browser-external"`. `async-context` is the only module in the shared `exports.ts` surface that statically imports a `node:` builtin, yet it was re-exported from both the `index` and `no-diagnostic-channels` barrels — so any browser/edge bundle importing *any* helper from those barrels dragged `node:async_hooks` into the graph. - Move `setAsyncLocalStorageAsyncContextStrategy` out of the shared `exports.ts` into a dedicated `@sentry/server-utils/async-context` entry, so `index` / `no-diagnostic-channels` are free of `node:` builtins. Update its consumers (Node/Deno/Cloudflare SDKs + tests), all of which run where `node:async_hooks` resolves. - Point the two `@sentry/remix/cloudflare`-reachable imports (`instrumentServer`'s `loadModule`, `cloudflare/index`'s `trpcMiddleware`) at the lean `no-diagnostic-channels` barrel instead of the full `@sentry/server-utils` barrel, whose Node-only integrations (`tedious` → `node:events`, …) otherwise reach the bundled Hydrogen client build. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01D7JDQBD9J2okCe1hkWCanU
1 parent eb54f84 commit 6396adc

24 files changed

Lines changed: 43 additions & 22 deletions

‎packages/cloudflare/src/durableobject.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { RPC } from '@sentry/conventions/op';
33
import { isObjectLike } from '@sentry/core';
44
import type { DurableObject } from 'cloudflare:workers';
5-
import { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/no-diagnostic-channels';
5+
import { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/async-context';
66
import type { CloudflareOptions } from './client';
77
import { getInstrumented, markAsInstrumented } from './instrument';
88
import { instrumentDurableObjectHandlers } from './instrumentations/instrumentDurableObjectHandlers';

‎packages/cloudflare/src/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,4 @@ export {
137137

138138
export { instrumentWorkflowWithSentry } from './workflows';
139139

140-
export { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/no-diagnostic-channels';
140+
export { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/async-context';

‎packages/cloudflare/src/instrumentations/instrumentWorkerEntrypoint.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { RpcStub, WorkerEntrypoint } from 'cloudflare:workers';
22
import { RPC } from '@sentry/conventions/op';
3-
import { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/no-diagnostic-channels';
3+
import { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/async-context';
44
import type { CloudflareOptions } from '../client';
55
import { getFinalOptions } from '../options';
66
import type { DefaultEnv, ResolveEnv, StrictCloudflareOptions } from '../types';

‎packages/cloudflare/src/pages-plugin.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/no-diagnostic-channels';
1+
import { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/async-context';
22
import type { CloudflareOptions } from './client';
33
import type { ExecutionContextCompat } from './executionContext';
44
import { wrapRequestHandlerWithInit } from './wrapRequestHandlerWithInit';

‎packages/cloudflare/src/withSentry.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/no-diagnostic-channels';
1+
import { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/async-context';
22
import { instrumentExportedHandlerEmail } from './instrumentations/worker/instrumentEmail';
33
import { instrumentExportedHandlerFetch } from './instrumentations/worker/instrumentFetch';
44
import { instrumentExportedHandlerQueue } from './instrumentations/worker/instrumentQueue';

‎packages/cloudflare/src/workflows.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import type {
2222
WorkflowStepRollbackOptions,
2323
WorkflowTimeoutDuration,
2424
} from 'cloudflare:workers';
25-
import { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/no-diagnostic-channels';
25+
import { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/async-context';
2626
import type { CloudflareOptions } from './client';
2727
import { flushAndDispose, getOriginalWaitUntil } from './flush';
2828
import { instrumentEnv } from './instrumentations/worker/instrumentEnv';

‎packages/cloudflare/test/client.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
2-
import { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/no-diagnostic-channels';
2+
import { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/async-context';
33
import { CloudflareClient, type CloudflareClientOptions } from '../src/client';
44
import { makeFlushLock } from '../src/flush';
55
import { getInvocationState } from '../src/utils/invocationContext';

‎packages/cloudflare/test/instrumentCloudflareAgent.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
startSpan,
99
} from '@sentry/core';
1010
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
11-
import { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/no-diagnostic-channels';
11+
import { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/async-context';
1212
import { CloudflareClient, type CloudflareClientOptions } from '../src/client';
1313
import { withStaticSpan } from '../src/index';
1414
import { instrumentCloudflareAgent } from '../src/instrumentations/agents';

‎packages/cloudflare/test/instrumentations/instrumentWorkerEntrypoint.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ describe('instrumentWorkerEntrypoint', () => {
176176
});
177177

178178
it('Calls setAsyncLocalStorageAsyncContextStrategy outside Proxy (at instrumentation time), not inside construct', async () => {
179-
const asyncModule = await import('@sentry/server-utils/no-diagnostic-channels');
179+
const asyncModule = await import('@sentry/server-utils/async-context');
180180
const setStrategy = vi.spyOn(asyncModule, 'setAsyncLocalStorageAsyncContextStrategy');
181181
const mockContext = createMockExecutionContext();
182182
const TestClass = class extends WorkerEntrypoint {

‎packages/cloudflare/test/opentelemetry.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { trace } from '@opentelemetry/api';
22
import type { TransactionEvent } from '@sentry/core';
33
import { getActiveSpan, spanToJSON, startSpan } from '@sentry/core';
4-
import { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/no-diagnostic-channels';
4+
import { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/async-context';
55
import { beforeEach, describe, expect, test, vi } from 'vitest';
66
import type { CloudflareOptions } from '../src/client';
77
import { wrapRequestHandler } from '../src/request';

0 commit comments

Comments
 (0)