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

ref: Avoid using global singleton for logger #8880

Merged
merged 4 commits into from
Aug 30, 2023
Merged

Conversation

mydea
Copy link
Member

@mydea mydea commented Aug 28, 2023

Instead of #8873, this tries to simplify the logger to avoid the global lookup.
If you have more than one utils, having multiple loggers would be the least of your problems. So IMHO no need to special case handle this, in the worst case logging should still work somehow 🤔

Note some test code seems to rely on the global stuff the logger does, which required minor changes there.
This now relies on the originalConsoleMethods we keep in the console instrumentation, so no need to look for __sentry_original__ anymore. If that doesn't exist, nothing to do for us (because we haven't instrumented the console).

Closes #8741

@mydea mydea self-assigned this Aug 28, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Aug 28, 2023

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped) 75.26 KB (-0.03% 🔽)
@sentry/browser (incl. Tracing) - Webpack (gzipped) 31.21 KB (-0.11% 🔽)
@sentry/browser - Webpack (gzipped) 21.83 KB (-0.13% 🔽)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (gzipped) 69.76 KB (-0.06% 🔽)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (gzipped) 28.16 KB (-0.15% 🔽)
@sentry/browser - ES6 CDN Bundle (gzipped) 20.15 KB (-0.17% 🔽)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (minified & uncompressed) 220.21 KB (-0.06% 🔽)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (minified & uncompressed) 85 KB (-0.15% 🔽)
@sentry/browser - ES6 CDN Bundle (minified & uncompressed) 59.71 KB (-0.22% 🔽)
@sentry/browser (incl. Tracing) - ES5 CDN Bundle (gzipped) 31.06 KB (-0.14% 🔽)
@sentry/react (incl. Tracing, Replay) - Webpack (gzipped) 75.28 KB (-0.03% 🔽)
@sentry/react - Webpack (gzipped) 21.86 KB (-0.13% 🔽)
@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped) 93.13 KB (-0.03% 🔽)
@sentry/nextjs Client - Webpack (gzipped) 50.78 KB (-0.04% 🔽)

Base automatically changed from fn/use-console-instrument to develop August 29, 2023 08:12
@mydea mydea force-pushed the fn/better-logging branch 2 times, most recently from 5345ce6 to 39f404d Compare August 29, 2023 11:38
@mydea mydea marked this pull request as ready for review August 29, 2023 14:51
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.

Nice!

Comment on lines +23 to +39
expect(consoleMessages).toEqual(
hasDebug
? [
'Sentry Logger [log]: Integration installed: InboundFilters',
'Sentry Logger [log]: Integration installed: FunctionToString',
'Sentry Logger [log]: Integration installed: TryCatch',
'Sentry Logger [log]: Integration installed: Breadcrumbs',
'Sentry Logger [log]: Global Handler attached: onerror',
'Sentry Logger [log]: Global Handler attached: onunhandledrejection',
'Sentry Logger [log]: Integration installed: GlobalHandlers',
'Sentry Logger [log]: Integration installed: LinkedErrors',
'Sentry Logger [log]: Integration installed: Dedupe',
'Sentry Logger [log]: Integration installed: HttpContext',
'Sentry Logger [warn]: Discarded session because of missing or non-string release',
'test log',
]
: ['[Sentry] Cannot initialize SDK with `debug` option using a non-debug bundle.', 'test log'],
Copy link
Member

Choose a reason for hiding this comment

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

l: This test is gonna fail whenever we add/remove a default integration or change the ordering. I guess one can argue in both directions whether that's a good thing or not, given that it even sort of tests that the integration is actually enabled by default. The downside is that this isn't strictly the purpose of this test. To get around this, we could use expect.stringContaining and only expect specific integrations. But in the end this is logaf-l for me so feel free to ignore :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I thought about the same thing, and was also not 100% sure... IMHO it's OK to leave it like this for now, if we get to the point where we add/change default integrations and this becomes annoying we can still replace it with something more generic. IMHO for now it is not bad to be "notified" if the defaults change somehow (and that rarely happens anyhow...!)

Copy link
Member

@lforst lforst left a comment

Choose a reason for hiding this comment

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

<3

@mydea mydea merged commit 0138d1c into develop Aug 30, 2023
79 checks passed
@mydea mydea deleted the fn/better-logging branch August 30, 2023 11:08
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.

Error in replay logging: TypeError: F.kg.info is not a function
4 participants