@@ -171,7 +171,7 @@ describe('Hub', () => {
171
171
} ) ;
172
172
173
173
describe ( 'sample()' , ( ) => {
174
- it ( 'should not sample transactions when tracing is disabled' , ( ) => {
174
+ it ( 'should set sampled = false when tracing is disabled' , ( ) => {
175
175
// neither tracesSampleRate nor tracesSampler is defined -> tracing disabled
176
176
const hub = new Hub ( new BrowserClient ( { } ) ) ;
177
177
const transaction = hub . startTransaction ( { name : 'dogpark' } ) ;
@@ -219,7 +219,7 @@ describe('Hub', () => {
219
219
expect ( transaction . sampled ) . toBe ( true ) ;
220
220
} ) ;
221
221
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' , ( ) => {
223
223
// so that the decision otherwise would be false
224
224
const tracesSampler = jest . fn ( ) . mockReturnValue ( 0 ) ;
225
225
const hub = new Hub ( new BrowserClient ( { tracesSampler } ) ) ;
@@ -228,7 +228,7 @@ describe('Hub', () => {
228
228
expect ( transaction . sampled ) . toBe ( true ) ;
229
229
} ) ;
230
230
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' , ( ) => {
232
232
// so that the decision otherwise would be true
233
233
const tracesSampler = jest . fn ( ) . mockReturnValue ( 1 ) ;
234
234
const hub = new Hub ( new BrowserClient ( { tracesSampler } ) ) ;
@@ -255,6 +255,40 @@ describe('Hub', () => {
255
255
expect ( tracesSampler ) . toHaveBeenCalled ( ) ;
256
256
expect ( transaction . sampled ) . toBe ( true ) ;
257
257
} ) ;
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 ( { 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 ( { samplingMethod : 'client_sampler' , 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 ( { 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 ( { samplingMethod : 'client_rate' , sampleRate : '0.1121' } ) ,
290
+ ) ;
291
+ } ) ;
258
292
} ) ;
259
293
260
294
describe ( 'isValidSampleRate()' , ( ) => {
0 commit comments