Skip to content

Commit 7b4e60b

Browse files
author
Luca Forstner
committed
Encourage using parentSampleRate for tracesSampler in js
1 parent faf1e71 commit 7b4e60b

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

platform-includes/performance/traces-sampler-as-sampler/javascript.mdx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ interface SamplingContext {
55
name: string;
66
// Initial attributes of the span
77
attributes: SpanAttributes | undefined;
8-
// If the parent span was sampled - undefined if there is no parent span
8+
// If the parent span was sampled - undefined if there is no incoming trace
99
parentSampled: boolean | undefined;
10+
// Sample rate that is coming from the incoming trace - undefined if there is no incoming trace
11+
parentSampleRate: number | undefined;
1012
}
1113

1214
Sentry.init({
@@ -15,7 +17,6 @@ Sentry.init({
1517
tracesSampler: ({ name, attributes, parentSampled }) => {
1618
// Do not sample health checks ever
1719
if (name.includes("healthcheck")) {
18-
// Drop this completely by setting its sample rate to 0%
1920
return 0;
2021
}
2122

@@ -29,13 +30,24 @@ Sentry.init({
2930
return 0.01;
3031
}
3132

32-
// Continue trace decision, if there is any parentSampled information
33-
if (typeof parentSampled === "boolean") {
34-
return parentSampled;
33+
// Inherit the samle rate of the incoming trace if there is one. Sampling is deterministic
34+
// for one entire trace, i.e. if the parent was sampled, we will be sampled too at the same
35+
// rate.
36+
if (typeof parentSampleRate === "number") {
37+
return parentSampleRate;
3538
}
3639

3740
// Else, use default sample rate
3841
return 0.5;
3942
},
4043
});
4144
```
45+
46+
<Alert title="parentSampleRate">
47+
48+
The `parentSampleRate` sampling context was introduced in version 9 of the SDK.
49+
To inherit sampling decisions in earlier versions of the SDK, us the `parentSampled` sampling context.
50+
51+
Going forward, using `parentSampleRate` is strongly encouraged over using `parentSampled`, because it allows for deterministic sampling and metric extrapolation for downstream traces.
52+
53+
</Alert>

0 commit comments

Comments
 (0)