Description
Problem Statement
This issue is a plea to revisit the feature request #4800.
I came across this request while researching options for changing the sampling rate dynamically without reinitializing the client. During my research I found Sentry discouraged doing this re-initialization and while looking for alternative configuration options I came across tracesSampler
. To my disappointment it was however not available for errors. After a bit of googling I found it was actually dismissed as not planned in the above feature request.
I've asked about alternative designs to this issue in this discussion and listed a few alternatives sentry offers, unfortunately none satisfactory I could find. I believe this is something that is hard enough to byo in user land and would be better done by this new configuration option in sentry.
This errorsSampler
would be a perfect fit as it would allow users to pull in a dynamic value from anywhere (eg. fetching some dynamic configuration from the server) and return it to select a new sample rate. It could also be used to sample certain errors or errors from critical code blocks higher than other errors for example. Imagine a critical payment block where we want to receive 100% of errors, a semi critical search code block where we can get away with 50% to preserve quotas and a non important bloopers page where we still want to get some errors but only if they really occur frequently - let's say 1%.
None of this is possible with beforeSend
unless the client writes a new sampler entirely (completely bypassing sentry's sampler). In that case they could do it with beforeSend
but since tracesSampler
already exists as well this feels like redundant work.
An argument was raised in the original thread that
tracesSampler
was required because traces could not be stopped from being sent inbeforeSend
. I'm not sure I understand that argument since we also havebeforeSendTransaction
which can be used exactly asbeforeSend
to block a trace from being sent. From that one could arguetracesSampler
is then nothing more than syntactic sugar aroundbeforeSendTransaction
as well.
Solution Brainstorm
The following is an example of the proposed api:
import { fetchDynamicSampleRate } from "somewhere";
Sentry.init({
errorsSampler: async () => {
return await fetchDynamicSampleRate();
}
});
This would allow truly dynamic sampling controlled by the client in addition to all the other sampling sentry is already doing.
Alternatively if there are technical limitations or api opposition towards making this method support asynchronous functions a slight adjustment (albeit slightly more cumbersome to work with) on the client's side would still make this possible:
import { pollDynamicSampleRate } from "somewhere";
let dynamicSampleRate = 1;
pollDynamicSampleRate((nextSampleRate) => {
dynamicSampleRate = nextSampleRate;
});
Sentry.init({
errorsSampler: () => {
return dynamicSampleRate;
}
});
I hope the team could at least give some guidance in the docs on how to approach such situations if the decision to not support this configuration option is final. Thank you Sentry Team 🙏
Metadata
Metadata
Assignees
Type
Projects
Status