Skip to content

feat(cloudflare): Support rpc trace propagation for WorkerEntrypoint - #20523

Merged
JPeer264 merged 2 commits into
developfrom
jp/support-workerentrypoint-entirely
May 4, 2026
Merged

feat(cloudflare): Support rpc trace propagation for WorkerEntrypoint#20523
JPeer264 merged 2 commits into
developfrom
jp/support-workerentrypoint-entirely

Conversation

@JPeer264

@JPeer264JPeer264 commented Apr 27, 2026

Copy link
Copy Markdown
Member

closes#15942
closes JS-212

We already have support for WorkerEntrypoint, but they were not yet fully supported because we didn't have trace propagation for them.

This PR basically adds RPC trace propagation (and therefore full support for WorkerEntrypoint) by instrumenting env for the WorkerEntrypoint. The base implementation is pretty straight forward, it is using instrumentEnv and overwrites the env of the entrypoint instance.

The rest are tests and different scenarios showing how it works. Most tests are the same as the normal exported handler tests: worker-do-rpc is the same as workerentrypoint-do-rpc, just with a WorkerEntrypoint rather than the ExportedHandler. The only additional test scenario is worker-workerentrypoint-rpc which showcases if ExportedHandler and WorkerEntrypoint are working out together.

@JPeer264JPeer264 self-assigned this Apr 27, 2026
@linear-code

Copy link
Copy Markdown

@github-actions

github-actionsBot commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize% ChangeChange
@sentry/browser26.16 kB--
@sentry/browser - with treeshaking flags24.63 kB--
@sentry/browser (incl. Tracing)44.13 kB--
@sentry/browser (incl. Tracing + Span Streaming)46.34 kB--
@sentry/browser (incl. Tracing, Profiling)49.08 kB--
@sentry/browser (incl. Tracing, Replay)83.48 kB--
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags72.96 kB--
@sentry/browser (incl. Tracing, Replay with Canvas)88.15 kB--
@sentry/browser (incl. Tracing, Replay, Feedback)100.8 kB--
@sentry/browser (incl. Feedback)43.4 kB--
@sentry/browser (incl. sendFeedback)30.96 kB--
@sentry/browser (incl. FeedbackAsync)36.14 kB--
@sentry/browser (incl. Metrics)27.44 kB--
@sentry/browser (incl. Logs)27.59 kB--
@sentry/browser (incl. Metrics & Logs)28.28 kB--
@sentry/react27.9 kB--
@sentry/react (incl. Tracing)46.36 kB--
@sentry/vue31.03 kB--
@sentry/vue (incl. Tracing)45.96 kB--
@sentry/svelte26.18 kB--
CDN Bundle28.85 kB--
CDN Bundle (incl. Tracing)46.91 kB--
CDN Bundle (incl. Logs, Metrics)30.27 kB--
CDN Bundle (incl. Tracing, Logs, Metrics)48.03 kB--
CDN Bundle (incl. Replay, Logs, Metrics)69.35 kB--
CDN Bundle (incl. Tracing, Replay)84.07 kB--
CDN Bundle (incl. Tracing, Replay, Logs, Metrics)85.14 kB--
CDN Bundle (incl. Tracing, Replay, Feedback)89.86 kB--
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics)90.96 kB--
CDN Bundle - uncompressed84.55 kB--
CDN Bundle (incl. Tracing) - uncompressed140.16 kB--
CDN Bundle (incl. Logs, Metrics) - uncompressed88.75 kB--
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed143.62 kB--
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed212.71 kB--
CDN Bundle (incl. Tracing, Replay) - uncompressed257.96 kB--
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed261.41 kB--
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed271.66 kB--
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed275.1 kB--
@sentry/nextjs (client)48.85 kB--
@sentry/sveltekit (client)44.58 kB--
@sentry/node-core59.06 kB+0.02%+10 B 🔺
@sentry/node170.35 kB+0.01%+12 B 🔺
@sentry/node - without tracing96.92 kB+0.02%+10 B 🔺
@sentry/aws-serverless113.78 kB+0.03%+30 B 🔺
@sentry/cloudflare (withSentry) - minified165.07 kB+0.07%+103 B 🔺
@sentry/cloudflare (withSentry)417.38 kB+0.07%+278 B 🔺

View base workflow run

@JPeer264
JPeer264force-pushed the jp/support-workerentrypoint-entirely branch from 7ea2cd5 to ace755bCompareApril 27, 2026 09:40

@nicohrubecnicohrubec left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks lgtm, just not sure about the test

const response = await runner.makeRequest<string>('get', '/rpc/hello');
expect(response).toBe('Hello, World!');

await runner.completed();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

h: Can we guarantee at this point that we actually get no RPC transaction? I think the runner just terminates as soon as we see the one expected envelope, so if the RPC transaction just arrives later this test will pass fine even though we don't have the behavior we want. If that's the case maybe we can come up with a pattern that makes this stable. Alternatively we could think about removing this E2E app and relying on unit tests to check this.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'll rewrite it and check if both events are arriving but have different trace id's, then we can be 100% sure

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to a .fetch RPC. Now we get a second trace and we can be sure the traces are not connected

@github-actions

Copy link
Copy Markdown
Contributor

👋 @s1gr1d — Please review this PR when you get a chance!

@JPeer264
JPeer264 requested a review from a team as a code ownerApril 30, 2026 18:33
@JPeer264
JPeer264force-pushed the jp/support-workerentrypoint-entirely branch from 11e5f85 to 9b3228aCompareMay 4, 2026 08:38
@JPeer264
JPeer264 requested a review from nicohrubecMay 4, 2026 08:38
});
}

if ('env' in obj) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

env should always be on the obj, right? Maybe it's worth just calling this unconditionally. And for extra safety, wrapping it in a try/catch:

try{Object.defineProperty(obj,'env',{ ... });}catch{}

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not always guaranteed to be there. I like this approach of calling it unconditionally actually.

However, I'd leave it as is for now to be consistent with the code above. Once some performance metrics are added I'd like to see if there are some performance increases with this method.

@JPeer264
JPeer264 merged commit 5f77c76 into developMay 4, 2026
68 checks passed
@JPeer264
JPeer264 deleted the jp/support-workerentrypoint-entirely branch May 4, 2026 09:32
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for Cloudflare WorkerEntrypoint

3 participants

@JPeer264@nicohrubec@s1gr1d