You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
With sampling rate 0, transactions are still recorded #16849
Sentry.init({
...
tracesSampler(_){returngetCurrentSamplingRate();// Reads global variable, updated when user data is initialized. We want to only record the paid users},
...
})
Steps to Reproduce
Initialised Sentry with tracesSampler
Added samplingRate as custom attribute
Observed that transactions with sampling Rate 0 are reported in Sentry
Expected Result
Transactions with sampling Rate 0 should be dropped
Actual Result
Transactions with sampling Rate 0 are getting reported to Sentry
Can you provide a minimal reproduction for this bug report? The currently posted code is not enough for us to reproduce this.
Added samplingRate as custom attribute
Observed that transactions with sampling Rate 0 are reported in Sentry
While I'm not 100% sure, I guess you mean that you add a span attribute with the sample rate you attach onto the global variable? Are you reading this variable at exactly the same time as when the tracesSampler callback is called? I'm asking because based on your description, I could see tracesSampler initially returning a >0 rate and the global variable being updated only later to 0 when the root span was already started. Though again, without a reproduction, this is only a wild guess.
In my App component, I am setting the sampling rate based on user_id and their subscription status.
exportfunctiongetCurrentSamplingRate(): number{returnwindow.__SENTRY_TRACES_SAMPLER__??0;}//Calculated in AppComponent. Goal is to sample all transactions of the paid users i.e. samplingRate = 1.0 and others should be dropped (0 sampling rate)functionsetSamplingRate(rate: number): void{window.__SENTRY_TRACES_SAMPLER__=rate;}
One observation is that I am using 0 sampling rate when app is loaded (before my AppComponent is even mounted). This should result in sampling rate 0 and all page load transactions should be dropped. However, I am still seeing pageload events in Sentry dashboard.
Using Traces dashboard, I added sampling_rate column (Query: has:sampling_rate). Can you tell what this represents? Is this the sampling rate for the current span/transaction? This value is not sent from the app.
Update: I tried reproducing this but I cannot find a way how a span/transaction is sent, when tracesSampler correctly returns 0. Since I only have limited information about your app, I made some assumptions how you set things up. See my reproduction attempt repo: https://github.com/Lms24/gh-sentry-javascript-16849-samplerate-0-still-sampled
I also added more explicit tests for our sampling logic (#17055) but to be clear, this was already tested before.
I only have some further guesses what could be potential causes for transactions showing up in Sentry that you wouldn't expect:
if you're in some kind of micro frontend or multi-Sentry-client setup, you might set tracesSampler on the "wrong" client
Are you setting the tracesSampler function directly at Sentry.init time? If you mutate the options retroactively (e.g. redefined the tracesSampler function), this might not propagate to the sampling logic.
the unexpected transactions could come from users who never reloaded the page and therefore have an old SDK config where the sampling logic was different(?)
At this time, we cannot investigate this further, due to lack of reproduction. Please provide your own reproduction or feel free to change mine (see repo link above) so that this becomes reproducible. Thank you!
This issue has gone three weeks without activity. In another week, I will close it.
But! If you comment or otherwise update it, I will reset the clock, and if you remove the label Waiting for: Community, I will leave it alone ... forever!
"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀
Are you setting the tracesSampler function directly at Sentry.init time? If you mutate the options retroactively (e.g. redefined the tracesSampler function), this might not propagate to the sampling logic.
Apologies for the late response. I think this is the issue with my setup. I am redefining it with custom sampling logic. However it is initial set to 0.001. I believe this is never updating.
The sampling_rate column in the traces dashboard added to the further confusion, but it is now clarified in the comment above that its a backend value not set by the javascript sdk.
Activity
Lms24 commentedon Jul 9, 2025
Hey @PankajSati-apl thanks for writing in!
Can you provide a minimal reproduction for this bug report? The currently posted code is not enough for us to reproduce this.
While I'm not 100% sure, I guess you mean that you add a span attribute with the sample rate you attach onto the global variable? Are you reading this variable at exactly the same time as when the
tracesSamplercallback is called? I'm asking because based on your description, I could seetracesSamplerinitially returning a>0rate and the global variable being updated only later to0when the root span was already started. Though again, without a reproduction, this is only a wild guess.PankajSati-apl commentedon Jul 9, 2025
@Lms24
Here is my current setup (Have omitted beforeSend from the snippet)
In my App component, I am setting the sampling rate based on user_id and their subscription status.
One observation is that I am using 0 sampling rate when app is loaded (before my AppComponent is even mounted). This should result in sampling rate 0 and all page load transactions should be dropped. However, I am still seeing
pageloadevents in Sentry dashboard.Using Traces dashboard, I added
sampling_ratecolumn (Query:has:sampling_rate). Can you tell what this represents? Is this the sampling rate for the current span/transaction? This value is not sent from the app.19 remaining items
PankajSati-apl commentedon Jul 14, 2025
Hey @Lms24
Any luck with the issue?
Lms24 commentedon Jul 14, 2025
Not yet, but still on my radar to investigate. I couldn't reproduce this so far.
Lms24 commentedon Jul 17, 2025
Update: I tried reproducing this but I cannot find a way how a span/transaction is sent, when
tracesSamplercorrectly returns0. Since I only have limited information about your app, I made some assumptions how you set things up. See my reproduction attempt repo: https://github.com/Lms24/gh-sentry-javascript-16849-samplerate-0-still-sampledI also added more explicit tests for our sampling logic (#17055) but to be clear, this was already tested before.
I only have some further guesses what could be potential causes for transactions showing up in Sentry that you wouldn't expect:
tracesSampleron the "wrong" clienttracesSamplerfunction directly atSentry.inittime? If you mutate the options retroactively (e.g. redefined thetracesSamplerfunction), this might not propagate to the sampling logic.At this time, we cannot investigate this further, due to lack of reproduction. Please provide your own reproduction or feel free to change mine (see repo link above) so that this becomes reproducible. Thank you!
getsantry commentedon Aug 8, 2025
This issue has gone three weeks without activity. In another week, I will close it.
But! If you comment or otherwise update it, I will reset the clock, and if you remove the label
Waiting for: Community, I will leave it alone ... forever!"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀
PankajSati-apl commentedon Aug 8, 2025
@Lms24
Apologies for the late response. I think this is the issue with my setup. I am redefining it with custom sampling logic. However it is initial set to
0.001. I believe this is never updating.The
sampling_ratecolumn in the traces dashboard added to the further confusion, but it is now clarified in the comment above that its a backend value not set by the javascript sdk.