Skip to content

ref(tracing): update hasTracingEnabled return value #4225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 3, 2021
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
5 changes: 1 addition & 4 deletions packages/tracing/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ export function hasTracingEnabled(
.getClient()
?.getOptions(),
): boolean {
if (!options) {
return false;
}
return 'tracesSampleRate' in options || 'tracesSampler' in options;
return !!options && ('tracesSampleRate' in options || 'tracesSampler' in options);
}

/**
Expand Down
19 changes: 18 additions & 1 deletion packages/tracing/test/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
import { extractTraceparentData } from '../src/utils';
import { extractTraceparentData, hasTracingEnabled } from '../src/utils';

describe('hasTracingEnabled', () => {
const tracesSampler = () => 1;
const tracesSampleRate = 1;
it.each([
['No options', undefined, false],
['No tracesSampler or tracesSampleRate', {}, false],
['With tracesSampler', { tracesSampler }, true],
['With tracesSampleRate', { tracesSampleRate }, true],
['With tracesSampler and tracesSampleRate', { tracesSampler, tracesSampleRate }, true],
])(
'%s',
(_: string, input: Parameters<typeof hasTracingEnabled>[0], output: ReturnType<typeof hasTracingEnabled>) => {
expect(hasTracingEnabled(input)).toBe(output);
},
);
});

describe('extractTraceparentData', () => {
test('no sample', () => {
Expand Down