Skip to content

feat(various): Apply debug guard to logger everywhere #4698

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
Mar 9, 2022

Conversation

lobsterkatie
Copy link
Member

@lobsterkatie lobsterkatie commented Mar 9, 2022

This applies the isDebugBuild() guard (which allows logging code to be stripped when creating minified bundles) to a number of aspects of the logger:

  • All calls to the logger now have the guard. While it's true that not all log statements appear in spots which currently have any chance of making it into a bundle, applying the guard universally reduces cognitive load for both folks reading and writing our code, and future-proofs (or, perhaps more accurately, new-bundling-situation-proofs) all of our logging.

  • The Sentry.init() option debug now only enables the logger if we're in a debug build. This allows us to remove any reference to the logger in non-debug builds, making it able to be dropped from the code. A warning message has also been added to non-debug builds, because someone using debug is presumably doing so because they actually do want logging.

  • The logger singleton is only attached to global.__SENTRY__ if we're in a debug build. This makes logger.ts side-effect-free in non-debug builds, allowing it to be treeshaken freely.

Note that because the return value of isDebugBuild() is always true (absent intervention by a bundler), it's safe to use everywhere without changing any current behavior.

Finally, all preexisting if-block versions of the check are converted to short-circuit versions, for consistency and concision.

NOTE: The bundle size increases here come because this PR is part of a series refactoring the way we strip logging when creating minified bundles, after the old way has been taken out but before the new way has been phased in. Once all PRs have been merged, there should be a net savings.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2022

size-limit report

Path Base Size (21a623b) Current Size Change
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 20.42 KB 20.43 KB +0.06% 🔺
@sentry/browser - ES5 CDN Bundle (minified) 65.23 KB 65.2 KB -0.05% 🔽
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 19 KB 19.01 KB +0.06% 🔺
@sentry/browser - ES6 CDN Bundle (minified) 58.25 KB 58.22 KB -0.05% 🔽
@sentry/browser - Webpack (gzipped + minified) 22.25 KB 22.3 KB +0.24% 🔺
@sentry/browser - Webpack (minified) 76.26 KB 76.58 KB +0.43% 🔺
@sentry/react - Webpack (gzipped + minified) 22.28 KB 22.33 KB +0.24% 🔺
@sentry/nextjs Client - Webpack (gzipped + minified) 46.4 KB 46.56 KB +0.34% 🔺
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 27.25 KB 27.25 KB +0.01% 🔺
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 25.61 KB 25.62 KB +0.04% 🔺

@lobsterkatie lobsterkatie force-pushed the kmclb-debug-guard-logger-everywhere branch from 76570a0 to ea5993d Compare March 9, 2022 18:10
@lobsterkatie lobsterkatie marked this pull request as ready for review March 9, 2022 18:23
@lobsterkatie lobsterkatie merged commit 2d3b861 into master Mar 9, 2022
@lobsterkatie lobsterkatie deleted the kmclb-debug-guard-logger-everywhere branch March 9, 2022 18:50
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.

2 participants