Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/core/src/js/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,16 @@ export interface BaseReactNativeOptions {
* @default false
*/
propagateTraceparent?: boolean;

/**
* Controls the origin of the logger to be logged, it takes effect when `enableLogger` is set to true.
* 'all' will log all origins.
* 'JS' will log only enable Logger to capture JavaScript logs.
* 'Native' will log only Native Logs..
*
* @default 'all'
*/
loggerOrigin?: 'all' | 'js' | 'native';
}

export type SentryReplayQuality = 'low' | 'medium' | 'high';
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/js/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ export const NATIVE: SentryNativeWrapper = {
enableNative: true,
autoInitializeNativeSdk: true,
...originalOptions,
// Keeps original behavior of enableLogs by not setting it when not defined.
...(originalOptions.enableLogs !== undefined
? { enableLogs: originalOptions.enableLogs && originalOptions.loggerOrigin !== 'js' }
: {}),
};

if (!options.enableNative) {
Expand Down Expand Up @@ -273,7 +277,7 @@ export const NATIVE: SentryNativeWrapper = {

// filter out all the options that would crash native.
/* eslint-disable @typescript-eslint/unbound-method,@typescript-eslint/no-unused-vars */
const { beforeSend, beforeBreadcrumb, beforeSendTransaction, integrations, ignoreErrors, ...filteredOptions } =
const { beforeSend, beforeBreadcrumb, beforeSendTransaction, integrations, ignoreErrors, loggerOrigin, ...filteredOptions } =
options;
/* eslint-enable @typescript-eslint/unbound-method,@typescript-eslint/no-unused-vars */
const nativeIsReady = await RNSentry.initNativeSdk(filteredOptions);
Expand Down
38 changes: 38 additions & 0 deletions packages/core/test/wrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,44 @@ describe('Tests Native Wrapper', () => {
expect(initParameter.ignoreErrorsStr).toBeUndefined();
expect(initParameter.ignoreErrorsRegex).toBeUndefined();
});

test('does not set enableLogs when option is undefined', async () => {
await NATIVE.initNativeSdk({
dsn: 'test',
enableNative: true,
autoInitializeNativeSdk: true,
devServerUrl: undefined,
defaultSidecarUrl: undefined,
mobileReplayOptions: undefined,
});

expect(RNSentry.initNativeSdk).toHaveBeenCalled();
const initParameter = (RNSentry.initNativeSdk as jest.MockedFunction<any>).mock.calls[0][0];
expect(initParameter.enableLogs).toBeUndefined();
});

it.each([
['without loggerOrigin', undefined, true],
['with loggerOrigin set to Native', 'native' as const, true],
['with loggerOrigin set to all', 'all' as const, true],
['with loggerOrigin set to JS', 'js' as const, false],
])('handles enableLogs %s', async (_description, loggerOrigin, expectedEnableLogs) => {
await NATIVE.initNativeSdk({
dsn: 'test',
enableNative: true,
autoInitializeNativeSdk: true,
enableLogs: true,
...(loggerOrigin !== undefined ? { loggerOrigin } : {}),
devServerUrl: undefined,
defaultSidecarUrl: undefined,
mobileReplayOptions: undefined,
});

expect(RNSentry.initNativeSdk).toHaveBeenCalled();
const initParameter = (RNSentry.initNativeSdk as jest.MockedFunction<any>).mock.calls[0][0];
expect(initParameter.enableLogs).toBe(expectedEnableLogs);
expect(initParameter.loggerOrigin).toBeUndefined();
});
});

describe('sendEnvelope', () => {
Expand Down
Loading