Skip to content
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

feat(tracing): Add enableTracing option #7238

Merged
merged 3 commits into from Feb 22, 2023
Merged

feat(tracing): Add enableTracing option #7238

merged 3 commits into from Feb 22, 2023

Conversation

mydea
Copy link
Member

@mydea mydea commented Feb 21, 2023

This adds a new enableTracing option, which can be used to streamline performance collection.

  • Setting this to true will default the tracesSampleRate basically to 1
  • It is overwritten by tracesSampleRate and tracesSampler, if they are defined

This change also moves the hasTracingEnabled util to @sentry/core, so we can use it everywhere in a consistent way.

Closes #7065

@mydea mydea self-assigned this Feb 21, 2023
@mydea mydea requested a review from lforst February 21, 2023 12:45
packages/types/src/options.ts Outdated Show resolved Hide resolved
@github-actions
Copy link
Contributor

github-actions bot commented Feb 21, 2023

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 20.07 KB (+0.01% 🔺)
@sentry/browser - ES5 CDN Bundle (minified) 62.3 KB (0%)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 18.69 KB (0%)
@sentry/browser - ES6 CDN Bundle (minified) 55.31 KB (0%)
@sentry/browser - Webpack (gzipped + minified) 20.42 KB (+0.02% 🔺)
@sentry/browser - Webpack (minified) 66.76 KB (+0.01% 🔺)
@sentry/react - Webpack (gzipped + minified) 20.45 KB (+0.02% 🔺)
@sentry/nextjs Client - Webpack (gzipped + minified) 47.98 KB (+0.26% 🔺)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 27 KB (+0.23% 🔺)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 25.25 KB (+0.19% 🔺)
@sentry/replay ES6 CDN Bundle (gzipped + minified) 42.57 KB (0%)
@sentry/replay - Webpack (gzipped + minified) 36.78 KB (0%)
@sentry/browser + @sentry/tracing + @sentry/replay - ES6 CDN Bundle (gzipped + minified) 60.25 KB (+0.08% 🔺)
@sentry/browser + @sentry/replay - ES6 CDN Bundle (gzipped + minified) 53.8 KB (0%)

Co-authored-by: Daniel Griesser <daniel.griesser.86@gmail.com>
Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a couple other places in the codebase we also need to address.

if ('tracesSampleRate' in options || 'tracesSampler' in options) {

if (!('tracesSampleRate' in options) && !('tracesSampler' in options)) {

@mydea
Copy link
Member Author

mydea commented Feb 21, 2023

So I moved the hasTracingEnabled util to @sentry/core, and deprecated the old export from @sentry/tracing.
I added a check for __SENTRY_TRACING__ that should hopefully (?) lead to this function being replaced with return false when this is disabled.

export function hasTracingEnabled(
maybeOptions?: Pick<Options, 'tracesSampleRate' | 'tracesSampler' | 'enableTracing'> | undefined,
): boolean {
if (typeof __SENTRY_TRACING__ === 'boolean' && !__SENTRY_TRACING__) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I wonder if this is worth it 🤔 WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure but theoretically, rollup should be able to basically reduce this function to return false if users configure this guard in their bundler setup 🤔 So I'd argue yes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the "downside" is that users that do not configure this will/may still have this code in their bundle, right?

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

export function hasTracingEnabled(
maybeOptions?: Pick<Options, 'tracesSampleRate' | 'tracesSampler' | 'enableTracing'> | undefined,
): boolean {
if (typeof __SENTRY_TRACING__ === 'boolean' && !__SENTRY_TRACING__) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure but theoretically, rollup should be able to basically reduce this function to return false if users configure this guard in their bundler setup 🤔 So I'd argue yes

@mydea
Copy link
Member Author

mydea commented Feb 22, 2023

@AbhiPrasad is this good by you now as well?

Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@mydea mydea merged commit 46a527b into develop Feb 22, 2023
@mydea mydea deleted the fn/add-enableTracing branch February 22, 2023 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add enableTracing Option
4 participants