Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,35 @@ Sentry.startSpan((span: Span) => {
span.setAttribute("attr", 1);
});
```

### Forcing a sampling decision

Previously in v7, you could force a positive or negative sampling decision when calling `startTransaction` by setting the `sampled` option.
This would effectively override your <PlatformLink to="/configuration/sampling">sampling configuration</PlatformLink> for the specific transaction.
In v8, the `sampled` option was removed to align with OpenTelemetry. You can still force a decision by defining a
`tracesSampler` callback in `Sentry.init` and returning `1` or `0` for specific spans:

```JavaScript
// v7
Sentry.startTransition({op: 'function.myFunction', sampled: true});

// v8
// 1. define a tracesSampler
Sentry.init({
tracesSampler: (samplingContext) => {
// force a positive sampling decision for a specific span
if (samplingContext.op === 'function.myFunction') {
return 1;
}
// force a negative sampling decision for a specific span
if (samplingContext.op === 'function.healthCheck') {
return 0;
}
// return 0.1 as a default sample rate for all other spans
return 0.1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The text above talks about 1 or 0, but there's a value in-between used here. Is that on purpose? I'd probably rewrite the paragraph above if so.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added an example for a positive (1) and negative (0) decision, as well as a comment to show that the 0.1 is used as a default sample rate

}
});

// 2. start the span
Sentry.startSpan({op: 'function.myFunction'}, {/*...*/});
```