tracesSampler not working
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
-
vueOptionsare supposed to be inside thetracingobject (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. - Having functions in the configuration can be problematic in Nuxt. Can you have a look at generated
.nuxt/sentry.client.jsfile and check if the function is properly serialized?
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
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
},
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.
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
You are right.
Alright! thank for the help. Closing this now.
This should be fixed in the module so re-opening.
Actually tracesSampler is not part of the tracing object but as you said config (eventually clientConfig). So it works as expected.