Sampling
Sending a trace for every single page load can be more data than you need. Sampling lets you control the amount of traces that are sent. The SDK is still recording full traces, it's just not sending every single one to Flare. We recommend values between 0.1 and 0.2 to avoid exhausting your trace limit too quickly.
There are two ways to control sampling. Only one of them runs at a time: if you set tracesSampler, it takes over completely and tracesSampleRate is ignored.
tracesSampleRate
A number between 0 and 1. It defaults to 1, meaning every trace is sent. A value outside that range is clamped to that range.
import { flare } from '@flareapp/js';
flare.configure({
enableTracing: true,
tracesSampleRate: 0.2,
});
0.2 sends roughly 1 in 5 traces. Each trace is sampled independently, using a random number, so you can't predict which ones get through, only roughly how many.
tracesSampler
A function that decides sampling itself, instead of using a fixed rate. Set it and it takes precedence over tracesSampleRate:
import { flare } from '@flareapp/js';
flare.configure({
enableTracing: true,
tracesSampler: (ctx) => {
if (ctx.spanType === 'browser_pageload') {
return 1;
}
return 0.1;
},
});
The example above always samples a full page load, but only 1 in 10 navigations after that.
Your function is called with one object describing the span that is about to start a trace:
name: the span's name.attributes: the attributes set on it so far.spanType: its span type, for example'browser_pageload', if it has one.
Return a number between 0 and 1 to sample by chance, the same way tracesSampleRate does. Return true or false instead to force a definite decision for that trace, with no randomness involved. If your function throws, the trace is not sampled.
The decision happens once, per trace
A trace has one root span: the first span in it with no parent. tracesSampler or tracesSampleRate runs exactly once, when that root span is created. Every span added to the trace after that reuses the same decision.
This means a trace is never half sampled. Either every span in it is recorded and sent, or none of them are.