-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(cloudflare): Enable RPC trace propagation with enableRpcTracePropagation #20345
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
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
60 changes: 60 additions & 0 deletions
60
...cloudflare-integration-tests/suites/tracing/propagation/no-propagation-worker-do/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,60 @@ | ||
| import * as Sentry from '@sentry/cloudflare'; | ||
| import { DurableObject } from 'cloudflare:workers'; | ||
|
|
||
| interface Env { | ||
| SENTRY_DSN: string; | ||
| MY_DURABLE_OBJECT: DurableObjectNamespace; | ||
| MY_QUEUE: Queue; | ||
| } | ||
|
|
||
| class MyDurableObjectBase extends DurableObject<Env> { | ||
| async fetch(_request: Request) { | ||
| return new Response('DO is fine'); | ||
| } | ||
| } | ||
|
|
||
| export const MyDurableObject = Sentry.instrumentDurableObjectWithSentry( | ||
| (env: Env) => ({ | ||
| dsn: env.SENTRY_DSN, | ||
| tracesSampleRate: 1.0, | ||
| }), | ||
| MyDurableObjectBase, | ||
| ); | ||
|
|
||
| export default Sentry.withSentry( | ||
| (env: Env) => ({ | ||
| dsn: env.SENTRY_DSN, | ||
| tracesSampleRate: 1.0, | ||
| }), | ||
| { | ||
| async fetch(request, env) { | ||
| const url = new URL(request.url); | ||
|
|
||
| if (url.pathname === '/queue/send') { | ||
| await env.MY_QUEUE.send({ action: 'test' }); | ||
| return new Response('Queued'); | ||
| } | ||
|
|
||
| const id = env.MY_DURABLE_OBJECT.idFromName('test'); | ||
| const stub = env.MY_DURABLE_OBJECT.get(id); | ||
| const response = await stub.fetch(new Request('http://fake-host/hello')); | ||
| const text = await response.text(); | ||
| return new Response(text); | ||
| }, | ||
|
|
||
| async queue(batch, env, _ctx) { | ||
| const id = env.MY_DURABLE_OBJECT.idFromName('test'); | ||
| const stub = env.MY_DURABLE_OBJECT.get(id); | ||
| for (const message of batch.messages) { | ||
| await stub.fetch(new Request('http://fake-host/hello')); | ||
| message.ack(); | ||
| } | ||
| }, | ||
|
|
||
| async scheduled(controller, env, _ctx) { | ||
| const id = env.MY_DURABLE_OBJECT.idFromName('test'); | ||
| const stub = env.MY_DURABLE_OBJECT.get(id); | ||
| await stub.fetch(new Request('http://fake-host/hello')); | ||
| }, | ||
| } satisfies ExportedHandler<Env>, | ||
| ); |
209 changes: 209 additions & 0 deletions
209
.../cloudflare-integration-tests/suites/tracing/propagation/no-propagation-worker-do/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,209 @@ | ||
| import { expect, it } from 'vitest'; | ||
| import type { Event } from '@sentry/core'; | ||
| import { createRunner } from '../../../../runner'; | ||
|
|
||
| it('does not propagate trace from worker to durable object when enableRpcTracePropagation is disabled', async ({ | ||
| signal, | ||
| }) => { | ||
| let workerTraceId: string | undefined; | ||
| let workerSpanId: string | undefined; | ||
| let doTraceId: string | undefined; | ||
| let doParentSpanId: string | undefined; | ||
|
|
||
| const runner = createRunner(__dirname) | ||
| .expect(envelope => { | ||
| const transactionEvent = envelope[1]?.[0]?.[1] as Event; | ||
|
|
||
| expect(transactionEvent).toEqual( | ||
| expect.objectContaining({ | ||
| contexts: expect.objectContaining({ | ||
| trace: expect.objectContaining({ | ||
| op: 'http.server', | ||
| data: expect.objectContaining({ | ||
| 'sentry.origin': 'auto.http.cloudflare', | ||
| }), | ||
| origin: 'auto.http.cloudflare', | ||
| }), | ||
| }), | ||
| transaction: 'GET /hello', | ||
| }), | ||
| ); | ||
| doTraceId = transactionEvent.contexts?.trace?.trace_id as string; | ||
| doParentSpanId = transactionEvent.contexts?.trace?.parent_span_id as string; | ||
| }) | ||
| .expect(envelope => { | ||
| const transactionEvent = envelope[1]?.[0]?.[1] as Event; | ||
|
|
||
| expect(transactionEvent).toEqual( | ||
| expect.objectContaining({ | ||
| contexts: expect.objectContaining({ | ||
| trace: expect.objectContaining({ | ||
| op: 'http.server', | ||
| data: expect.objectContaining({ | ||
| 'sentry.origin': 'auto.http.cloudflare', | ||
| }), | ||
| origin: 'auto.http.cloudflare', | ||
| }), | ||
| }), | ||
| transaction: 'GET /', | ||
| }), | ||
| ); | ||
| workerTraceId = transactionEvent.contexts?.trace?.trace_id as string; | ||
| workerSpanId = transactionEvent.contexts?.trace?.span_id as string; | ||
| }) | ||
| .unordered() | ||
| .start(signal); | ||
| await runner.makeRequest('get', '/'); | ||
| await runner.completed(); | ||
|
|
||
| expect(workerTraceId).toBeDefined(); | ||
| expect(doTraceId).toBeDefined(); | ||
| expect(workerTraceId).not.toBe(doTraceId); | ||
|
|
||
| expect(workerSpanId).toBeDefined(); | ||
| expect(doParentSpanId).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('does not propagate trace from queue handler to durable object when enableRpcTracePropagation is disabled', async ({ | ||
| signal, | ||
| }) => { | ||
| let queueTraceId: string | undefined; | ||
| let queueSpanId: string | undefined; | ||
| let doTraceId: string | undefined; | ||
| let doParentSpanId: string | undefined; | ||
|
|
||
| const runner = createRunner(__dirname) | ||
| .expect(envelope => { | ||
| const transactionEvent = envelope[1]?.[0]?.[1] as Event; | ||
|
|
||
| expect(transactionEvent).toEqual( | ||
| expect.objectContaining({ | ||
| contexts: expect.objectContaining({ | ||
| trace: expect.objectContaining({ | ||
| op: 'http.server', | ||
| data: expect.objectContaining({ | ||
| 'sentry.origin': 'auto.http.cloudflare', | ||
| }), | ||
| origin: 'auto.http.cloudflare', | ||
| }), | ||
| }), | ||
| transaction: 'GET /hello', | ||
| }), | ||
| ); | ||
| doTraceId = transactionEvent.contexts?.trace?.trace_id as string; | ||
| doParentSpanId = transactionEvent.contexts?.trace?.parent_span_id as string; | ||
| }) | ||
| .expect(envelope => { | ||
| const transactionEvent = envelope[1]?.[0]?.[1] as Event; | ||
|
|
||
| expect(transactionEvent).toEqual( | ||
| expect.objectContaining({ | ||
| contexts: expect.objectContaining({ | ||
| trace: expect.objectContaining({ | ||
| op: 'queue.process', | ||
| data: expect.objectContaining({ | ||
| 'sentry.origin': 'auto.faas.cloudflare.queue', | ||
| }), | ||
| origin: 'auto.faas.cloudflare.queue', | ||
| }), | ||
| }), | ||
| transaction: 'process my-queue', | ||
| }), | ||
| ); | ||
| queueTraceId = transactionEvent.contexts?.trace?.trace_id as string; | ||
| queueSpanId = transactionEvent.contexts?.trace?.span_id as string; | ||
| }) | ||
| // Also expect the fetch transaction from the /queue/send request | ||
| .expect(envelope => { | ||
| const transactionEvent = envelope[1]?.[0]?.[1] as Event; | ||
|
|
||
| expect(transactionEvent).toEqual( | ||
| expect.objectContaining({ | ||
| contexts: expect.objectContaining({ | ||
| trace: expect.objectContaining({ | ||
| op: 'http.server', | ||
| data: expect.objectContaining({ | ||
| 'sentry.origin': 'auto.http.cloudflare', | ||
| }), | ||
| origin: 'auto.http.cloudflare', | ||
| }), | ||
| }), | ||
| transaction: 'GET /queue/send', | ||
| }), | ||
| ); | ||
| }) | ||
| .unordered() | ||
| .start(signal); | ||
| // The fetch handler sends a message to the queue, which triggers the queue consumer | ||
| await runner.makeRequest('get', '/queue/send'); | ||
| await runner.completed(); | ||
|
|
||
| expect(queueTraceId).toBeDefined(); | ||
| expect(doTraceId).toBeDefined(); | ||
| expect(queueTraceId).not.toBe(doTraceId); | ||
|
|
||
| expect(queueSpanId).toBeDefined(); | ||
| expect(doParentSpanId).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('does not propagate trace from scheduled handler to durable object when enableRpcTracePropagation is disabled', async ({ | ||
| signal, | ||
| }) => { | ||
| let scheduledTraceId: string | undefined; | ||
| let scheduledSpanId: string | undefined; | ||
| let doTraceId: string | undefined; | ||
| let doParentSpanId: string | undefined; | ||
|
|
||
| const runner = createRunner(__dirname) | ||
| .withWranglerArgs('--test-scheduled') | ||
| .expect(envelope => { | ||
| const transactionEvent = envelope[1]?.[0]?.[1] as Event; | ||
|
|
||
| expect(transactionEvent).toEqual( | ||
| expect.objectContaining({ | ||
| contexts: expect.objectContaining({ | ||
| trace: expect.objectContaining({ | ||
| op: 'http.server', | ||
| data: expect.objectContaining({ | ||
| 'sentry.origin': 'auto.http.cloudflare', | ||
| }), | ||
| origin: 'auto.http.cloudflare', | ||
| }), | ||
| }), | ||
| transaction: 'GET /hello', | ||
| }), | ||
| ); | ||
| doTraceId = transactionEvent.contexts?.trace?.trace_id as string; | ||
| doParentSpanId = transactionEvent.contexts?.trace?.parent_span_id as string; | ||
| }) | ||
| .expect(envelope => { | ||
| const transactionEvent = envelope[1]?.[0]?.[1] as Event; | ||
|
|
||
| expect(transactionEvent).toEqual( | ||
| expect.objectContaining({ | ||
| contexts: expect.objectContaining({ | ||
| trace: expect.objectContaining({ | ||
| op: 'faas.cron', | ||
| data: expect.objectContaining({ | ||
| 'sentry.origin': 'auto.faas.cloudflare.scheduled', | ||
| }), | ||
| origin: 'auto.faas.cloudflare.scheduled', | ||
| }), | ||
| }), | ||
| }), | ||
| ); | ||
| scheduledTraceId = transactionEvent.contexts?.trace?.trace_id as string; | ||
| scheduledSpanId = transactionEvent.contexts?.trace?.span_id as string; | ||
| }) | ||
| .unordered() | ||
| .start(signal); | ||
| await runner.makeRequest('get', '/__scheduled?cron=*+*+*+*+*'); | ||
| await runner.completed(); | ||
|
|
||
| expect(scheduledTraceId).toBeDefined(); | ||
| expect(doTraceId).toBeDefined(); | ||
| expect(scheduledTraceId).not.toBe(doTraceId); | ||
|
|
||
| expect(scheduledSpanId).toBeDefined(); | ||
| expect(doParentSpanId).toBeUndefined(); | ||
| }); |
39 changes: 39 additions & 0 deletions
39
...lare-integration-tests/suites/tracing/propagation/no-propagation-worker-do/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,39 @@ | ||
| { | ||
| "name": "cloudflare-durable-objects", | ||
| "main": "index.ts", | ||
| "compatibility_date": "2025-06-17", | ||
| "compatibility_flags": ["nodejs_als"], | ||
| "migrations": [ | ||
| { | ||
| "new_sqlite_classes": ["MyDurableObject"], | ||
| "tag": "v1", | ||
| }, | ||
| ], | ||
| "durable_objects": { | ||
| "bindings": [ | ||
| { | ||
| "class_name": "MyDurableObject", | ||
| "name": "MY_DURABLE_OBJECT", | ||
| }, | ||
| ], | ||
| }, | ||
| "queues": { | ||
| "producers": [ | ||
| { | ||
| "binding": "MY_QUEUE", | ||
| "queue": "my-queue", | ||
| }, | ||
| ], | ||
| "consumers": [ | ||
| { | ||
| "queue": "my-queue", | ||
| }, | ||
| ], | ||
| }, | ||
| "triggers": { | ||
| "crons": ["* * * * *"], | ||
| }, | ||
| "vars": { | ||
| "SENTRY_DSN": "https://932e620ee3921c3b4a61c72558ad88ce@o447951.ingest.us.sentry.io/4509553159831552", | ||
| }, | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.