-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(browser): Add shim package for logs #18831
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
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
10 changes: 10 additions & 0 deletions
10
.../browser-integration-tests/suites/public-api/logger/consoleLoggingIntegrationShim/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,10 @@ | ||
| import * as Sentry from '@sentry/browser'; | ||
|
|
||
| window.Sentry = Sentry; | ||
|
|
||
| // consoleLoggingIntegration should not actually work, but still not error out | ||
| Sentry.init({ | ||
| dsn: 'https://[email protected]/1337', | ||
| sampleRate: 1, | ||
| integrations: [Sentry.consoleLoggingIntegration()], | ||
| }); |
37 changes: 37 additions & 0 deletions
37
.../browser-integration-tests/suites/public-api/logger/consoleLoggingIntegrationShim/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,37 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import { sentryTest } from '../../../../utils/fixtures'; | ||
|
|
||
| sentryTest('exports a shim consoleLoggingIntegration for non-logs bundles', async ({ getLocalTestUrl, page }) => { | ||
| const bundle = process.env.PW_BUNDLE; | ||
|
|
||
| // Only run this for CDN bundles that do NOT include logs | ||
| // Skip minified bundles because DEBUG_BUILD is false and warnings won't appear | ||
| if (!bundle?.startsWith('bundle') || bundle.includes('logs') || bundle.includes('min')) { | ||
| sentryTest.skip(); | ||
| } | ||
|
|
||
| const consoleMessages: string[] = []; | ||
| page.on('console', msg => consoleMessages.push(msg.text())); | ||
|
|
||
| let requestCount = 0; | ||
| await page.route(/^https:\/\/dsn\.ingest\.sentry\.io\//, route => { | ||
| requestCount++; | ||
| return route.fulfill({ | ||
| status: 200, | ||
| contentType: 'application/json', | ||
| body: JSON.stringify({ id: 'test-id' }), | ||
| }); | ||
| }); | ||
|
|
||
| const url = await getLocalTestUrl({ testDir: __dirname, skipDsnRouteHandler: true }); | ||
|
|
||
| await page.goto(url); | ||
|
|
||
| // Wait a bit to ensure no requests are made | ||
| await page.waitForTimeout(500); | ||
|
|
||
| expect(requestCount).toBe(0); | ||
| expect(consoleMessages).toEqual([ | ||
| 'You are using consoleLoggingIntegration() even though this bundle does not include logs.', | ||
| ]); | ||
| }); | ||
18 changes: 18 additions & 0 deletions
18
dev-packages/browser-integration-tests/suites/public-api/logger/loggerShim/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,18 @@ | ||
| import * as Sentry from '@sentry/browser'; | ||
|
|
||
| window.Sentry = Sentry; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://[email protected]/1337', | ||
| sampleRate: 1, | ||
| }); | ||
|
|
||
| // These should not actually work, but still not error out | ||
| Sentry.logger.trace('test trace'); | ||
| Sentry.logger.debug('test debug'); | ||
| Sentry.logger.info('test info'); | ||
| Sentry.logger.warn('test warn'); | ||
| Sentry.logger.error('test error'); | ||
| Sentry.logger.fatal('test fatal'); | ||
| const testVar = 'test'; | ||
| Sentry.logger.info(Sentry.logger.fmt`formatted ${testVar}`); |
37 changes: 37 additions & 0 deletions
37
dev-packages/browser-integration-tests/suites/public-api/logger/loggerShim/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,37 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import { sentryTest } from '../../../../utils/fixtures'; | ||
|
|
||
| sentryTest('exports a shim logger for non-logs bundles', async ({ getLocalTestUrl, page }) => { | ||
| const bundle = process.env.PW_BUNDLE; | ||
|
|
||
| // Only run this for CDN bundles that do NOT include logs | ||
| // Skip minified bundles because DEBUG_BUILD is false and warnings won't appear | ||
| if (!bundle?.startsWith('bundle') || bundle.includes('logs') || bundle.includes('min')) { | ||
| sentryTest.skip(); | ||
| } | ||
|
|
||
| const consoleMessages: string[] = []; | ||
| page.on('console', msg => consoleMessages.push(msg.text())); | ||
|
|
||
| let requestCount = 0; | ||
| await page.route(/^https:\/\/dsn\.ingest\.sentry\.io\//, route => { | ||
| requestCount++; | ||
| return route.fulfill({ | ||
| status: 200, | ||
| contentType: 'application/json', | ||
| body: JSON.stringify({ id: 'test-id' }), | ||
| }); | ||
| }); | ||
|
|
||
| const url = await getLocalTestUrl({ testDir: __dirname, skipDsnRouteHandler: true }); | ||
|
|
||
| await page.goto(url); | ||
|
|
||
| // Wait a bit to ensure no requests are made | ||
| await page.waitForTimeout(500); | ||
|
|
||
| expect(requestCount).toBe(0); | ||
|
|
||
| expect(consoleMessages).toContain('You are using Sentry.logger.* even though this bundle does not include logs.'); | ||
| expect(consoleMessages).toContain('You are using Sentry.logger.fmt even though this bundle does not include logs.'); | ||
| }); |
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
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
20 changes: 20 additions & 0 deletions
20
packages/browser/test/index.bundle.replay.feedback.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,20 @@ | ||
| import { | ||
| browserTracingIntegrationShim, | ||
| consoleLoggingIntegrationShim, | ||
| loggerShim, | ||
| } from '@sentry-internal/integration-shims'; | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { feedbackAsyncIntegration, replayIntegration } from '../src'; | ||
| import * as ReplayFeedbackBundle from '../src/index.bundle.replay.feedback'; | ||
|
|
||
| describe('index.bundle.replay.feedback', () => { | ||
| it('has correct exports', () => { | ||
| expect(ReplayFeedbackBundle.browserTracingIntegration).toBe(browserTracingIntegrationShim); | ||
| expect(ReplayFeedbackBundle.feedbackAsyncIntegration).toBe(feedbackAsyncIntegration); | ||
| expect(ReplayFeedbackBundle.feedbackIntegration).toBe(feedbackAsyncIntegration); | ||
| expect(ReplayFeedbackBundle.replayIntegration).toBe(replayIntegration); | ||
|
|
||
| expect(ReplayFeedbackBundle.logger).toBe(loggerShim); | ||
| expect(ReplayFeedbackBundle.consoleLoggingIntegration).toBe(consoleLoggingIntegrationShim); | ||
| }); | ||
| }); |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| declare const __DEBUG_BUILD__: boolean; | ||
|
|
||
| /** | ||
| * This serves as a build time flag that will be true by default, but false in non-debug builds or if users replace `__SENTRY_DEBUG__` in their generated code. | ||
| * | ||
| * ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking. | ||
| */ | ||
| export const DEBUG_BUILD = __DEBUG_BUILD__; |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.