How do you use @sentry/cloudflare with Custom Managed Components? #18911
Unanswered
wuservices
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm excited that Sentry now has an official Cloudflare Workers integration from #13007. I see there is support for various parts of the Cloudflare ecosystem, but didn't see any suggestions for using with a Custom Managed Component - used with Cloudflare Zaraz.
The tricky part here is that you essentially build a specialized worker via managed-component-to-cloudflare-worker. Your code exports a special handler, rather than the
fetchthatwithSentrywould typically instrument. Since you don't have access tofetch, it seems like you can't follow the typical integration pattern.I'm looking for any suggestions or guidance, but so far have a Claude Code assisted solution and summary below that seems to sort of work.
Context
I'm using a Cloudflare Managed Component (via Zaraz/Tag Management). Managed Components don't follow the standard Cloudflare Worker export pattern:
The https://github.com/cloudflare/managed-component-to-cloudflare-worker bundler wraps my component in a standard Worker, but I don't have access to modify that wrapper.
Problem
The
@sentry/cloudflareSDK'swithSentry()wrapper expects the standard Worker API withRequest,Env, andExecutionContext. Since:fetchhandlerinit()function exists in the SDK but isn't exported from the main package indexI needed an alternative initialization approach.
Working Solution
I used
@sentry/coredirectly withServerRuntimeClientinstead ofCloudflareClient:Important:
initSentry()must be called after remappingfetchtomanager.fetchin Managed Components.Questions for Sentry Team
init()from the main package index? This would support Managed Components, Durable Objects, and other non-standard patterns.ServerRuntimeClientdirectly a supported/recommended approach? Or is there a better way?Beta Was this translation helpful? Give feedback.
All reactions