-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
ref: Avoid using global singleton for logger #8880
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
packages/browser-integration-tests/suites/public-api/debug/init.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
debug: true, | ||
}); |
41 changes: 41 additions & 0 deletions
41
packages/browser-integration-tests/suites/public-api/debug/test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* eslint-disable no-console */ | ||
import type { ConsoleMessage } from '@playwright/test'; | ||
import { expect } from '@playwright/test'; | ||
|
||
import { sentryTest } from '../../../utils/fixtures'; | ||
|
||
sentryTest('logs debug messages correctly', async ({ getLocalTestUrl, page }) => { | ||
const bundleKey = process.env.PW_BUNDLE || ''; | ||
const hasDebug = !bundleKey.includes('_min'); | ||
|
||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
||
const consoleMessages: string[] = []; | ||
|
||
page.on('console', (msg: ConsoleMessage) => { | ||
consoleMessages.push(msg.text()); | ||
}); | ||
|
||
await page.goto(url); | ||
|
||
await page.evaluate(() => console.log('test log')); | ||
|
||
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'], | ||
); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 :)There was a problem hiding this comment.
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...!)