Skip to content

Commit 46f7431

Browse files
isaacsandreiborza
andauthored
feat(server-utils): Implement setAsyncLocalStorageAsyncContextStrategy (#22889)
This unifies the ACS strategy from cloudflare and deno into server-utils. Eventually this will also be used in node (when not in otel mode). Also, this makes it easier to adjust this in follow ups as there is more centralization now. This also adds an export to server utils package `@sentry/server-utils/no-diagnostic-channel` which can be used e.g. by cloudflare or in the future by vercel-edge, in runtimes where this is not supported. --------- Co-authored-by: Andrei Borza <andrei.borza@sentry.io>
1 parent ecd606e commit 46f7431

24 files changed

Lines changed: 191 additions & 126 deletions

dev-packages/cloudflare-integration-tests/suites/tracing/durableobject-sync-kv/test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const flushMarkerMatcher = (envelope: Envelope): void => {
1313

1414
it('instruments sync KV operations on Durable Object storage', async ({ signal }) => {
1515
const runner = createRunner(__dirname)
16+
.unordered()
1617
.expect(envelope => {
1718
const transactionEvent = envelope[1]?.[0]?.[1] as TransactionEvent | undefined;
1819
const spans = transactionEvent?.spans ?? [];

packages/cloudflare/.oxlintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"message": "Do not import from `@sentry/node` in the Cloudflare SDK. It relies on Node.js APIs that are only available when the `nodejs_compat` flag is set. The only allowed importers are files in `src/nodejs_compat/`, which are exposed via the `@sentry/cloudflare/nodejs_compat/*` entry points."
3535
},
3636
{
37-
"group": ["@sentry/server-utils/**"],
37+
"group": ["@sentry/server-utils/**", "!@sentry/server-utils/no-diagnostic-channels"],
3838
"message": "Do not import from `@sentry/server-utils` in the Cloudflare SDK. It relies on Node.js APIs that are only available when the `nodejs_compat` flag is set. The only allowed importers are files in `src/nodejs_compat/`, which are exposed via the `@sentry/cloudflare/nodejs_compat/*` entry points."
3939
}
4040
]

packages/cloudflare/src/async.ts

Lines changed: 0 additions & 81 deletions
This file was deleted.

packages/cloudflare/src/durableobject.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable @typescript-eslint/unbound-method */
22
import { captureException } from '@sentry/core';
33
import type { DurableObject } from 'cloudflare:workers';
4-
import { setAsyncLocalStorageAsyncContextStrategy } from './async';
4+
import { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/no-diagnostic-channels';
55
import type { CloudflareOptions } from './client';
66
import { ensureInstrumented } from './instrument';
77
import { instrumentEnv } from './instrumentations/worker/instrumentEnv';

packages/cloudflare/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,4 @@ export { instrumentD1WithSentry } from './instrumentations/worker/instrumentD1';
134134

135135
export { instrumentWorkflowWithSentry } from './workflows';
136136

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

packages/cloudflare/src/instrumentations/instrumentWorkerEntrypoint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { RpcStub, WorkerEntrypoint } from 'cloudflare:workers';
2-
import { setAsyncLocalStorageAsyncContextStrategy } from '../async';
2+
import { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/no-diagnostic-channels';
33
import type { CloudflareOptions } from '../client';
44
import { getFinalOptions } from '../options';
55
import { instrumentContext } from '../utils/instrumentContext';

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 './async';
1+
import { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/no-diagnostic-channels';
22
import type { CloudflareOptions } from './client';
33
import type { ExecutionContextCompat } from './executionContext';
44
import { wrapRequestHandler } from './request';

packages/cloudflare/src/withSentry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { env as cloudflareEnv } from 'cloudflare:workers';
2-
import { setAsyncLocalStorageAsyncContextStrategy } from './async';
2+
import { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/no-diagnostic-channels';
33
import type { CloudflareOptions } from './client';
44
import { instrumentExportedHandlerEmail } from './instrumentations/worker/instrumentEmail';
55
import { instrumentExportedHandlerFetch } from './instrumentations/worker/instrumentFetch';

packages/cloudflare/src/workflows.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import type {
2323
WorkflowStepRollbackOptions,
2424
WorkflowTimeoutDuration,
2525
} from 'cloudflare:workers';
26-
import { setAsyncLocalStorageAsyncContextStrategy } from './async';
26+
import { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/no-diagnostic-channels';
2727
import type { CloudflareOptions } from './client';
2828
import { flushAndDispose } from './flush';
2929
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 '../src/async';
2+
import { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/no-diagnostic-channels';
33
import { CloudflareClient, type CloudflareClientOptions } from '../src/client';
44
import { makeFlushLock } from '../src/flush';
55

0 commit comments

Comments
 (0)