Skip to content

Commit d929920

Browse files
authored
fix(javascript): Add entry to migration guide about forcing a sampling decision (#10771)
1 parent 7c5fbd2 commit d929920

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

docs/platforms/javascript/common/migration/v7-to-v8/v8-new-performance-api.mdx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,35 @@ Sentry.startSpan((span: Span) => {
252252
span.setAttribute("attr", 1);
253253
});
254254
```
255+
256+
### Forcing a sampling decision
257+
258+
Previously in v7, you could force a positive or negative sampling decision when calling `startTransaction` by setting the `sampled` option.
259+
This would effectively override your <PlatformLink to="/configuration/sampling">sampling configuration</PlatformLink> for the specific transaction.
260+
In v8, the `sampled` option was removed to align with OpenTelemetry. You can still force a decision by defining a
261+
`tracesSampler` callback in `Sentry.init` and returning `1` or `0` for specific spans:
262+
263+
```JavaScript
264+
// v7
265+
Sentry.startTransition({op: 'function.myFunction', sampled: true});
266+
267+
// v8
268+
// 1. define a tracesSampler
269+
Sentry.init({
270+
tracesSampler: (samplingContext) => {
271+
// force a positive sampling decision for a specific span
272+
if (samplingContext.op === 'function.myFunction') {
273+
return 1;
274+
}
275+
// force a negative sampling decision for a specific span
276+
if (samplingContext.op === 'function.healthCheck') {
277+
return 0;
278+
}
279+
// return 0.1 as a default sample rate for all other spans
280+
return 0.1;
281+
}
282+
});
283+
284+
// 2. start the span
285+
Sentry.startSpan({op: 'function.myFunction'}, {/*...*/});
286+
```

0 commit comments

Comments
 (0)