@@ -171,7 +171,7 @@ describe('Hub', () => {
171171 } ) ;
172172
173173 describe ( 'sample()' , ( ) => {
174- it ( 'should not sample transactions when tracing is disabled' , ( ) => {
174+ it ( 'should set sampled = false when tracing is disabled' , ( ) => {
175175 // neither tracesSampleRate nor tracesSampler is defined -> tracing disabled
176176 const hub = new Hub ( new BrowserClient ( { } ) ) ;
177177 const transaction = hub . startTransaction ( { name : 'dogpark' } ) ;
@@ -219,7 +219,7 @@ describe('Hub', () => {
219219 expect ( transaction . sampled ) . toBe ( true ) ;
220220 } ) ;
221221
222- it ( 'should not try to override positive sampling decision provided in transaction context ' , ( ) => {
222+ it ( 'should not try to override explicitly set positive sampling decision' , ( ) => {
223223 // so that the decision otherwise would be false
224224 const tracesSampler = jest . fn ( ) . mockReturnValue ( 0 ) ;
225225 const hub = new Hub ( new BrowserClient ( { tracesSampler } ) ) ;
@@ -228,7 +228,7 @@ describe('Hub', () => {
228228 expect ( transaction . sampled ) . toBe ( true ) ;
229229 } ) ;
230230
231- it ( 'should not try to override negative sampling decision provided in transaction context ' , ( ) => {
231+ it ( 'should not try to override explicitly set negative sampling decision' , ( ) => {
232232 // so that the decision otherwise would be true
233233 const tracesSampler = jest . fn ( ) . mockReturnValue ( 1 ) ;
234234 const hub = new Hub ( new BrowserClient ( { tracesSampler } ) ) ;
@@ -255,6 +255,40 @@ describe('Hub', () => {
255255 expect ( tracesSampler ) . toHaveBeenCalled ( ) ;
256256 expect ( transaction . sampled ) . toBe ( true ) ;
257257 } ) ;
258+
259+ it ( 'should record sampling method when sampling decision is explicitly set' , ( ) => {
260+ const tracesSampler = jest . fn ( ) . mockReturnValue ( 0.1121 ) ;
261+ const hub = new Hub ( new BrowserClient ( { tracesSampler } ) ) ;
262+ const transaction = hub . startTransaction ( { name : 'dogpark' , sampled : true } ) ;
263+
264+ expect ( transaction . tags ) . toEqual ( expect . objectContaining ( { __sentry_samplingMethod : 'explicitly_set' } ) ) ;
265+ } ) ;
266+
267+ it ( 'should record sampling method and rate when sampling decision comes from tracesSampler' , ( ) => {
268+ const tracesSampler = jest . fn ( ) . mockReturnValue ( 0.1121 ) ;
269+ const hub = new Hub ( new BrowserClient ( { tracesSampler } ) ) ;
270+ const transaction = hub . startTransaction ( { name : 'dogpark' } ) ;
271+
272+ expect ( transaction . tags ) . toEqual (
273+ expect . objectContaining ( { __sentry_samplingMethod : 'client_sampler' , __sentry_sampleRate : '0.1121' } ) ,
274+ ) ;
275+ } ) ;
276+
277+ it ( 'should record sampling method when sampling decision is inherited' , ( ) => {
278+ const hub = new Hub ( new BrowserClient ( { tracesSampleRate : 0.1121 } ) ) ;
279+ const transaction = hub . startTransaction ( { name : 'dogpark' , parentSampled : true } ) ;
280+
281+ expect ( transaction . tags ) . toEqual ( expect . objectContaining ( { __sentry_samplingMethod : 'inheritance' } ) ) ;
282+ } ) ;
283+
284+ it ( 'should record sampling method and rate when sampling decision comes from traceSampleRate' , ( ) => {
285+ const hub = new Hub ( new BrowserClient ( { tracesSampleRate : 0.1121 } ) ) ;
286+ const transaction = hub . startTransaction ( { name : 'dogpark' } ) ;
287+
288+ expect ( transaction . tags ) . toEqual (
289+ expect . objectContaining ( { __sentry_samplingMethod : 'client_rate' , __sentry_sampleRate : '0.1121' } ) ,
290+ ) ;
291+ } ) ;
258292 } ) ;
259293
260294 describe ( 'isValidSampleRate()' , ( ) => {
0 commit comments