sentry-module icon indicating copy to clipboard operation
sentry-module copied to clipboard

tracesSampler not working

Open fauzymk opened this issue 3 years ago • 8 comments

Version

@nuxtjs/sentry: 5.1.7 nuxt: 2.15.3

Sentry configuration

{
 dsn: 'secret',
 tracing: {
  tracesSampler: (samplingContext) => {
     // equivalent to returning 0
      return false
   },
  vueOptions: {
      tracing: true,
      tracingOptions: {
        hooks: ['mount', 'update'],
        timeout: 2000,
        trackComponents: true,
      },
    },
 }
}

Reproduction Link

Steps to reproduce

What is Expected?

Trace sample rate should use value returned by tracesSampler. In this case tracing should be disabled if traceSampler return false. Returning a number value e.g 0.2 also doesn't work.

What is actually happening?

Trace sample rate value still using default value 1

fauzymk avatar Apr 01 '22 04:04 fauzymk

  1. vueOptions are supposed to be inside the tracing object (see https://sentry.nuxtjs.org/sentry/options#tracing) but since you are just repeating the defaults, it shouldn't make any difference in your case.
  2. Having functions in the configuration can be problematic in Nuxt. Can you have a look at generated .nuxt/sentry.client.js file and check if the function is properly serialized?

rchl avatar Apr 01 '22 07:04 rchl

Hi thanks for the reply

I think the vueOptions is already inside the tracing object. Sorry for the messy code.

I've checked .nuxt/sentry.client.js and I can't find the traceSampler function

fauzymk avatar Apr 01 '22 08:04 fauzymk

If you can't find traceSampler there then it means that Nuxt failed to serialize it. You can try writing it this way instead:

tracesSampler(samplingContext) {
  // equivalent to returning 0
  return false
},

rchl avatar Apr 01 '22 08:04 rchl

Hi unfortunately the issue is still the same. I don't think it's a serialization issue because I tried passing beforeSend hook function and it got serialized successfully both using arrow and non arrow syntax.

fauzymk avatar Apr 01 '22 09:04 fauzymk

Hi i've found the solution. It turns out I need to pass tracesSampler into config instead of tracing object. I thinks it's not yet handled.

https://github.com/nuxt-community/sentry-module/blob/a15416e5047e53896af999d3208f3107470b0a86/lib/core/options.js#L106

fauzymk avatar Apr 01 '22 09:04 fauzymk

You are right.

rchl avatar Apr 01 '22 09:04 rchl

Alright! thank for the help. Closing this now.

fauzymk avatar Apr 01 '22 09:04 fauzymk

This should be fixed in the module so re-opening.

rchl avatar Apr 01 '22 09:04 rchl

Actually tracesSampler is not part of the tracing object but as you said config (eventually clientConfig). So it works as expected.

rchl avatar Aug 26 '22 20:08 rchl