Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/tracing/src/hubextensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function traceHeaders(this: Hub): { [key: string]: string } {
*/
function sample<T extends Transaction>(transaction: T, options: Options, samplingContext: SamplingContext): T {
// nothing to do if tracing is not enabled
if (!hasTracingEnabled()) {
if (!hasTracingEnabled(options)) {
transaction.sampled = false;
return transaction;
}
Expand Down
19 changes: 19 additions & 0 deletions packages/tracing/test/hub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ addDOMPropertiesToGlobal(['XMLHttpRequest', 'Event', 'location', 'document']);
describe('Hub', () => {
afterEach(() => {
jest.clearAllMocks();
// Reset global carrier to the initial state
const hub = new Hub();
makeMain(hub);
});

describe('getTransaction()', () => {
Expand Down Expand Up @@ -125,6 +128,13 @@ describe('Hub', () => {
expect(transaction.sampled).toBe(true);
});

it('should set sampled = true if tracesSampleRate is 1 (without global hub)', () => {
const hub = new Hub(new BrowserClient({ tracesSampleRate: 1 }));
const transaction = hub.startTransaction({ name: 'dogpark' });

expect(transaction.sampled).toBe(true);
});

it("should call tracesSampler if it's defined", () => {
const tracesSampler = jest.fn();
const hub = new Hub(new BrowserClient({ tracesSampler }));
Expand Down Expand Up @@ -154,6 +164,15 @@ describe('Hub', () => {
expect(transaction.sampled).toBe(true);
});

it('should set sampled = true if tracesSampler returns 1 (without global hub)', () => {
const tracesSampler = jest.fn().mockReturnValue(1);
const hub = new Hub(new BrowserClient({ tracesSampler }));
const transaction = hub.startTransaction({ name: 'dogpark' });

expect(tracesSampler).toHaveBeenCalled();
expect(transaction.sampled).toBe(true);
});

it('should not try to override explicitly set positive sampling decision', () => {
// so that the decision otherwise would be false
const tracesSampler = jest.fn().mockReturnValue(0);
Expand Down