@@ -28,18 +28,6 @@ function traceHeaders(this: Hub): { [key: string]: string } {
2828 return { } ;
2929}
3030
31- /**
32- * Implements sampling inheritance and falls back to user-provided static rate if no parent decision is available.
33- *
34- * @param parentSampled: The parent transaction's sampling decision, if any.
35- * @param givenRate: The rate to use if no parental decision is available.
36- *
37- * @returns The parent's sampling decision (if one exists), or the provided static rate
38- */
39- function _inheritOrUseGivenRate ( parentSampled : boolean | undefined , givenRate : unknown ) : boolean | unknown {
40- return parentSampled !== undefined ? parentSampled : givenRate ;
41- }
42-
4331/**
4432 * Makes a sampling decision for the given transaction and stores it on the transaction.
4533 *
@@ -64,15 +52,33 @@ function sample<T extends Transaction>(hub: Hub, transaction: T, samplingContext
6452
6553 // if the user has forced a sampling decision by passing a `sampled` value in their transaction context, go with that
6654 if ( transaction . sampled !== undefined ) {
55+ transaction . tags = { ...transaction . tags , __sentry_samplingMethod : 'explicitly_set' } ;
6756 return transaction ;
6857 }
6958
7059 // we would have bailed already if neither `tracesSampler` nor `tracesSampleRate` were defined, so one of these should
7160 // work; prefer the hook if so
72- const sampleRate =
73- typeof options . tracesSampler === 'function'
74- ? options . tracesSampler ( samplingContext )
75- : _inheritOrUseGivenRate ( samplingContext . parentSampled , options . tracesSampleRate ) ;
61+ let sampleRate ;
62+ if ( typeof options . tracesSampler === 'function' ) {
63+ sampleRate = options . tracesSampler ( samplingContext ) ;
64+ // cast the rate to a number first in case it's a boolean
65+ transaction . tags = {
66+ ...transaction . tags ,
67+ __sentry_samplingMethod : 'client_sampler' ,
68+ __sentry_sampleRate : String ( Number ( sampleRate ) ) ,
69+ } ;
70+ } else if ( samplingContext . parentSampled !== undefined ) {
71+ sampleRate = samplingContext . parentSampled ;
72+ transaction . tags = { ...transaction . tags , __sentry_samplingMethod : 'inheritance' } ;
73+ } else {
74+ sampleRate = options . tracesSampleRate ;
75+ // cast the rate to a number first in case it's a boolean
76+ transaction . tags = {
77+ ...transaction . tags ,
78+ __sentry_samplingMethod : 'client_rate' ,
79+ __sentry_sampleRate : String ( Number ( sampleRate ) ) ,
80+ } ;
81+ }
7682
7783 // Since this is coming from the user (or from a function provided by the user), who knows what we might get. (The
7884 // only valid values are booleans or numbers between 0 and 1.)
@@ -88,7 +94,7 @@ function sample<T extends Transaction>(hub: Hub, transaction: T, samplingContext
8894 `[Tracing] Discarding transaction because ${
8995 typeof options . tracesSampler === 'function'
9096 ? 'tracesSampler returned 0 or false'
91- : 'tracesSampleRate is set to 0'
97+ : 'a negative sampling decision was inherited or tracesSampleRate is set to 0'
9298 } `,
9399 ) ;
94100 transaction . sampled = false ;
0 commit comments