File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
docs/platforms/javascript/common/migration/v7-to-v8 Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff 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+ ```
You can’t perform that action at this time.
0 commit comments