Skip to content

With sampling rate 0, transactions are still recorded #16849

Closed

Description

@PankajSati-apl

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/react

SDK Version

9.28.1

Framework Version

18.3.0

Link to Sentry event

No response

Reproduction Example/SDK Setup

Sentry.init({
   ...
    tracesSampler(_) {
      return getCurrentSamplingRate(); // Reads global variable, updated when user data is initialized. We want to only record the paid users
    },
   ...
})

Steps to Reproduce

  1. Initialised Sentry with tracesSampler
  2. Added samplingRate as custom attribute
  3. 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

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Jul 8, 2025
  2. Lms24 commented on Jul 9, 2025

    @Lms24
    Member

    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.

    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.

  3. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Jul 9, 2025
  4. moved this to Waiting for: Community in GitHub Issues with 👀 3on Jul 9, 2025
  5. PankajSati-apl commented on Jul 9, 2025

    @PankajSati-apl
    Author

    @Lms24
    Here is my current setup (Have omitted beforeSend from the snippet)

      Sentry.init({
        environment: process.env.SENTRY_ENV,
        enabled: true, 
        dsn: SENTRY_DSN,
        attachStacktrace: true,
        tracesSampler(_) {
           return getCurrentSamplingRate();
        },
        profilesSampleRate: 0.01,
        ignoreErrors: SentryIgnoreList,
      });

    In my App component, I am setting the sampling rate based on user_id and their subscription status.

    export function getCurrentSamplingRate(): number {
      return window.__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)
    function setSamplingRate(rate: number): void {
      window.__SENTRY_TRACES_SAMPLER__ = rate;
    }

    1. 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.

    2. 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.

    Image
  6. 19 remaining items

  7. self-assigned this
    on Jul 11, 2025
  8. PankajSati-apl commented on Jul 14, 2025

    @PankajSati-apl
    Author

    Hey @Lms24
    Any luck with the issue?

  9. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Jul 14, 2025
  10. Lms24 commented on Jul 14, 2025

    @Lms24
    Member

    Not yet, but still on my radar to investigate. I couldn't reproduce this so far.

  11. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Jul 14, 2025
  12. Lms24 commented on Jul 17, 2025

    @Lms24
    Member

    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!

  13. moved this to Waiting for: Community in GitHub Issues with 👀 3on Jul 17, 2025
  14. getsantry commented on Aug 8, 2025

    @getsantry

    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 🥀

  15. PankajSati-apl commented on Aug 8, 2025

    @PankajSati-apl
    Author

    @Lms24

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions