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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

## Unreleased

### Features

- Add `enableAutoConsoleLogs` option to opt out of automatic `console.*` capture while keeping `enableLogs: true` for manual `Sentry.logger.*` calls ([#6231](https://github.com/getsentry/sentry-react-native/issues/6231))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
- Add `enableAutoConsoleLogs` option to opt out of automatic `console.*` capture while keeping `enableLogs: true` for manual `Sentry.logger.*` calls ([#6231](https://github.com/getsentry/sentry-react-native/issues/6231))
- Add `enableAutoConsoleLogs` option to opt out of automatic `console.*` capture while keeping `enableLogs: true` for manual `Sentry.logger.*` calls ([#6231](https://github.com/getsentry/sentry-react-native/pull/6235))


### Internal

- Convert `sentry.gradle` to Kotlin DSL (`sentry.gradle.kts`) ([#6119](https://github.com/getsentry/sentry-react-native/pull/6119))
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/js/integrations/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ export function getDefaultIntegrations(options: ReactNativeClientOptions): Integ
integrations.push(modulesLoaderIntegration());
if (options.enableLogs && options.logsOrigin !== 'native') {
integrations.push(logEnricherIntegration());
integrations.push(consoleLoggingIntegration());
if (options.enableAutoConsoleLogs !== false) {
integrations.push(consoleLoggingIntegration());
}
}
if (options.attachScreenshot) {
integrations.push(screenshotIntegration());
Expand Down
12 changes: 12 additions & 0 deletions packages/core/src/js/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,18 @@ export interface BaseReactNativeOptions {
*/
logsOrigin?: 'all' | 'js' | 'native';

/**
* When `enableLogs` is true, the SDK automatically captures `console.*` calls
* as logs via the `ConsoleLogs` integration. Set this to `false` to disable
* the automatic console capture while still being able to send logs manually
* via `Sentry.logger.*`.
*
* Has no effect when `enableLogs` is false or `logsOrigin` is `'native'`.
*
* @default true
*/
enableAutoConsoleLogs?: boolean;

/**
* A callback that is invoked when the native SDK emits a log message.
* This is useful for surfacing native SDK logs (e.g., transport errors like HTTP 413)
Expand Down
24 changes: 24 additions & 0 deletions packages/core/test/integrations/defaultLogs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,30 @@ describe('getDefaultIntegrations - logging integrations', () => {
expect(names).not.toContain(consoleLoggingIntegrationName);
});

it('keeps log enricher but drops console logging when enableAutoConsoleLogs is false', () => {
const names = getIntegrationNames(
createOptions({
enableLogs: true,
enableAutoConsoleLogs: false,
}),
);

expect(names).toContain(logEnricherIntegrationName);
expect(names).not.toContain(consoleLoggingIntegrationName);
});

it('adds console logging when enableAutoConsoleLogs is true (explicit default)', () => {
const names = getIntegrationNames(
createOptions({
enableLogs: true,
enableAutoConsoleLogs: true,
}),
);

expect(names).toContain(logEnricherIntegrationName);
expect(names).toContain(consoleLoggingIntegrationName);
});

it.each([
['all', true],
['js', true],
Expand Down
Loading