sentry icon indicating copy to clipboard operation
sentry copied to clipboard

Managed Components & Cloudflare Zaraz integration

Open POD666 opened this issue 7 months ago • 1 comments

Problem Statement

It seem to be possible to create a Managed Component and install Sentry on a Cloudflare website with a few clicks via Zaraz integration.

I'm especially keen in this to avoid handling user's consent to enable/disable Sentry Reply. But obviously it's important for other Sentry features too.

Please let me know if that is something feasible and if it's in your roadmap (any ETA?).

Solution Brainstorm

I have tried to vibe-code something very quickly and it looks promising but I didn't manage to make it production ready and dropped with a hope you would implement it anyway.

Product Area

Other

POD666 avatar Jun 13 '25 16:06 POD666

Assigning to @getsentry/support for routing ⏲️

getsantry[bot] avatar Jun 13 '25 16:06 getsantry[bot]

Routing to @getsentry/product-owners-replays for triage ⏲️

getsantry[bot] avatar Jun 16 '25 07:06 getsantry[bot]

Maybe using Managed Components is not the best way to respect consent selections with Sentry 😅

I end up with an integration that adjusts configs of a parent sentry instance according to consent selection changes ~https://github.com/POD666/sentry-zaraz-consent-integration~

Looking for some high level feedback 🙏 ignore details pls, it's a bit embarrassing to share at the current stage, blame copilot agent

UPD: Refactored the integration to be generic and consent provider independent and moved to another repo:

  • https://github.com/imviidx/sentry-consent-integration
  • https://github.com/imviidx/sentry-zaraz-consent-integration

POD666 avatar Sep 01 '25 23:09 POD666

Hey @POD666, thanks for creating this integration and sharing your implementation!

Your approach with the consent integration modules looks promising. We appreciate you taking the initiative to build this out.

A few questions to help us understand the use case better:

  1. How are you currently handling the different consent categories (analytics, marketing, etc.) with your integration?
  2. Have you tested this with Sentry's various features beyond Replay (errors, performance monitoring)?
  3. Are there any specific Zaraz/Managed Components APIs that would make this integration smoother if Sentry provided official support?

We'll review this internally to determine if we can provide official Managed Component support. In the meantime, your community solution is a great resource for others with similar needs.

sentaur-athena avatar Sep 04 '25 22:09 sentaur-athena

Hi @sentaur-athena, thanks for your interest in the project!

Here are the answers to your questions:

  1. So I did I few interactions with Gemini, feeding it with the Sentry GDPR PDF (e.g. chat), and end up with following tables for Sentry settings (with proposed "Required Consent Purpose": https://github.com/imviidx/sentry-consent-integration/blob/master/SENTRY.md In short, it defines 4 common consent purposes (functional, analytics, marketing, preferences) and assigns them to related Sentry properties.
  2. I didn't test it well, the demos seem to show correct sentry settings updates but most likely I miss some .stop()/.start() calls here and there.
  3. So it depends and requires the user story:

It started as a simple SPA and at some point of time access to client's local storage is needed. It seem to require GDPR with some "Functional" purpose. So I go to CF Zaraz Consent and setup "Functional" purpose for the feature I need but also I discover other apps available for a few clicks install via Zaraz tag management. So I found no Sentry and started looking into how it could work:

Image
  1. A managed component (MC) could init sentry on a page dynamically on load, missing any previous error. This could help to achieve "a few clicks install". For very basic getting started with Sentry, feels nice. But if sentry replay or other custom configs are required then it requires several consent purposes and CF doesn't have good UI for several purposes per tool.
  2. If a Sentry instance already exists, then it requires external management to be implemented via MC. Should be achievable but I'm not sure about GDPR-breaking events that could happen before MC is loaded. So it sounds like we need a direct sentry integration anyway just to prevent sending any events before MC is loaded.

So I end up with building just the sentry consent integration: Image

It's adjusts sentry configs according to consent limitations and it seem to be flexible enough.

So, using MC for sentry was not the answer to my problem.

At the current stage I'm not sure if grouping sentry configs into "consent purposes" is sustainable in general, would really like to get your official suggestion on consent purposes, their descriptions, related sentry configs... and your opinion on the direction in general of course 🙌

POD666 avatar Sep 06 '25 21:09 POD666

Side note: using Sentry via MC seem to be similar to using Sentry via GTM, feels like unnecessary complexity. So might worth renaming this issue to "Sentry Consent Integrations" or something (just to switch focus). Up to you

POD666 avatar Sep 08 '25 08:09 POD666

Moving forward, It would be a pleasure if my integration is mentioned here: https://sentry.zendesk.com/hc/en-us/articles/37358708239003-How-can-I-delay-replay-recording-until-a-user-consents

*there might be more places, just the first google link

Could you help with TODOs/checklists in such case to make the integration prod ready?

*of course if it makes sense in general when answering the previous comments.

POD666 avatar Sep 11 '25 13:09 POD666

I am not super familiar with Managed Components but would it be possible if you create your own Managed Component where you set up Sentry? It's also possible to manually start a Replay.

However, I am not sure if I understood that correctly - can you "just delay" the initialization of Sentry and put the Sentry init to the Managed Component or does it need very granular configuration of all the permissions?

s1gr1d avatar Sep 15 '25 08:09 s1gr1d

Managed Components are basically CF workers, they are executed on a backend and they receive events and have some access to browser, e.g. execute some code. CF Zaraz offers marketplace for reusable MC, e.g. GA4, Amplitude, etc.

It's kind of GTM but each "Managed Component" is executed in a CF Worker.

Well, if you are more curious about Sentry MC, here is something I played with before switching to just sentry integration: https://github.com/imviidx/sentry-managed-component/blob/main/src/index.ts It seem to be broken now (I tried to clean it up and upgrade but still broken 😅) but by just briefly reviewing the code you could notice some GTM inspired patters. At the end of the day, I could simply use "Custom HTML" injection approach with Sentry CDN loader instead of creating the custom MC. However my goal was not just to init sentry but to adjust it to current consent selection which also comes with CF Zaraz.

does it need very granular configuration of all the permissions?

That is something I'm trying to avoid with the common purposes (functional, analytics, marketing, preferences) in scope of sentry-consent-integration.

POD666 avatar Sep 15 '25 22:09 POD666

Okay so this would involve creating a Sentry Managed Component made available on the Cloudflare Zaraz marketplace. We'll discuss this internally. If someone else is interested in this feature -> You can react with 👍 in the post at the very top which helps us prioritize.


And thanks for providing your repository. I checked out your code and I think you can make this work. However, you're using the Hub which is not available anymore since v8. You can create a client instance based on those docs: https://docs.sentry.io/platforms/javascript/best-practices/multiple-sentry-instances/

s1gr1d avatar Sep 16 '25 07:09 s1gr1d

Great, thanks for checking it.

As I mentioned, I changed the approach to sentry-consent-integration to solve my sentry related consent challenges. Could I get some feedback on that too?

POD666 avatar Sep 17 '25 03:09 POD666

I just took a short look but it seems fine :)

We backlogged this feature for now and we'll see how requested this is until we implement this.

s1gr1d avatar Sep 18 '25 08:09 s1gr1d