Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
test(e2e): Add more test modes, pre-init and element timing#21760
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
Uh oh!
There was an error while loading. Please reload this page.
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
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3 dev-packages/e2e-tests/test-applications/lighthouse-react/package.json
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
2 changes: 1 addition & 1 deletion
2 dev-packages/e2e-tests/test-applications/lighthouse-react/src/App.tsx
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
71 changes: 71 additions & 0 deletions
71 dev-packages/e2e-tests/test-applications/lighthouse-react/src/main.tsx
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 |
|---|---|---|
| @@ -3,6 +3,13 @@ import { createRoot } from 'react-dom/client'; | ||
| import App from './App'; | ||
| const sentryInitStart = performance.now(); | ||
| performance.measure('sentry-sdk-pre-init-duration', { | ||
| detail: { mode: import.meta.env.MODE ?? 'unknown_mode' }, | ||
| start: 0, | ||
| end: sentryInitStart, | ||
| }); | ||
sentry[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| performance.mark('sentry-sdk-init-start', { | ||
| detail: { mode: import.meta.env.MODE ?? 'unknown_mode' }, | ||
| }); | ||
| @@ -26,13 +33,43 @@ if (import.meta.env.MODE === 'tracing-replay') { | ||
| integrations: [Sentry.browserTracingIntegration()], | ||
| tracesSampleRate: 1.0, | ||
| }); | ||
| } else if (import.meta.env.MODE === 'tracing-lazy-import') { | ||
| // Tracing + errors, but browsertracing loaded lazily. | ||
| // (We don't recommend this setup anywhere and neither will it work well. | ||
| // this is purely for testing if it changes anything about overhead.) | ||
| Sentry.init({ | ||
| dsn: import.meta.env.VITE_E2E_TEST_DSN as string | undefined, | ||
| release: 'lighthouse-fixture', | ||
| environment: 'qa', | ||
| tracesSampleRate: 1.0, | ||
| }); | ||
| import('@sentry/react').then(lazySentry => { | ||
| Sentry.addIntegration(lazySentry.browserTracingIntegration()); | ||
| }); | ||
| } else if (import.meta.env.MODE === 'errors-only') { | ||
| // Default integrations only — errors are always captured, no tracing or replay. | ||
| Sentry.init({ | ||
| dsn: import.meta.env.VITE_E2E_TEST_DSN as string | undefined, | ||
| release: 'lighthouse-fixture', | ||
| environment: 'qa', | ||
| }); | ||
| } else if (import.meta.env.MODE === 'minimal-integrations') { | ||
| // Minimal integratoins setup only (everything necessary to automatically get errors) | ||
| Sentry.init({ | ||
| dsn: import.meta.env.VITE_E2E_TEST_DSN as string | undefined, | ||
| release: 'lighthouse-fixture', | ||
| environment: 'qa', | ||
| defaultIntegrations: false, | ||
| integrations: [ | ||
| Sentry.globalHandlersIntegration(), | ||
| Sentry.linkedErrorsIntegration(), | ||
| Sentry.dedupeIntegration(), | ||
| // for good measure, let's include event filters since noise reduction is usually desired | ||
| // 99% of this integration's work is done in an event processor, so outside the hot path | ||
| Sentry.eventFiltersIntegration(), | ||
| ], | ||
| }); | ||
| } else if (import.meta.env.MODE === 'no-integrations') { | ||
| // DSN set but every integration disabled. Isolates the cost of the enabled | ||
| // client itself from the default instrumentation that wraps DOM/timer/network APIs. | ||
| @@ -54,6 +91,15 @@ if (import.meta.env.MODE === 'tracing-replay') { | ||
| integrations: defaultIntegrations => | ||
| defaultIntegrations.filter(integration => integration.name !== 'BrowserApiErrors'), | ||
| }); | ||
| } else if (import.meta.env.MODE === 'no-breadcrumbs') { | ||
| // Default integrations minus Breadcrumbs, which adds a lot of monkey patching to | ||
| // DOM and Network APIs as well as event targets and listeners | ||
| Sentry.init({ | ||
| dsn: import.meta.env.VITE_E2E_TEST_DSN as string | undefined, | ||
| release: 'lighthouse-fixture', | ||
| environment: 'qa', | ||
| integrations: defaultIntegrations => defaultIntegrations.filter(integration => integration.name !== 'Breadcrumbs'), | ||
| }); | ||
| } else if (import.meta.env.MODE === 'init-only') { | ||
| // enabled: false makes the SDK a guaranteed no-op (no transport allocation, | ||
| // no DSN warning). We're measuring pure SDK-loading + tree-shaking cost. | ||
| @@ -72,5 +118,30 @@ performance.mark('sentry-sdk-init-end', { | ||
| // 'no-sentry' mode: all branches above are statically dead, so Vite drops | ||
| // the @sentry/react import entirely from the bundle. | ||
| // Elements tagged with `elementtiming` (e.g. the hero logo) emit a | ||
| // PerformanceElementTiming entry when painted. Re-emit each as a | ||
| // performance.measure spanning time origin -> render so the element's render | ||
| // duration lands on the same timeline as the SDK init marks. | ||
| // `PerformanceElementTiming` isn't in this project's TS lib, so type it locally. | ||
| type ElementTimingEntry = PerformanceEntry & { | ||
| identifier: string; | ||
| renderTime: number; | ||
| loadTime: number; | ||
| }; | ||
| const elementTimingObserver = new PerformanceObserver(list => { | ||
| for (const entry of list.getEntries() as ElementTimingEntry[]) { | ||
| const renderEnd = entry.renderTime || entry.loadTime; | ||
| performance.measure(`element-timing-${entry.identifier}`, { | ||
| detail: { mode: import.meta.env.MODE ?? 'unknown_mode', identifier: entry.identifier }, | ||
| start: 0, | ||
| end: renderEnd, | ||
| }); | ||
| } | ||
| }); | ||
| elementTimingObserver.observe({ type: 'element', buffered: true }); | ||
| const root = createRoot(document.getElementById('root')!); | ||
| root.render(<App />); | ||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.