Skip to content

Commit e3bab53

Browse files
committed
never overrule explicitly-provided sampling decision
1 parent 91b56b5 commit e3bab53

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

packages/tracing/src/hubextensions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ function sample<T extends Transaction>(hub: Hub, transaction: T, samplingContext
6262
return transaction;
6363
}
6464

65+
// if the user has forced a sampling decision by passing a `sampled` value in their transaction context, go with that
66+
if (transaction.sampled !== undefined) {
67+
return transaction;
68+
}
69+
6570
// we would have bailed already if neither `tracesSampler` nor `tracesSampleRate` were defined, so one of these should
6671
// work; prefer the hook if so
6772
const sampleRate =

packages/tracing/test/hub.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,14 @@ describe('Hub', () => {
183183
expect(transaction.sampled).toBe(false);
184184
});
185185

186+
it('should not try to override sampling decision provided in transaction context', () => {
187+
// setting tracesSampleRate to 1 means that without the override, the sampling decision should be true
188+
const hub = new Hub(new BrowserClient({ tracesSampleRate: 1 }));
189+
const transaction = hub.startTransaction({ name: 'dogpark', sampled: false });
190+
191+
expect(transaction.sampled).toBe(false);
192+
});
193+
186194
it('should not sample transactions when tracesSampleRate is 0', () => {
187195
const hub = new Hub(new BrowserClient({ tracesSampleRate: 0 }));
188196
const transaction = hub.startTransaction({ name: 'dogpark' });

0 commit comments

Comments
 (0)