Repository navigation
test(cloudflare): Add e2e test for the Cloudflare trace id without tracing #25643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JPeer264
merged 1 commit into
jp/cloudflare-native-trace-id-events
from
jp/cloudflare-without-tracing-e2e
Nov 16, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
.../e2e-tests/test-applications/cloudflare-workers-without-tracing-send-to-sentry/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| dist | ||
| .wrangler | ||
| node_modules | ||
| test-results | ||
| pnpm-lock.yaml |
3 changes: 3 additions & 0 deletions
3
...tests/test-applications/cloudflare-workers-without-tracing-send-to-sentry/global-setup.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import { createWorkerGlobalSetup } from '@sentry-internal/test-utils/cloudflare'; | ||
|
|
||
| export default createWorkerGlobalSetup({ workerPrefix: 'e2e-without-tracing-send-to-sentry' }); |
1 change: 1 addition & 0 deletions
1
...ts/test-applications/cloudflare-workers-without-tracing-send-to-sentry/global-teardown.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { workerGlobalTeardown as default } from '@sentry-internal/test-utils/cloudflare'; |
34 changes: 34 additions & 0 deletions
34
...2e-tests/test-applications/cloudflare-workers-without-tracing-send-to-sentry/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| { | ||
| "name": "cloudflare-workers-without-tracing-send-to-sentry", | ||
| "version": "0.0.0", | ||
| "private": true, | ||
| "type": "module", | ||
| "scripts": { | ||
| "build": "vite build", | ||
| "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.node.json", | ||
| "test": "playwright test", | ||
| "clean": "npx rimraf node_modules pnpm-lock.yaml dist .wrangler", | ||
| "test:build": "pnpm install && pnpm build", | ||
| "test:assert": "pnpm typecheck && pnpm test" | ||
| }, | ||
| "dependencies": { | ||
| "@sentry/cloudflare": "file:../../packed/sentry-cloudflare-packed.tgz" | ||
| }, | ||
| "devDependencies": { | ||
| "@cloudflare/vite-plugin": "^1.47.0", | ||
| "@cloudflare/workers-types": "^5.20260727.1", | ||
| "@playwright/test": "1.64.1", | ||
| "@sentry-internal/test-utils": "file:../../packed/sentry-internal-test-utils-packed.tgz", | ||
| "@types/node": "^26.1.2", | ||
| "sentry": "~0.44.1", | ||
| "typescript": "~6.0.3", | ||
| "vite": "^8.1.5", | ||
| "wrangler": "^4.114.0" | ||
| }, | ||
| "volta": { | ||
| "extends": "../../package.json" | ||
| }, | ||
| "sentryTest": { | ||
| "optional": true | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
.../test-applications/cloudflare-workers-without-tracing-send-to-sentry/playwright.config.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { getPlaywrightConfig } from '@sentry-internal/test-utils'; | ||
|
|
||
| const config = getPlaywrightConfig(undefined, { | ||
| // The tests read what arrived in Sentry through the sentry CLI, so there is no event proxy to start. | ||
| webServer: undefined, | ||
| // The worker is deployed once for the whole run and deleted again afterwards. | ||
| globalSetup: './global-setup.ts', | ||
| globalTeardown: './global-teardown.ts', | ||
| // A test polls Workers Logs and then Sentry, each for up to 180s. | ||
| timeout: 400_000, | ||
| }); | ||
|
|
||
| export default config; |
4 changes: 4 additions & 0 deletions
4
...s/test-applications/cloudflare-workers-without-tracing-send-to-sentry/pnpm-workspace.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| allowBuilds: | ||
| esbuild: true | ||
| workerd: true | ||
| minimumReleaseAge: 0 |
3 changes: 3 additions & 0 deletions
3
...2e-tests/test-applications/cloudflare-workers-without-tracing-send-to-sentry/src/env.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| interface Env { | ||
| E2E_TEST_DSN: string; | ||
| } |
16 changes: 16 additions & 0 deletions
16
...2e-tests/test-applications/cloudflare-workers-without-tracing-send-to-sentry/src/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import * as Sentry from '@sentry/cloudflare'; | ||
|
|
||
| export default { | ||
| async fetch(request) { | ||
| switch (new URL(request.url).pathname) { | ||
| case '/test-error': { | ||
| const eventId = Sentry.captureException(new Error('E2E test error in a Cloudflare trace')); | ||
| // Workers Logs store the `cf-ray` of the request with the invocation, so the test finds the Cloudflare trace | ||
| // with it. | ||
| return Response.json({ eventId, rayId: request.headers.get('cf-ray') }); | ||
| } | ||
| default: | ||
| return new Response('Hello World!'); | ||
| } | ||
| }, | ||
| } satisfies ExportedHandler<Env>; |
5 changes: 5 additions & 0 deletions
5
...t-applications/cloudflare-workers-without-tracing-send-to-sentry/src/instrument.server.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { defineCloudflareOptions } from '@sentry/cloudflare'; | ||
|
|
||
| export default defineCloudflareOptions((env: Env) => ({ | ||
| dsn: env.E2E_TEST_DSN, | ||
| })); |
36 changes: 36 additions & 0 deletions
36
...plications/cloudflare-workers-without-tracing-send-to-sentry/tests/send-to-sentry.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { expect, test } from '@playwright/test'; | ||
| import { EVENT_POLLING_OPTIONS, fetchEvent, traceTarget } from '@sentry-internal/test-utils/cli'; | ||
| import type { ApiEvent } from '@sentry-internal/test-utils/cli'; | ||
| import { fetchFromWorker, fetchWorkersLogsEvents } from '@sentry-internal/test-utils/cloudflare'; | ||
| import type { WorkersLogsEvent } from '@sentry-internal/test-utils/cloudflare'; | ||
|
|
||
| // Set by global-setup.ts once the worker for this run is deployed. | ||
| const workerUrl = process.env.E2E_TEST_WORKER_URL; | ||
|
|
||
| test('Sends an error in the Cloudflare trace to Sentry', async () => { | ||
| const { eventId, rayId }: { eventId: string; rayId: string } = JSON.parse( | ||
| await fetchFromWorker(`${workerUrl}/test-error`, 200), | ||
| ); | ||
|
|
||
| // The span of the request is the root span of the Cloudflare trace, and the only span with the `cf-ray` of the | ||
| // request. | ||
| let cloudflareSpans: WorkersLogsEvent[] = []; | ||
| await expect | ||
| .poll( | ||
| async () => | ||
| (cloudflareSpans = await fetchWorkersLogsEvents({ '$metadata.rayId': rayId, '$metadata.type': 'span' })), | ||
| EVENT_POLLING_OPTIONS, | ||
| ) | ||
| .toHaveLength(1); | ||
| const { traceId, spanId } = cloudflareSpans[0]!.$metadata; | ||
| expect(traceId).toEqual(expect.stringMatching(/^[\da-f]{32}$/)); | ||
| expect(spanId).toEqual(expect.stringMatching(/^[\da-f]{16}$/)); | ||
|
|
||
| console.log(`Polling for error eventId ${eventId}: sentry trace view ${traceTarget(traceId!)}`); | ||
|
|
||
| let event: ApiEvent | undefined; | ||
| await expect.poll(() => (event = fetchEvent(eventId)), EVENT_POLLING_OPTIONS).toBeDefined(); | ||
|
|
||
| expect(event?.contexts?.trace?.trace_id).toBe(traceId); | ||
| expect(event?.contexts?.trace?.parent_span_id).toBe(spanId); | ||
| }); | ||
16 changes: 16 additions & 0 deletions
16
...e-tests/test-applications/cloudflare-workers-without-tracing-send-to-sentry/tsconfig.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "target": "es2023", | ||
| "lib": ["es2023"], | ||
| "module": "es2022", | ||
| "moduleResolution": "bundler", | ||
| "types": ["@cloudflare/workers-types", "node"], | ||
| "skipLibCheck": true, | ||
| "noEmit": true, | ||
| "isolatedModules": true, | ||
| "allowSyntheticDefaultImports": true, | ||
| "forceConsistentCasingInFileNames": true, | ||
| "strict": true | ||
| }, | ||
| "include": ["src/**/*", "vite.config.ts"] | ||
| } |
7 changes: 7 additions & 0 deletions
7
...ts/test-applications/cloudflare-workers-without-tracing-send-to-sentry/tsconfig.node.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "extends": "./tsconfig.json", | ||
| "compilerOptions": { | ||
| "types": ["node"] | ||
| }, | ||
| "include": ["tests/**/*", "global-setup.ts", "global-teardown.ts", "playwright.config.ts"] | ||
| } |
7 changes: 7 additions & 0 deletions
7
...-tests/test-applications/cloudflare-workers-without-tracing-send-to-sentry/vite.config.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { cloudflare } from '@cloudflare/vite-plugin'; | ||
| import { sentryCloudflareVitePlugin } from '@sentry/cloudflare/vite'; | ||
| import { defineConfig } from 'vite'; | ||
|
|
||
| export default defineConfig({ | ||
| plugins: [cloudflare(), sentryCloudflareVitePlugin()], | ||
| }); |
11 changes: 11 additions & 0 deletions
11
...-tests/test-applications/cloudflare-workers-without-tracing-send-to-sentry/wrangler.jsonc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "$schema": "node_modules/wrangler/config-schema.json", | ||
| // Placeholder only: every test run deploys under a unique name, see global-setup.ts. | ||
| "name": "cloudflare-workers-without-tracing-send-to-sentry", | ||
| "main": "src/index.ts", | ||
| "compatibility_date": "2026-05-20", | ||
| "compatibility_flags": ["nodejs_compat"], | ||
| "workers_dev": true, | ||
| // The tests read the Cloudflare trace of each request from Workers Logs. | ||
| "observability": { "enabled": true, "traces": { "enabled": true } }, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.