Skip to content

Commit c90484e

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

2 files changed

Lines changed: 22 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: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { expect, test } from '@playwright/test';
2-
import { waitForTransaction } from '@sentry-internal/test-utils';
2+
import { collectStreamedSpans, getSpanOp } from '@sentry-internal/test-utils';
3+
import type { SerializedStreamedSpan } from '@sentry/core';
4+
5+
function isHttpServerSegment(span: SerializedStreamedSpan, urlPath: string): boolean {
6+
return getSpanOp(span) === 'http.server' && span.is_segment && span.attributes['url.path']?.value === urlPath;
7+
}
38

49
/**
510
* This must be the only test in here.
@@ -10,24 +15,27 @@ import { waitForTransaction } from '@sentry-internal/test-utils';
1015
* and masks bugs in our instrumentation - causing this test to pass when it
1116
* should fail.
1217
*/
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';
18+
test('Worker and Durable Object both send segment spans when worker calls DO', async ({ baseURL }) => {
19+
// With span streaming, URL-sourced `http.server` spans are named by method only, so the worker
20+
// and the Durable Object segment can only be told apart by `url.path`.
21+
const spansPromise = collectStreamedSpans('cloudflare-local-workers', spans => {
22+
return (
23+
spans.some(span => isHttpServerSegment(span, '/pass-to-object/storage/get')) &&
24+
spans.some(span => isHttpServerSegment(span, '/storage/get'))
25+
);
2026
});
2127

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

25-
const [workerTransaction, doTransaction] = await Promise.all([workerTransactionPromise, doTransactionPromise]);
31+
const spans = await spansPromise;
32+
const workerSpan = spans.find(span => isHttpServerSegment(span, '/pass-to-object/storage/get'))!;
33+
const doSpan = spans.find(span => isHttpServerSegment(span, '/storage/get'))!;
2634

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

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);
38+
expect(doSpan.name).toBe('GET');
39+
expect(doSpan.attributes['sentry.segment.name.source']?.value).toBe('url');
40+
expect(spans.some(span => getSpanOp(span) === 'db' && span.parent_span_id === doSpan.span_id)).toBe(true);
3341
});

0 commit comments

Comments
 (0)