Skip to content

feat(React Native): Add Logs documentation #13934

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
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
32 changes: 32 additions & 0 deletions docs/platforms/react-native/logs/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
title: Set Up Logs
sidebar_title: Logs
description: "Structured logs allow you to send, view and query logs sent from your applications within Sentry."
sidebar_order: 5755
---

<PlatformContent includePath="llm-rules-logs" />

<Include name="feature-stage-beta-logs.mdx" />

With Sentry Structured Logs, you can send text based log information from your applications to Sentry. Once in Sentry, these logs can be viewed alongside relevant errors, searched by text-string, or searched using their individual attributes.

## Requirements

<PlatformContent includePath="logs/requirements" />

## Setup

<PlatformContent includePath="logs/setup" />

## Usage

<PlatformContent includePath="logs/usage" />

## Integrations

<PlatformContent includePath="logs/integrations" />

## Options

<PlatformContent includePath="logs/options" />
1 change: 1 addition & 0 deletions platform-includes/logs/integrations/react-native.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<Include name="logs/javascript-console-logging-integration.mdx" />
29 changes: 29 additions & 0 deletions platform-includes/logs/options/react-native.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#### beforeSendLog

To filter logs, or update them before they are sent to Sentry, you can use the `_experiments.beforeSendLog` option.

```js
Sentry.init({
dsn: "___PUBLIC_DSN___",
_experiments: {
enableLogs: true,
beforeSendLog: (log) => {
if (log.level === "info") {
// Filter out all info logs
return null;
}

return log;
},
},
});
```

The `beforeSendLog` function receives a log object, and should return the log object if you want it to be sent to Sentry, or `null` if you want to discard it.

The log object has the following properties:

- `level`: (string - one of `trace`, `debug`, `info`, `warn`, `error`, `fatal`) The log level.
- `message`: (string) The message to be logged.
- `timestamp`: (number) The timestamp of the log.
- `attributes`: (object) The attributes of the log.
1 change: 1 addition & 0 deletions platform-includes/logs/requirements/react-native.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Logs for React Native are supported in Sentry React Native SDK version `7.0.0-beta.1` and above.
9 changes: 9 additions & 0 deletions platform-includes/logs/setup/react-native.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
To enable logging, you need to initialize the SDK with the `_experiments.enableLogs` option set to `true`.

```js
Sentry.init({
dsn: "___PUBLIC_DSN___",
// Enable logs to be sent to Sentry
_experiments: { enableLogs: true },
});
```
1 change: 1 addition & 0 deletions platform-includes/logs/usage/react-native.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<Include name="logs/javascript-usage.mdx" />