Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(javascript): Add entry to migration guide about forcing a sampling decision #10771

Merged
merged 2 commits into from
Jul 18, 2024
Merged
Changes from 1 commit
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,29 @@ 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) => {
if (samplingContext.op === 'function.myFunction') {
return 1;
}
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'}, {/*...*/});
```
Loading