Issue
I need to disable or enable Sentry dynamically based on certain criteria in my application. How can I achieve this?
Applies To
- Anyone using a JS SDK
Resolution
Dynamically enabling and disabling Sentry completely is not officially supported and is generally not recommended. Doing so may lead to the creation of multiple client instances, which can cause unexpected behavior.
That said, you can use the enabled option as a workaround. This option specifies whether the SDK should send events to Sentry.
Note: Setting
enabled: false
only disables the transport layer and stops data from being sent to Sentry. It does not remove all instrumentation or eliminate runtime overhead.