From 9de8d9cf92441ec5f38a187e190da5ac27d16b2b Mon Sep 17 00:00:00 2001 From: JoshuaMoelans <60878493+JoshuaMoelans@users.noreply.github.com> Date: Tue, 23 Sep 2025 12:56:56 +0200 Subject: [PATCH 1/6] add native logs documentation --- .../native/common/configuration/options.mdx | 14 ++++++++++ docs/platforms/native/logs/index.mdx | 28 +++++++++++++++++++ .../message-template-examples/native.mdx | 10 +++++++ .../logs/default-attributes/native.mdx | 9 ++++++ platform-includes/logs/options/native.mdx | 24 ++++++++++++++++ .../logs/requirements/native.mdx | 1 + platform-includes/logs/setup/native.mdx | 8 ++++++ platform-includes/logs/usage/native.mdx | 12 ++++++++ 8 files changed, 106 insertions(+) create mode 100644 docs/platforms/native/logs/index.mdx create mode 100644 includes/logs/default-attributes/message-template-examples/native.mdx create mode 100644 platform-includes/logs/default-attributes/native.mdx create mode 100644 platform-includes/logs/options/native.mdx create mode 100644 platform-includes/logs/requirements/native.mdx create mode 100644 platform-includes/logs/setup/native.mdx create mode 100644 platform-includes/logs/usage/native.mdx diff --git a/docs/platforms/native/common/configuration/options.mdx b/docs/platforms/native/common/configuration/options.mdx index 16e8a0c1dafdf..6de7b1b4b5918 100644 --- a/docs/platforms/native/common/configuration/options.mdx +++ b/docs/platforms/native/common/configuration/options.mdx @@ -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 must be defined to enable tracing. An example can be found in the [Sampling](/platforms/native/configuration/sampling/#setting-a-sampling-function) section. + +## Logs options + + + +This option enables the logging integration, which allows the SDK to capture logs and send them to Sentry. This is disabled by default. + + + + + +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. + + diff --git a/docs/platforms/native/logs/index.mdx b/docs/platforms/native/logs/index.mdx new file mode 100644 index 0000000000000..32140b4a29f89 --- /dev/null +++ b/docs/platforms/native/logs/index.mdx @@ -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 + + + +## Setup + + + +## Usage + + + +## Options + + + +## Default Attributes + + diff --git a/includes/logs/default-attributes/message-template-examples/native.mdx b/includes/logs/default-attributes/message-template-examples/native.mdx new file mode 100644 index 0000000000000..25991274cf329 --- /dev/null +++ b/includes/logs/default-attributes/message-template-examples/native.mdx @@ -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" diff --git a/platform-includes/logs/default-attributes/native.mdx b/platform-includes/logs/default-attributes/native.mdx new file mode 100644 index 0000000000000..13763cf8e29f2 --- /dev/null +++ b/platform-includes/logs/default-attributes/native.mdx @@ -0,0 +1,9 @@ +The Android SDK automatically sets several default attributes on all log entries to provide context and improve debugging: + + + + + + + + diff --git a/platform-includes/logs/options/native.mdx b/platform-includes/logs/options/native.mdx new file mode 100644 index 0000000000000..803402b19bfa4 --- /dev/null +++ b/platform-includes/logs/options/native.mdx @@ -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. diff --git a/platform-includes/logs/requirements/native.mdx b/platform-includes/logs/requirements/native.mdx new file mode 100644 index 0000000000000..81465343938a2 --- /dev/null +++ b/platform-includes/logs/requirements/native.mdx @@ -0,0 +1 @@ +Logs for Native are supported in Sentry Native SDK version `0.12.0` and above. diff --git a/platform-includes/logs/setup/native.mdx b/platform-includes/logs/setup/native.mdx new file mode 100644 index 0000000000000..0f3dc535535f4 --- /dev/null +++ b/platform-includes/logs/setup/native.mdx @@ -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); +``` diff --git a/platform-includes/logs/usage/native.mdx b/platform-includes/logs/usage/native.mdx new file mode 100644 index 0000000000000..043121b1cb51f --- /dev/null +++ b/platform-includes/logs/usage/native.mdx @@ -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"); +``` From c9d35ab6fef8179dd650d8c83cc44e9818afba02 Mon Sep 17 00:00:00 2001 From: JoshuaMoelans <60878493+JoshuaMoelans@users.noreply.github.com> Date: Tue, 23 Sep 2025 13:10:01 +0200 Subject: [PATCH 2/6] fix duplicate sentence --- includes/logs/default-attributes/core.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/logs/default-attributes/core.mdx b/includes/logs/default-attributes/core.mdx index 30929c220c7e8..f7c9006f7834c 100644 --- a/includes/logs/default-attributes/core.mdx +++ b/includes/logs/default-attributes/core.mdx @@ -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. From 1abc44804ebc5cf0af093880eeecd6dfbd2840b4 Mon Sep 17 00:00:00 2001 From: JoshuaMoelans <60878493+JoshuaMoelans@users.noreply.github.com> Date: Tue, 23 Sep 2025 15:02:17 +0200 Subject: [PATCH 3/6] update native from upcoming to supported --- docs/product/explore/logs/getting-started/index.mdx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/product/explore/logs/getting-started/index.mdx b/docs/product/explore/logs/getting-started/index.mdx index 0cba73b2dbd47..7e7a1999d7b12 100644 --- a/docs/product/explore/logs/getting-started/index.mdx +++ b/docs/product/explore/logs/getting-started/index.mdx @@ -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 + +- + ## Upcoming SDKs We're actively working on adding Log functionality to additional SDKs. Check out these GitHub issues for the latest updates: @@ -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" /> -- 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! From 83340b2d9cb99c864333cdc23915340c71b9d7cf Mon Sep 17 00:00:00 2001 From: JoshuaMoelans <60878493+JoshuaMoelans@users.noreply.github.com> Date: Tue, 23 Sep 2025 18:31:51 +0200 Subject: [PATCH 4/6] Update platform-includes/logs/default-attributes/native.mdx Co-authored-by: Abhijeet Prasad --- platform-includes/logs/default-attributes/native.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform-includes/logs/default-attributes/native.mdx b/platform-includes/logs/default-attributes/native.mdx index 13763cf8e29f2..608b63353461d 100644 --- a/platform-includes/logs/default-attributes/native.mdx +++ b/platform-includes/logs/default-attributes/native.mdx @@ -1,4 +1,4 @@ -The Android SDK automatically sets several default attributes on all log entries to provide context and improve debugging: +The Native SDK automatically sets several default attributes on all log entries to provide context and improve debugging: From 5ede2ac25627c7e14fe387e4154cb3f6daf9cb80 Mon Sep 17 00:00:00 2001 From: JoshuaMoelans <60878493+JoshuaMoelans@users.noreply.github.com> Date: Tue, 23 Sep 2025 18:36:19 +0200 Subject: [PATCH 5/6] Update includes/logs/default-attributes/core.mdx --- includes/logs/default-attributes/core.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/logs/default-attributes/core.mdx b/includes/logs/default-attributes/core.mdx index f7c9006f7834c..18078428bb40c 100644 --- a/includes/logs/default-attributes/core.mdx +++ b/includes/logs/default-attributes/core.mdx @@ -4,4 +4,4 @@ - `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`. -- `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` From 1538c145d4fcb6fa67de74e47973532ffb498f2c Mon Sep 17 00:00:00 2001 From: JoshuaMoelans <60878493+JoshuaMoelans@users.noreply.github.com> Date: Tue, 23 Sep 2025 18:36:49 +0200 Subject: [PATCH 6/6] Update includes/logs/default-attributes/core.mdx --- includes/logs/default-attributes/core.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/logs/default-attributes/core.mdx b/includes/logs/default-attributes/core.mdx index 18078428bb40c..e93138ee84670 100644 --- a/includes/logs/default-attributes/core.mdx +++ b/includes/logs/default-attributes/core.mdx @@ -4,4 +4,4 @@ - `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`. -- `sdk.version`: The version of the SDK that sent the log. This is sent from the SDK as `sentry.sdk.version` +- `sdk.version`: The version of the SDK that sent the log. This is sent from the SDK as `sentry.sdk.version`.