Skip to content

Commit f10c7fe

Browse files
committed
Read the per-request client from inside the worker handler
The Cloudflare SDK calls `init()` inside `withIsolationScope`, so the client is bound to the scope forked for that request. Reading it from outside the handler only worked while the current scope was shared by reference.
1 parent 38d209a commit f10c7fe

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ describe('instrumentWorkerEntrypoint', () => {
216216
const waitUntil = vi.fn();
217217
const TestClass = vi.fn((context: ExecutionContext) => ({
218218
fetch: () => {
219+
// The client is created per request, on the scope forked for that request, so it is only
220+
// reachable from inside the handler.
221+
testClient = SentryCore.getClient();
219222
context.waitUntil(deferred);
220223
return new Response('test');
221224
},
@@ -225,7 +228,6 @@ describe('instrumentWorkerEntrypoint', () => {
225228
const worker = Reflect.construct(instrumented, [context, {}]);
226229

227230
const responsePromise = worker.fetch(new Request('https://example.com'));
228-
testClient = SentryCore.getClient();
229231

230232
const response = await responsePromise;
231233
await response.text();

0 commit comments

Comments
 (0)