-
-
Notifications
You must be signed in to change notification settings - Fork 361
Experimental: Android UI profiling #5518
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
Changes from 3 commits
a5451ae
4ff485a
d533217
d212f79
d559e11
3b69a13
9f4a319
c3a68ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -224,6 +224,7 @@ export class ReactNativeClient extends Client<ReactNativeClientOptions> { | |
| 'options' in this._integrations[MOBILE_REPLAY_INTEGRATION_NAME] | ||
| ? (this._integrations[MOBILE_REPLAY_INTEGRATION_NAME] as ReturnType<typeof mobileReplayIntegration>).options | ||
| : undefined, | ||
| androidProfilingOptions: this._options._experiments?.androidProfilingOptions, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Suggested FixIn Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews. |
||
| }) | ||
| .then( | ||
| (result: boolean) => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| import type { Spec } from '../src/js/NativeRNSentry'; | ||
| import type { ReactNativeClientOptions } from '../src/js/options'; | ||
| import { NATIVE } from '../src/js/wrapper'; | ||
|
|
||
| jest.mock('react-native', () => { | ||
| let initPayload: ReactNativeClientOptions | null = null; | ||
|
|
||
| const RNSentry: Spec = { | ||
| addBreadcrumb: jest.fn(), | ||
| captureEnvelope: jest.fn(), | ||
| clearBreadcrumbs: jest.fn(), | ||
| crashedLastRun: jest.fn(), | ||
| crash: jest.fn(), | ||
| fetchNativeDeviceContexts: jest.fn(() => | ||
| Promise.resolve({ | ||
| someContext: { | ||
| someValue: 0, | ||
| }, | ||
| }), | ||
| ), | ||
| fetchNativeRelease: jest.fn(() => | ||
| Promise.resolve({ | ||
| build: '1.0.0.1', | ||
| id: 'test-mock', | ||
| version: '1.0.0', | ||
| }), | ||
| ), | ||
| setContext: jest.fn(), | ||
| setExtra: jest.fn(), | ||
| setTag: jest.fn(), | ||
| setUser: jest.fn(() => { | ||
| return; | ||
| }), | ||
| initNativeSdk: jest.fn(options => { | ||
| initPayload = options; | ||
| return Promise.resolve(true); | ||
| }), | ||
| closeNativeSdk: jest.fn(() => Promise.resolve()), | ||
| // @ts-expect-error for testing. | ||
| _getLastPayload: () => ({ initPayload }), | ||
| startProfiling: jest.fn(), | ||
| stopProfiling: jest.fn(), | ||
| }; | ||
|
|
||
| return { | ||
| NativeModules: { | ||
| RNSentry, | ||
| }, | ||
| Platform: { | ||
| OS: 'android', | ||
| }, | ||
| }; | ||
| }); | ||
|
|
||
| const RNSentry = require('react-native').NativeModules.RNSentry as Spec; | ||
|
|
||
| describe('Android UI Profiling Options', () => { | ||
| beforeEach(() => { | ||
| NATIVE.platform = 'android'; | ||
| NATIVE.enableNative = true; | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('passes androidProfilingOptions to native SDK', async () => { | ||
| await NATIVE.initNativeSdk({ | ||
| dsn: 'https://example@sentry.io/123', | ||
| enableNative: true, | ||
| autoInitializeNativeSdk: true, | ||
| devServerUrl: undefined, | ||
| defaultSidecarUrl: undefined, | ||
| mobileReplayOptions: undefined, | ||
| androidProfilingOptions: { | ||
| profileSessionSampleRate: 0.5, | ||
| lifecycle: 'trace', | ||
| startOnAppStart: true, | ||
| }, | ||
| }); | ||
|
|
||
| expect(RNSentry.initNativeSdk).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| _experiments: expect.objectContaining({ | ||
| androidProfilingOptions: { | ||
| profileSessionSampleRate: 0.5, | ||
| lifecycle: 'trace', | ||
| startOnAppStart: true, | ||
| }, | ||
| }), | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it('passes androidProfilingOptions with manual lifecycle', async () => { | ||
| await NATIVE.initNativeSdk({ | ||
| dsn: 'https://example@sentry.io/123', | ||
| enableNative: true, | ||
| autoInitializeNativeSdk: true, | ||
| devServerUrl: undefined, | ||
| defaultSidecarUrl: undefined, | ||
| mobileReplayOptions: undefined, | ||
| androidProfilingOptions: { | ||
| profileSessionSampleRate: 1.0, | ||
| lifecycle: 'manual', | ||
| startOnAppStart: false, | ||
| }, | ||
| }); | ||
|
|
||
| expect(RNSentry.initNativeSdk).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| _experiments: expect.objectContaining({ | ||
| androidProfilingOptions: { | ||
| profileSessionSampleRate: 1.0, | ||
| lifecycle: 'manual', | ||
| startOnAppStart: false, | ||
| }, | ||
| }), | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it('does not pass androidProfilingOptions when undefined', async () => { | ||
| await NATIVE.initNativeSdk({ | ||
| dsn: 'https://example@sentry.io/123', | ||
| enableNative: true, | ||
| autoInitializeNativeSdk: true, | ||
| devServerUrl: undefined, | ||
| defaultSidecarUrl: undefined, | ||
| mobileReplayOptions: undefined, | ||
| androidProfilingOptions: undefined, | ||
| }); | ||
|
|
||
| const callArgs = (RNSentry.initNativeSdk as jest.Mock).mock.calls[0][0]; | ||
| expect(callArgs._experiments?.androidProfilingOptions).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('handles partial androidProfilingOptions', async () => { | ||
| await NATIVE.initNativeSdk({ | ||
| dsn: 'https://example@sentry.io/123', | ||
| enableNative: true, | ||
| autoInitializeNativeSdk: true, | ||
| devServerUrl: undefined, | ||
| defaultSidecarUrl: undefined, | ||
| mobileReplayOptions: undefined, | ||
| androidProfilingOptions: { | ||
| profileSessionSampleRate: 0.3, | ||
| // lifecycle and startOnAppStart not provided | ||
| }, | ||
| }); | ||
|
|
||
| expect(RNSentry.initNativeSdk).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| _experiments: expect.objectContaining({ | ||
| androidProfilingOptions: { | ||
| profileSessionSampleRate: 0.3, | ||
| }, | ||
| }), | ||
| }), | ||
| ); | ||
| }); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.