Skip to content
Draft
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 @@ -63,7 +63,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 Down Expand Up @@ -108,7 +107,6 @@ class MyWorker extends WorkerEntrypoint {

export default Sentry.withSentry(
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,11 @@
import { expect, test } from '@playwright/test';
import { waitForError, waitForRequest, waitForTransaction } from '@sentry-internal/test-utils';
import {
getSpanOp,
waitForError,
waitForRequest,
waitForStreamedSpan,
waitForStreamedSpans,
} from '@sentry-internal/test-utils';
import { SDK_VERSION } from '@sentry/cloudflare';
import { WebSocket } from 'ws';

Expand All @@ -9,6 +15,22 @@ test('Index page', async ({ baseURL }) => {
await expect(result.text()).resolves.toBe('Hello World!');
});

test('Sends a streamed span for a basic request', async ({ baseURL }) => {
const spanPromise = waitForStreamedSpan('cloudflare-workersentrypoint', span => {
return getSpanOp(span) === 'http.server' && span.is_segment;
});

await fetch(baseURL!);

const span = await spanPromise;

// The root path is a low-cardinality route, so the span keeps the full `GET /` name under streaming.
expect(span.name).toBe('GET /');
expect(span.trace_id).toMatch(/[a-f0-9]{32}/);
expect(span.status).toBe('ok');
expect(span.attributes['sentry.segment.name.source']?.value).toBe('route');
});

test("worker's withSentry", async ({ baseURL }) => {
const eventWaiter = waitForError('cloudflare-workersentrypoint', event => {
return event.exception?.values?.[0]?.mechanism?.type === 'auto.http.cloudflare';
Expand Down Expand Up @@ -83,19 +105,18 @@ test('sends user-agent header with SDK name and version in envelope requests', a
});
});

test('Storage operations create spans in Durable Object transactions', async ({ baseURL }) => {
const transactionWaiter = waitForTransaction('cloudflare-workersentrypoint', event => {
return event.spans?.some(span => span.op === 'db' && span.description === 'durable_object_storage_put') ?? false;
test('Storage operations create spans in Durable Object', async ({ baseURL }) => {
const spansPromise = waitForStreamedSpans('cloudflare-workersentrypoint', spans => {
return spans.some(span => span.name === 'durable_object_storage_put' && getSpanOp(span) === 'db');
});

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

const transaction = await transactionWaiter;
const putSpan = transaction.spans?.find(span => span.description === 'durable_object_storage_put');
const spans = await spansPromise;
const putSpan = spans.find(span => span.name === 'durable_object_storage_put' && getSpanOp(span) === 'db');

expect(putSpan).toBeDefined();
expect(putSpan?.op).toBe('db');
expect(putSpan?.data?.['db.system.name']).toBe('cloudflare.durable_object.storage');
expect(putSpan?.data?.['db.operation.name']).toBe('put');
expect(putSpan?.attributes['db.system.name']?.value).toBe('cloudflare.durable_object.storage');
expect(putSpan?.attributes['db.operation.name']?.value).toBe('put');
});
Loading