-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(browserprofiling): Add manual mode and deprecate old profiling
#18189
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
Open
s1gr1d
wants to merge
19
commits into
develop
Choose a base branch
from
sig/profiling-manual-mode
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
f6c55e2
Add test for manual profiling
s1gr1d 4e0c670
add common UIProfiler
s1gr1d 47b89b1
align with previous code
s1gr1d ea38195
prepare profiling for manual mode
s1gr1d 32080bf
add comment about node profiling namespace
s1gr1d 98b6de2
improve integration tests
s1gr1d ff7fc66
add util in test
s1gr1d 389a6a5
add test, refactor
s1gr1d 53bdb13
revert comment changes
s1gr1d 09bfd6c
add tests for logs
s1gr1d 68847c3
remove profile_id between cycles
s1gr1d d03bba3
remove lifecycle folder
s1gr1d 9373335
add deprecation warning
s1gr1d 373a1ed
Merge branch 'develop' into sig/profiling-manual-mode
s1gr1d 038edda
remove ts comments
s1gr1d 9fe4c7d
fix small issues
s1gr1d 79dae58
fix prettier
s1gr1d ea98579
fix AI review comments
s1gr1d ffc15f2
fix deprecation issues
s1gr1d 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
76 changes: 76 additions & 0 deletions
76
dev-packages/browser-integration-tests/suites/profiling/manualMode/subject.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,76 @@ | ||
| import * as Sentry from '@sentry/browser'; | ||
| import { browserProfilingIntegration } from '@sentry/browser'; | ||
|
|
||
| window.Sentry = Sentry; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| integrations: [browserProfilingIntegration()], | ||
| tracesSampleRate: 1, | ||
| profileSessionSampleRate: 1, | ||
| profileLifecycle: 'manual', | ||
| }); | ||
|
|
||
| function largeSum(amount = 1000000) { | ||
| let sum = 0; | ||
| for (let i = 0; i < amount; i++) { | ||
| sum += Math.sqrt(i) * Math.sin(i); | ||
| } | ||
| } | ||
|
|
||
| function fibonacci(n) { | ||
| if (n <= 1) { | ||
| return n; | ||
| } | ||
| return fibonacci(n - 1) + fibonacci(n - 2); | ||
| } | ||
|
|
||
| function fibonacci1(n) { | ||
| if (n <= 1) { | ||
| return n; | ||
| } | ||
| return fibonacci1(n - 1) + fibonacci1(n - 2); | ||
| } | ||
|
|
||
| function fibonacci2(n) { | ||
| if (n <= 1) { | ||
| return n; | ||
| } | ||
| return fibonacci1(n - 1) + fibonacci1(n - 2); | ||
| } | ||
|
|
||
| function notProfiledFib(n) { | ||
| if (n <= 1) { | ||
| return n; | ||
| } | ||
| return fibonacci1(n - 1) + fibonacci1(n - 2); | ||
| } | ||
|
|
||
| // Adding setTimeout to ensure we cross the sampling interval to avoid flakes | ||
|
|
||
| Sentry.uiProfiler.startProfiler(); | ||
|
|
||
| fibonacci(40); | ||
| await new Promise(resolve => setTimeout(resolve, 25)); | ||
|
|
||
| largeSum(); | ||
| await new Promise(resolve => setTimeout(resolve, 25)); | ||
|
|
||
| Sentry.uiProfiler.stopProfiler(); | ||
|
|
||
| // --- | ||
|
|
||
| notProfiledFib(40); | ||
| await new Promise(resolve => setTimeout(resolve, 25)); | ||
|
|
||
| // --- | ||
|
|
||
| Sentry.uiProfiler.startProfiler(); | ||
|
|
||
| fibonacci2(40); | ||
| await new Promise(resolve => setTimeout(resolve, 25)); | ||
|
|
||
| Sentry.uiProfiler.stopProfiler(); | ||
|
|
||
| const client = Sentry.getClient(); | ||
| await client?.flush(8000); |
93 changes: 93 additions & 0 deletions
93
dev-packages/browser-integration-tests/suites/profiling/manualMode/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,93 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import type { ProfileChunkEnvelope } from '@sentry/core'; | ||
| import { sentryTest } from '../../../utils/fixtures'; | ||
| import { | ||
| countEnvelopes, | ||
| getMultipleSentryEnvelopeRequests, | ||
| properFullEnvelopeRequestParser, | ||
| shouldSkipTracingTest, | ||
| } from '../../../utils/helpers'; | ||
| import { validateProfile, validateProfilePayloadMetadata } from '../test-utils'; | ||
|
|
||
| sentryTest( | ||
| 'does not send profile envelope when document-policy is not set', | ||
| async ({ page, getLocalTestUrl, browserName }) => { | ||
| if (shouldSkipTracingTest() || browserName !== 'chromium') { | ||
| // Profiling only works when tracing is enabled | ||
| sentryTest.skip(); | ||
| } | ||
|
|
||
| const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
|
||
| // Assert that no profile_chunk envelope is sent without policy header | ||
| const chunkCount = await countEnvelopes(page, { url, envelopeType: 'profile_chunk', timeout: 1500 }); | ||
| expect(chunkCount).toBe(0); | ||
| }, | ||
| ); | ||
|
|
||
| sentryTest('sends profile_chunk envelopes in manual mode', async ({ page, getLocalTestUrl, browserName }) => { | ||
| if (shouldSkipTracingTest() || browserName !== 'chromium') { | ||
| // Profiling only works when tracing is enabled | ||
| sentryTest.skip(); | ||
| } | ||
|
|
||
| const url = await getLocalTestUrl({ testDir: __dirname, responseHeaders: { 'Document-Policy': 'js-profiling' } }); | ||
|
|
||
| // In manual mode we start and stop once -> expect exactly one chunk | ||
| const profileChunkEnvelopes = await getMultipleSentryEnvelopeRequests<ProfileChunkEnvelope>( | ||
| page, | ||
| 2, | ||
| { url, envelopeType: 'profile_chunk', timeout: 8000 }, | ||
| properFullEnvelopeRequestParser, | ||
| ); | ||
|
|
||
| expect(profileChunkEnvelopes.length).toBe(2); | ||
|
|
||
| // Validate the first chunk thoroughly | ||
| const profileChunkEnvelopeItem = profileChunkEnvelopes[0][1][0]; | ||
| const envelopeItemHeader = profileChunkEnvelopeItem[0]; | ||
| const envelopeItemPayload1 = profileChunkEnvelopeItem[1]; | ||
|
|
||
| expect(envelopeItemHeader).toHaveProperty('type', 'profile_chunk'); | ||
| expect(envelopeItemPayload1.profile).toBeDefined(); | ||
|
|
||
| const profilerId1 = envelopeItemPayload1.profiler_id; | ||
|
|
||
| validateProfilePayloadMetadata(envelopeItemPayload1); | ||
|
|
||
| validateProfile(envelopeItemPayload1.profile, { | ||
| expectedFunctionNames: ['startJSSelfProfile', 'fibonacci', 'largeSum'], | ||
| minSampleDurationMs: 20, | ||
| isChunkFormat: true, | ||
| }); | ||
|
|
||
| // only contains fibonacci | ||
| const functionNames1 = envelopeItemPayload1.profile.frames.map(frame => frame.function).filter(name => name !== ''); | ||
| expect(functionNames1).toEqual(expect.not.arrayContaining(['fibonacci1', 'fibonacci2', 'fibonacci3'])); | ||
|
|
||
| // === PROFILE CHUNK 2 === | ||
|
|
||
| const profileChunkEnvelopeItem2 = profileChunkEnvelopes[1][1][0]; | ||
| const envelopeItemHeader2 = profileChunkEnvelopeItem2[0]; | ||
| const envelopeItemPayload2 = profileChunkEnvelopeItem2[1]; | ||
|
|
||
| expect(envelopeItemHeader2).toHaveProperty('type', 'profile_chunk'); | ||
| expect(envelopeItemPayload2.profile).toBeDefined(); | ||
|
|
||
| expect(envelopeItemPayload2.profiler_id).toBe(profilerId1); // same profiler id for the whole session | ||
|
|
||
| validateProfilePayloadMetadata(envelopeItemPayload2); | ||
|
|
||
| validateProfile(envelopeItemPayload2.profile, { | ||
| expectedFunctionNames: [ | ||
| 'startJSSelfProfile', | ||
| 'fibonacci1', // called by fibonacci2 | ||
| 'fibonacci2', | ||
| ], | ||
| isChunkFormat: true, | ||
| }); | ||
|
|
||
| // does not contain notProfiledFib (called during unprofiled part) | ||
| const functionNames2 = envelopeItemPayload2.profile.frames.map(frame => frame.function).filter(name => name !== ''); | ||
| expect(functionNames2).toEqual(expect.not.arrayContaining(['notProfiledFib'])); | ||
| }); | ||
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
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.
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: the code suggests we get two envelopes/chunks. Should we update/remove the comment?