diff --git a/docs/platforms/react-native/integrations/console-logging.mdx b/docs/platforms/react-native/integrations/console-logging.mdx index 851556f2b56d7..28b5f232efeb0 100644 --- a/docs/platforms/react-native/integrations/console-logging.mdx +++ b/docs/platforms/react-native/integrations/console-logging.mdx @@ -5,37 +5,49 @@ description: "Capture console API calls as Sentry logs in React Native." -Enable the Sentry Logs feature with `enableLogs: true` in your `Sentry.init` call to unlock Sentry's full logging power. With Sentry Logs, you can search, filter, and analyze logs from across your entire application in one place. +Sentry Logs are enabled by default. Calls to `Sentry.logger.*` are sent without any extra configuration. With Sentry Logs, you can search, filter, and analyze logs from across your entire application in one place. -Console Logging integration is enabled by default which means calls to the `console` API will be captured as logs in Sentry. By default the integration instruments `console.debug`, `console.info`, `console.warn`, `console.error`, `console.log`, `console.trace`, and `console.assert`. +The Console Logging integration captures calls to the `console` API as logs in Sentry. By default the integration instruments `console.debug`, `console.info`, `console.warn`, `console.error`, `console.log`, `console.trace`, and `console.assert`. -## Disabling Console Logging Integration +## Enabling Console Logging Integration -To disable the integration, filter it out from the integrations array: +The integration is opt-in and must be added explicitly to the `integrations` array of your `Sentry.init` call: ```js +import * as Sentry from "@sentry/react-native"; + Sentry.init({ - ..., - integrations(integrations) { - return integrations.filter(i => i.name !== 'ConsoleLogs'); - }, - ... -}) + dsn: "___PUBLIC_DSN___", + integrations: [Sentry.consoleLoggingIntegration()], +}); +``` + +You can pass a `levels` option to limit which `console` methods are instrumented: + +```js +Sentry.init({ + dsn: "___PUBLIC_DSN___", + integrations: [ + Sentry.consoleLoggingIntegration({ levels: ["error", "warn"] }), + ], +}); ``` -You can also filter out the automatically captured logs in `beforeSendLog`: +## Filtering Console Logs + +If you want to drop specific console-originated logs, use `beforeSendLog`: ```js Sentry.init({ - ..., + dsn: "___PUBLIC_DSN___", + integrations: [Sentry.consoleLoggingIntegration()], beforeSendLog: (log) => { - if (log.attributes?.['sentry.origin'] === 'auto.log.console') { + if (log.attributes?.["sentry.origin"] === "auto.log.console") { return null; } return log; }, - ... -}) +}); ``` diff --git a/platform-includes/logs/options/react-native.mdx b/platform-includes/logs/options/react-native.mdx index ba2f914b0ae32..59aa3bf540fa7 100644 --- a/platform-includes/logs/options/react-native.mdx +++ b/platform-includes/logs/options/react-native.mdx @@ -5,7 +5,6 @@ To filter logs, or update them before they are sent to Sentry, you can use the ` ```js Sentry.init({ dsn: "___PUBLIC_DSN___", - enableLogs: true, beforeSendLog: (log) => { if (log.level === "info") { // Filter out all info logs diff --git a/platform-includes/logs/setup/react-native.mdx b/platform-includes/logs/setup/react-native.mdx index 99356aaa29e8c..c2f56f41dfaea 100644 --- a/platform-includes/logs/setup/react-native.mdx +++ b/platform-includes/logs/setup/react-native.mdx @@ -1,9 +1,13 @@ -To enable logging, you need to initialize the SDK with the `enableLogs` option set to `true`. +Logs are enabled by default. Once the SDK is initialized, calls to `Sentry.logger.*` are sent to Sentry without any extra configuration. + +To explicitly disable log capturing, set the `enableLogs` option to `false`: ```js Sentry.init({ dsn: "___PUBLIC_DSN___", - // Enable logs to be sent to Sentry - enableLogs: true, + // Disable logs from being sent to Sentry + enableLogs: false, }); ``` + +Integrations that automatically capture logs from third-party APIs (such as the [Console logging integration](/platforms/react-native/integrations/console-logging/)) are opt-in. Add them explicitly to the `integrations` array if you want them.