Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class MyDurableObjectBase extends DurableObject<Env> {

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

export default Sentry.withSentry(
(env: Env) => ({
traceLifecycle: 'static',
dsn: env.E2E_TEST_DSN,
environment: 'qa', // dynamic sampling bias to keep transactions
tunnel: `http://localhost:3031/`, // proxy server
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from '@playwright/test';
import { waitForTransaction } from '@sentry-internal/test-utils';
import { collectStreamedSpans, getSpanOp } from '@sentry-internal/test-utils';

/**
* This must be the only test in here.
Expand All @@ -10,24 +10,43 @@ import { waitForTransaction } from '@sentry-internal/test-utils';
* and masks bugs in our instrumentation - causing this test to pass when it
* should fail.
*/
test('Worker and Durable Object both send transactions when worker calls DO', async ({ baseURL }) => {
const workerTransactionPromise = waitForTransaction('cloudflare-local-workers', event => {
return event.transaction === 'GET /pass-to-object/storage/get' && event.contexts?.trace?.op === 'http.server';
});

const doTransactionPromise = waitForTransaction('cloudflare-local-workers', event => {
return event.transaction === 'GET /storage/get' && event.contexts?.trace?.op === 'http.server';
test('Worker and Durable Object both send segment spans when worker calls DO', async ({ baseURL }) => {
// With span streaming, URL-sourced `http.server` spans are named by method only, so the worker
// and the Durable Object segment can only be told apart by `url.path`.
const spansPromise = collectStreamedSpans('cloudflare-local-workers', spans => {
return (
spans.some(
span =>
getSpanOp(span) === 'http.server' &&
span.is_segment &&
span.attributes['url.path']?.value === '/pass-to-object/storage/get',
Comment on lines +16 to +22

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The test now uses collectStreamedSpans and assumes the Worker and Durable Object share a trace_id. If the default traceLifecycle behavior doesn't ensure this, the test will hang.
Severity: MEDIUM

Suggested Fix

Explicitly verify the default traceLifecycle behavior in the Cloudflare SDK ensures trace propagation between Workers and Durable Objects in streaming mode. If the default is not what is expected, explicitly set the traceLifecycle option to enable streaming and ensure trace context is propagated correctly.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location:
dev-packages/e2e-tests/test-applications/cloudflare-local-workers/tests/index.test.ts#L16-L22

Potential issue: The e2e test was migrated to use `collectStreamedSpans`, which groups
spans by `trace_id`. The test's predicate requires a span from the Worker and a span
from the Durable Object to be present in the same group, assuming they share a
`trace_id`. The pull request removes the explicit `traceLifecycle: 'static'`
configuration. If the default behavior in the Cloudflare SDK doesn't enable streaming or
if trace propagation between the Worker and DO is altered by this change, the spans
might get different `trace_id`s. As a result, the test predicate will never be
satisfied, causing the test to hang and eventually time out.

Also affects:

  • dev-packages/e2e-tests/test-applications/cloudflare-local-workers/src/index.ts:22~27
  • dev-packages/e2e-tests/test-applications/cloudflare-local-workers/src/index.ts:32~37

Did we get this right? 👍 / 👎 to inform future reviews.

) &&
spans.some(
span =>
getSpanOp(span) === 'http.server' && span.is_segment && span.attributes['url.path']?.value === '/storage/get',
)
);
});

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

const [workerTransaction, doTransaction] = await Promise.all([workerTransactionPromise, doTransactionPromise]);
const spans = await spansPromise;
const workerSpan = spans.find(
span =>
getSpanOp(span) === 'http.server' &&
span.is_segment &&
span.attributes['url.path']?.value === '/pass-to-object/storage/get',
)!;
const doSpan = spans.find(
span =>
getSpanOp(span) === 'http.server' && span.is_segment && span.attributes['url.path']?.value === '/storage/get',
)!;

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

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