-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(cloudflare): Derive rpcTracePropagationTargets from the wrangler config #23491
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
Draft
JPeer264
wants to merge
1
commit into
jp/rpc-trace-propagation-targets
from
jp/rpc-trace-propagation-targets-vite
Draft
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
31 changes: 31 additions & 0 deletions
31
...ckages/cloudflare-integration-tests/suites/vite-autoinstrument/durableobject-rpc/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,31 @@ | ||
| import { DurableObject } from 'cloudflare:workers'; | ||
|
|
||
| interface Env { | ||
| SENTRY_DSN: string; | ||
| COUNTER: DurableObjectNamespace<Counter>; | ||
| } | ||
|
|
||
| // Nothing is wrapped manually, the Vite plugin wraps both exports and enables RPC trace | ||
| // propagation for `COUNTER` on its own. | ||
| export class Counter extends DurableObject<Env> { | ||
| // An uninstrumented receiver would see Sentry's RPC metadata in the trailing optional parameter, | ||
| // see https://github.com/getsentry/sentry-javascript/issues/23233. | ||
| async increment(by: number, _unused?: number): Promise<{ count: number; argumentCount: number }> { | ||
| const count = ((await this.ctx.storage.get<number>('count')) ?? 0) + by; | ||
| await this.ctx.storage.put('count', count); | ||
| return { count, argumentCount: arguments.length }; | ||
| } | ||
| } | ||
|
|
||
| export default { | ||
| async fetch(request: Request, env: Env): Promise<Response> { | ||
| const url = new URL(request.url); | ||
|
|
||
| if (url.pathname === '/increment') { | ||
| const stub = env.COUNTER.get(env.COUNTER.idFromName('e2e')); | ||
| return Response.json(await stub.increment(1)); | ||
| } | ||
|
|
||
| return new Response('Not found', { status: 404 }); | ||
| }, | ||
| } satisfies ExportedHandler<Env>; |
8 changes: 8 additions & 0 deletions
8
...flare-integration-tests/suites/vite-autoinstrument/durableobject-rpc/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,8 @@ | ||
| import { defineCloudflareOptions } from '@sentry/cloudflare'; | ||
|
|
||
| // `rpcTracePropagationTargets` is deliberately absent, the Vite plugin derives `COUNTER` on its own. | ||
| export default defineCloudflareOptions((env: { SENTRY_DSN: string }) => ({ | ||
| dsn: env.SENTRY_DSN, | ||
| traceLifecycle: 'static', | ||
| tracesSampleRate: 1.0, | ||
| })); |
31 changes: 31 additions & 0 deletions
31
...ackages/cloudflare-integration-tests/suites/vite-autoinstrument/durableobject-rpc/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,31 @@ | ||
| import type { TransactionEvent } from '@sentry/core'; | ||
| import { expect, it } from 'vitest'; | ||
| import { createRunner } from '../../../runner'; | ||
|
|
||
| it('propagates the trace over a Durable Object RPC call without configuring the binding', async ({ signal }) => { | ||
| let workerTraceId: string | undefined; | ||
| let doTraceId: string | undefined; | ||
|
|
||
| const runner = createRunner(__dirname) | ||
| .unordered() | ||
| .expect(envelope => { | ||
| const transactionEvent = envelope[1]?.[0]?.[1] as TransactionEvent; | ||
| expect(transactionEvent.contexts?.trace?.op).toBe('rpc'); | ||
| doTraceId = transactionEvent.contexts?.trace?.trace_id; | ||
| }) | ||
| .expect(envelope => { | ||
| const transactionEvent = envelope[1]?.[0]?.[1] as TransactionEvent; | ||
| expect(transactionEvent.contexts?.trace?.op).toBe('http.server'); | ||
| workerTraceId = transactionEvent.contexts?.trace?.trace_id; | ||
| }) | ||
| .start(signal); | ||
|
|
||
| // `argumentCount` proves the receiver stripped the metadata argument again. | ||
| const response = await runner.makeRequest<{ count: number; argumentCount: number }>('get', '/increment'); | ||
| expect(response).toEqual({ count: 1, argumentCount: 1 }); | ||
|
|
||
| await runner.completed(); | ||
|
|
||
| expect(workerTraceId).toBeDefined(); | ||
| expect(doTraceId).toBe(workerTraceId); | ||
| }); |
8 changes: 8 additions & 0 deletions
8
...cloudflare-integration-tests/suites/vite-autoinstrument/durableobject-rpc/vite.config.mts
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,8 @@ | ||
| import { cloudflare } from '@cloudflare/vite-plugin'; | ||
| import { sentryCloudflareVitePlugin } from '@sentry/cloudflare/vite'; | ||
| import { defineConfig } from 'vite'; | ||
|
|
||
| export default defineConfig({ | ||
| // The Sentry transform wraps the entry before the Cloudflare plugin bundles it. | ||
| plugins: [cloudflare(), sentryCloudflareVitePlugin()], | ||
| }); |
12 changes: 12 additions & 0 deletions
12
.../cloudflare-integration-tests/suites/vite-autoinstrument/durableobject-rpc/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,12 @@ | ||
| { | ||
| "$schema": "../../../node_modules/wrangler/config-schema.json", | ||
| "name": "cloudflare-vite-autoinstrument-durableobject-rpc", | ||
| // `main` points at the source entry so the auto-instrument transform runs during the build. | ||
| "main": "index.ts", | ||
| "compatibility_date": "2025-06-17", | ||
| "compatibility_flags": ["nodejs_compat"], | ||
| "durable_objects": { | ||
| "bindings": [{ "name": "COUNTER", "class_name": "Counter" }], | ||
| }, | ||
| "migrations": [{ "tag": "v1", "new_sqlite_classes": ["Counter"] }], | ||
| } |
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
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed self-binding on default re-export
Medium Severity
When
export default AlreadyWrappedClassskips wrapping because the class was already auto-wrapped as a named export,undefinedis never added toautoWrapped. Entrypoint-less self service bindings useclassName: undefined, so they are filtered out ofrpcTracePropagationTargetseven though the default export is the instrumented class and would strip the trailing RPC metadata.Additional Locations (1)
packages/cloudflare/src/vite/transform.ts#L246-L249Reviewed by Cursor Bugbot for commit a85e9fb. Configure here.