Skip to content
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

How to disable Sentry again at runtime? #2039

Closed
4 of 8 tasks
felixfbecker opened this issue Apr 25, 2019 · 16 comments
Closed
4 of 8 tasks

How to disable Sentry again at runtime? #2039

felixfbecker opened this issue Apr 25, 2019 · 16 comments

Comments

@felixfbecker
Copy link

Package + Version

  • @sentry/browser
  • @sentry/node
  • raven-js
  • raven-node (raven for node)
  • other:

Description

We allow to enable or disable error reporting in our browser extension (which is needed for GDPR). A browser extensions background script is long-running (doesn't re-run at page reloads), so when error reporting is disabled, we need to disable Sentry after it was already enabled with Sentry.init(). I see there is Sentry.init({ enabled: false }) but it doesn't look legal to call Sentry.init() twice. How can I disable Sentry after it was enabled before, at runtime?

@kamilogorek
Copy link
Contributor

#2027 (comment)

@felixfbecker
Copy link
Author

SentryBrowser.getCurrentHub().getClient().getOptions().enabled

That gets me the current value, but how do I change it?

@kamilogorek
Copy link
Contributor

Sentry.getCurrentHub().getClient().getOptions().enabled = false; 😅

@felixfbecker
Copy link
Author

And just to be sure, that will make Sentry stop sending anything to Sentry servers?

@kamilogorek
Copy link
Contributor

Correct -

if (!this._isEnabled()) {
return SyncPromise.reject('SDK not enabled, will not send event.');
}

@HazAT HazAT closed this as completed Apr 29, 2019
@felixfbecker
Copy link
Author

Could you consider this a feature request for something more explicit, or at least a request for official documentation?

@HazAT
Copy link
Member

HazAT commented Apr 29, 2019

@felixfbecker Sure, can you just elaborate why you need this?
Is it some kind of "Ask the user for permission to send crash reports?"?

@felixfbecker
Copy link
Author

As described in the issue description, we need to allow users to opt in and out of error reporting for privacy reasons. Anything that is unclear? Happy to provide more info but not sure what you are looking for

@HazAT
Copy link
Member

HazAT commented Apr 29, 2019

@felixfbecker Sorry, still not fully awake 😅 should have read the initial issue.
We will add something like Sentry.setEnabled(boolean) it makes perfect sense to have something like this. We also got some reports for other SDKs already.

Just for the record, there are other ways of handling this (e.g. beforeSend) besides what Kamil posted but they are all not really convenient.

@vsvipul
Copy link

vsvipul commented Apr 30, 2019

Why is this issue closed if this feature request is in the works ?

@diegolanda
Copy link

Any updates on providing the Sentry.setEnabled(boolean) to toggle error reports on/off?

In Raven I think you had shouldSendCallback to toggle reporting

@kamilogorek
Copy link
Contributor

In Raven I think you had shouldSendCallback to toggle reporting

Sentry.init({
  beforeSend(event) {
    if (shouldSendEvent) return event;
    return null;
  }
});

Any updates on providing the Sentry.setEnabled(boolean) to toggle error reports on/off?

What's your use-case specifically? It's already possible to conditionally drop and/or enable/disable sdk.

@diegolanda
Copy link

Thanks, I couldn't find on the docs if actually sending null would prevent the sdk from reporting errors. this solves my use case

@kamilogorek
Copy link
Contributor

@diegolanda https://docs.sentry.io/error-reporting/configuration/?platform=go#before-send but I agree nothing is not specific enough for javascript 😅

@nathanredblur
Copy link

what about set sampleRate: 0 ?
it's this a safe way to disable sentry ?

@kamilogorek
Copy link
Contributor

It will effectively do the same thing as beforeSend with null, which is dropping all captured events.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants