Skip to content

Commit b7f8678

Browse files
JPeer264claude
andcommitted
test(e2e): Port cloudflare-local-workers to span streaming
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 8278f63 commit b7f8678

2 files changed

Lines changed: 33 additions & 16 deletions

File tree

‎dev-packages/e2e-tests/test-applications/cloudflare-local-workers/src/index.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class MyDurableObjectBase extends DurableObject<Env> {
2222

2323
export const MyDurableObject = Sentry.instrumentDurableObjectWithSentry(
2424
(env: Env) => ({
25-
traceLifecycle: 'static',
2625
dsn: env.E2E_TEST_DSN,
2726
environment: 'qa', // dynamic sampling bias to keep transactions
2827
tunnel: `http://localhost:3031/`, // proxy server
@@ -33,7 +32,6 @@ export const MyDurableObject = Sentry.instrumentDurableObjectWithSentry(
3332

3433
export default Sentry.withSentry(
3534
(env: Env) => ({
36-
traceLifecycle: 'static',
3735
dsn: env.E2E_TEST_DSN,
3836
environment: 'qa', // dynamic sampling bias to keep transactions
3937
tunnel: `http://localhost:3031/`, // proxy server
Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect, test } from '@playwright/test';
2-
import { waitForTransaction } from '@sentry-internal/test-utils';
2+
import { collectStreamedSpans, getSpanOp } from '@sentry-internal/test-utils';
33

44
/**
55
* This must be the only test in here.
@@ -10,24 +10,43 @@ import { waitForTransaction } from '@sentry-internal/test-utils';
1010
* and masks bugs in our instrumentation - causing this test to pass when it
1111
* should fail.
1212
*/
13-
test('Worker and Durable Object both send transactions when worker calls DO', async ({ baseURL }) => {
14-
const workerTransactionPromise = waitForTransaction('cloudflare-local-workers', event => {
15-
return event.transaction === 'GET /pass-to-object/storage/get' && event.contexts?.trace?.op === 'http.server';
16-
});
17-
18-
const doTransactionPromise = waitForTransaction('cloudflare-local-workers', event => {
19-
return event.transaction === 'GET /storage/get' && event.contexts?.trace?.op === 'http.server';
13+
test('Worker and Durable Object both send segment spans when worker calls DO', async ({ baseURL }) => {
14+
// With span streaming, URL-sourced `http.server` spans are named by method only, so the worker
15+
// and the Durable Object segment can only be told apart by `url.path`.
16+
const spansPromise = collectStreamedSpans('cloudflare-local-workers', spans => {
17+
return (
18+
spans.some(
19+
span =>
20+
getSpanOp(span) === 'http.server' &&
21+
span.is_segment &&
22+
span.attributes['url.path']?.value === '/pass-to-object/storage/get',
23+
) &&
24+
spans.some(
25+
span =>
26+
getSpanOp(span) === 'http.server' && span.is_segment && span.attributes['url.path']?.value === '/storage/get',
27+
)
28+
);
2029
});
2130

2231
const response = await fetch(`${baseURL}/pass-to-object/storage/get`);
2332
expect(response.status).toBe(200);
2433

25-
const [workerTransaction, doTransaction] = await Promise.all([workerTransactionPromise, doTransactionPromise]);
34+
const spans = await spansPromise;
35+
const workerSpan = spans.find(
36+
span =>
37+
getSpanOp(span) === 'http.server' &&
38+
span.is_segment &&
39+
span.attributes['url.path']?.value === '/pass-to-object/storage/get',
40+
)!;
41+
const doSpan = spans.find(
42+
span =>
43+
getSpanOp(span) === 'http.server' && span.is_segment && span.attributes['url.path']?.value === '/storage/get',
44+
)!;
2645

27-
expect(workerTransaction.transaction).toBe('GET /pass-to-object/storage/get');
28-
expect(workerTransaction.contexts?.trace?.op).toBe('http.server');
46+
expect(workerSpan.name).toBe('GET');
47+
expect(workerSpan.attributes['sentry.segment.name.source']?.value).toBe('url');
2948

30-
expect(doTransaction.transaction).toBe('GET /storage/get');
31-
expect(doTransaction.contexts?.trace?.op).toBe('http.server');
32-
expect(doTransaction.spans?.some(span => span.op === 'db')).toBe(true);
49+
expect(doSpan.name).toBe('GET');
50+
expect(doSpan.attributes['sentry.segment.name.source']?.value).toBe('url');
51+
expect(spans.some(span => getSpanOp(span) === 'db' && span.parent_span_id === doSpan.span_id)).toBe(true);
3352
});

0 commit comments

Comments
 (0)