GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test(cloudflare): Add e2e test for the Cloudflare trace id without tracing by JPeer264 · Pull Request #25643 · getsentry/sentry-javascript

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.

Sign up for GitHub

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

Uh oh!

There was an error while loading. Please reload this page.

Merged

test(cloudflare): Add e2e test for the Cloudflare trace id without tracing #25643

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
3fa92a6
test(cloudflare): Add e2e test for the Cloudflare trace id without tr…
JPeer264 Oct 22, 2026
File filter
Filter by extension


Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

1 change: 1 addition & 0 deletions 1 .github/workflows/cleanup-e2e-workers.yml
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
worker-prefix:
- e2e-send-to-sentry
- e2e-flue-send-to-sentry
- e2e-without-tracing-send-to-sentry
steps:
- name: Set up Node
uses: actions/setup-node@v7
Expand Down
2 changes: 2 additions & 0 deletions 2 dev-packages/e2e-tests/.env.example
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ E2E_OPENAI_DECISIONS_API_KEY=
# Cloudflare credentials for E2E tests that deploy a real Worker (e.g. cloudflare-workers-send-to-sentry).
# The API token needs "Workers Scripts: Edit" on the account; "Workers KV Storage: Read" additionally silences a
# warning when a worker is deleted. Leave it empty to use a `wrangler login` session instead.
# Apps that read Workers Logs (e.g. cloudflare-workers-without-tracing-send-to-sentry) need an API token with
# "Workers Observability: Edit".
CLOUDFLARE_API_TOKEN=
CLOUDFLARE_ACCOUNT_ID=
3 changes: 3 additions & 0 deletions 3 dev-packages/e2e-tests/README.md
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ Apps like `cloudflare-workers-send-to-sentry` deploy the built app as a real Wor
`cloudflare-flue-send-to-sentry/src/auth.ts`.
- Add the `workerPrefix` to `.github/workflows/cleanup-e2e-workers.yml`, which deletes the Worker of a PR when the PR
closes.
- To check what Cloudflare stored for a request (for example its Cloudflare trace id), read Workers Logs with
`fetchWorkersLogsEvents`. `CLOUDFLARE_API_TOKEN` then also needs "Workers Observability: Edit". See
`cloudflare-workers-without-tracing-send-to-sentry`.
- Set `"sentryTest": { "optional": true }` in `package.json`, because only the optional CI job has the Cloudflare
secrets.

Expand Down
5 changes: 5 additions & 0 deletions 5 .../e2e-tests/test-applications/cloudflare-workers-without-tracing-send-to-sentry/.gitignore
Show comments
View file
Open in desktop
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
Show comments
View file
Open in desktop
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
Show comments
View file
Open in desktop
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
Show comments
View file
Open in desktop
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
Show comments
View file
Open in desktop
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
Show comments
View file
Open in desktop
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
Show comments
View file
Open in desktop
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
Show comments
View file
Open in desktop
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
Show comments
View file
Open in desktop
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
Show comments
View file
Open in desktop
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;
Comment thread
JPeer264 marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

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
Show comments
View file
Open in desktop
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
Show comments
View file
Open in desktop
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
Show comments
View file
Open in desktop
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
Show comments
View file
Open in desktop
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 } },
}
1 change: 1 addition & 0 deletions 1 dev-packages/test-utils/src/cli.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export interface ApiEvent {
type: string;
data: { values?: { type?: string; value?: string; mechanism?: { type?: string; handled?: boolean } }[] };
}[];
contexts?: { trace?: { trace_id?: string; span_id?: string; parent_span_id?: string } };
}

/** Fetch an error event of the E2E test project. Returns `undefined` while the event is not stored yet. */
Expand Down
56 changes: 56 additions & 0 deletions 56 dev-packages/test-utils/src/cloudflare.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,62 @@ export function workerGlobalTeardown(config: FullConfig): void {
}
}

/** An event of Workers Logs: an invocation, a `console` call, or a span of the Cloudflare trace. */
export interface WorkersLogsEvent {
$metadata: {
/** The `cf-ray` header of the request that the event belongs to. */
rayId?: string;
/** `span` for a span of the Cloudflare trace, `cf-worker-event` for an invocation. */
type?: string;
traceId?: string;
spanId?: string;
};
}

/**
* Returns the Workers Logs events of the last hour with the given values, for example
* `{ '$metadata.rayId': rayId }`. Returns an empty list while the events are not queryable yet.
*
* `CLOUDFLARE_API_TOKEN` needs the "Workers Observability: Edit" permission, which the query endpoint
* requires also for reads. A `wrangler login` session does not have it.
*/
export async function fetchWorkersLogsEvents(values: Record<string, string>): Promise<WorkersLogsEvent[]> {
const now = Date.now();
const response = await fetch(
`https://api.cloudflare.com/client/v4/accounts/${process.env.CLOUDFLARE_ACCOUNT_ID}/workers/observability/telemetry/query`,
{
method: 'POST',
headers: { Authorization: `Bearer ${process.env.CLOUDFLARE_API_TOKEN}`, 'Content-Type': 'application/json' },
body: JSON.stringify({
queryId: 'sentry-e2e-tests',
// Runs the query without saving it to the account.
dry: true,
view: 'events',
limit: 100,
timeframe: { from: now - 60 * 60 * 1000, to: now },
parameters: {
filters: Object.entries(values).map(([key, value]) => ({ key, operation: 'eq', type: 'string', value })),
},
}),
},
);

if (response.status === 429) {
return [];
}

const body = await response.text();

if (!response.ok) {
throw new Error(
`The Workers Logs query failed with status ${response.status}: ${body}. ` +
'CLOUDFLARE_API_TOKEN needs the "Workers Observability: Edit" permission.',
);
}

return (JSON.parse(body) as { result: { events?: { events?: WorkersLogsEvent[] } } }).result.events?.events ?? [];
}

/**
* Sends a request until the Worker itself answers it, and returns the body of that answer.
*
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.