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

Change tracesSampleRate after Sentry.init called #3324

Closed
aguynamedben opened this issue Mar 11, 2021 · 5 comments
Closed

Change tracesSampleRate after Sentry.init called #3324

aguynamedben opened this issue Mar 11, 2021 · 5 comments

Comments

@aguynamedben
Copy link

  • Can I alter the tracesSampleRate option after Sentry.init is called?
  • [or] Can I call Sentry.init multiple times to change the value?

I looked at the SDK and don't see an updateOption() that allows option values to be updated after Sentry.init is called.

Options.tracesSampleRate is typed to undefined | number. If there's no method that lets me update the value of options, maybe you could allow the value of tracesSampleRate to be a function so I can dynamically decide what the sample rate is.

Use case: I'd like to remotely control the tracesSampleRate option using our feature flags system. If something goes wrong with the implementation of tracing, we could flip off the feature flag and make tracesSampleRate to go to 0. We build a long-lived Electron app, so we don't call Sentry.init on every page load like some web apps might.

Thanks for building a great product! 🙏

@aguynamedben
Copy link
Author

aguynamedben commented Mar 11, 2021

API ideas

Sentry.updateOption

import * as featureFlags from 'featureFlags';

await feautreFlags.syncFromServer();
Sentry.updateOption({
  tracesSampleRate: featureFlags.get('enableSentryTracing') ? 0.10 : 0,
});

Allow function as tracesSampleRate value

import * as featureFlags from 'featureFlags';

Sentry.init({
  // ...
  tracesSampleRate: () => featureFlags.get('enableSentryTracing')) ? 0.10 : 0,
});

@lobsterkatie
Copy link
Member

lobsterkatie commented Mar 12, 2021

I believe what you're describing is the tracesSampler option, described here (as option 2) and here. 🙂

What this tells me though is that the docs don't make that obvious enough, so we'll work on that. I'm going to close this, but please let me know if your concern hasn't been addressed.

@aguynamedben
Copy link
Author

Ahh! I see it in those docs, but it doesn't seem to be in the SDK/typing docs which I lean on a lot: https://getsentry.github.io/sentry-javascript/interfaces/types.options-1.html

Thanks, I'll give it a try!

@lobsterkatie
Copy link
Member

Oh - that's quite out of date (5.21.1, when current is 6.2.3). Thanks for pointing that out! Will try to get to the bottom of why it's not getting updated.

@aguynamedben
Copy link
Author

FWIW then sentry-electron is also on a pretty old version too (5.27.6) https://github.com/getsentry/sentry-electron/blob/master/package.json#L41 That's how I'm really using this.

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

2 participants