Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
14 changes: 14 additions & 0 deletions docs/platforms/native/common/configuration/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,17 @@ A number between `0.0` and `1.0`, controlling the percentage chance a given tran
A function responsible for determining the percentage chance a given transaction will be sent to Sentry. It will automatically be passed information about the transaction and the context in which it's being created, and must return a number between `0` (0% chance of being sent) and `1` (100% chance of being sent). Can also be used for filtering transactions, by returning 0 for those that are unwanted. Either this or <PlatformIdentifier name="traces-sample-rate" /> must be defined to enable tracing. An example can be found in the [Sampling](/platforms/native/configuration/sampling/#setting-a-sampling-function) section.

</ConfigKey>

## Logs options

<ConfigKey name="enable-logs">

This option enables the logging integration, which allows the SDK to capture logs and send them to Sentry. This is disabled by default.

</ConfigKey>

<ConfigKey name="before-send-log">

This function is called with an SDK-specific log object, and can return a modified log object, or `sentry_value_new_null()` to drop the log.

</ConfigKey>
28 changes: 28 additions & 0 deletions docs/platforms/native/logs/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
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
---

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" />

## Options

<PlatformContent includePath="logs/options" />

## Default Attributes

<PlatformContent includePath="logs/default-attributes" />
13 changes: 8 additions & 5 deletions docs/product/explore/logs/getting-started/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,14 @@ To set up Sentry Logs, use the links below for supported SDKs. After it's been s
url="/platforms/dotnet/guides/extensions-logging/logs/"
/>

### Native

- <LinkWithPlatformIcon
platform="native"
label="Native"
url="/platforms/native/logs"
/>

## Upcoming SDKs

We're actively working on adding Log functionality to additional SDKs. Check out these GitHub issues for the latest updates:
Expand All @@ -301,10 +309,5 @@ We're actively working on adding Log functionality to additional SDKs. Check out
label="Unreal"
url="https://github.com/getsentry/sentry-unreal/issues/883"
/>
- <LinkWithPlatformIcon
platform="native"
label="Native"
url="https://github.com/getsentry/sentry-native/issues/1210"
/>

If you don't see your platform listed above, please reach out to us on [GitHub](https://github.com/getsentry/sentry/discussions/86804) or [Discord](https://discord.gg/sentry), we'll get it prioritized!
4 changes: 2 additions & 2 deletions includes/logs/default-attributes/core.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
- `environment`: The environment set in the SDK if defined. This is sent from the SDK as `sentry.environment`.
- `release`: The release set in the SDK if defined. This is sent from the SDK as `sentry.release`.
- `trace.parent_span_id`: The span ID of the span that was active when the log was collected (only set if there was an active span). This is sent from the SDK as `sentry.trace.parent_span_id`.
- `sdk.name`: The name of the SDK that sent the log. This is sent from the SDK as `sentry.sdk.name`. This is sent from the SDK as `sentry.sdk.name`.
- `sdk.version`: The version of the SDK that sent the log. This is sent from the SDK as `sentry.sdk.version`. This is sent from the SDK as `sentry.sdk.version`.
- `sdk.name`: The name of the SDK that sent the log. This is sent from the SDK as `sentry.sdk.name`.
- `sdk.version`: The version of the SDK that sent the log. This is sent from the SDK as `sentry.sdk.
Copy link
Member

Choose a reason for hiding this comment

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

Why is this diff changed?

Copy link
Member Author

@JoshuaMoelans JoshuaMoelans Sep 23, 2025

Choose a reason for hiding this comment

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

The old version has a duplicate sentence at the end (This is sent from the SDK as sentry.sdk.name.)

Looks like I removed a bit too much from the bottom one though

Copy link
Member

Choose a reason for hiding this comment

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

Oh good catch!

Suggested change
- `sdk.name`: The name of the SDK that sent the log. This is sent from the SDK as `sentry.sdk.name`.
- `sdk.version`: The version of the SDK that sent the log. This is sent from the SDK as `sentry.sdk.
- `sdk.version`: The version of the SDK that sent the log. This is sent from the SDK as `sentry.sdk.version`.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
For example, with the following log:

```c
sentry_log_error("A %s log message", "formatted");
```

Sentry will add the following attributes:

- `message.template`: "A %s log message"
- `message.parameter.0`: "formatted"
9 changes: 9 additions & 0 deletions platform-includes/logs/default-attributes/native.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The Android SDK automatically sets several default attributes on all log entries to provide context and improve debugging:

<Include name="logs/default-attributes/core" />

<Include name="logs/default-attributes/message-template" />

<Include name="logs/default-attributes/message-template-examples/native" />

<Include name="logs/default-attributes/user-mobile" />
24 changes: 24 additions & 0 deletions platform-includes/logs/options/native.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#### before_send_log

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

```c
static sentry_value_t
before_send_log_callback(sentry_value_t log, void *user_data)
{
(void)user_data;
sentry_value_t attribute = sentry_value_new_object();
sentry_value_set_by_key(
attribute, "value", sentry_value_new_string("little"));
sentry_value_set_by_key(
attribute, "type", sentry_value_new_string("string"));
sentry_value_set_by_key(sentry_value_get_by_key(log, "attributes"),
"coffeepot.size", attribute);
return log;
}

sentry_options_set_before_send_log(options, before_send_log_callback, NULL);
```


The `before_send_log` function receives a log object and optional `user_data`, and should return the log object if you want it to be sent to Sentry, or it should free the log using `sentry_value_decref(log)` and return a `sentry_value_new_null()` if you want to discard it.
1 change: 1 addition & 0 deletions platform-includes/logs/requirements/native.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Logs for Native are supported in Sentry Native SDK version `0.12.0` and above.
8 changes: 8 additions & 0 deletions platform-includes/logs/setup/native.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
To enable logging, you need to initialize the SDK with the `enable_logs` option set to `true`.

```c
sentry_options_t *options = sentry_options_new();
sentry_options_set_enable_logs(options, true);
// set other options
sentry_init(options);
```
12 changes: 12 additions & 0 deletions platform-includes/logs/usage/native.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Once the feature is enabled on the SDK and the SDK is initialized, you can send logs using the `sentry_log_X()` APIs.

The API exposes six methods that you can use to log messages at different log levels: `trace`, `debug`, `info`, `warn`, `error`, and `fatal`.

These properties will be sent to Sentry, and can be searched from within the Logs UI, and even added to the Logs views as a dedicated column.

```c
import io.sentry.Sentry;

sentry_log_info("A simple log message");
sentry_log_error("A %s log message", "formatted");
```
Loading