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/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! diff --git a/includes/logs/default-attributes/core.mdx b/includes/logs/default-attributes/core.mdx index 30929c220c7e8..e93138ee84670 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.version`. 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..608b63353461d --- /dev/null +++ b/platform-includes/logs/default-attributes/native.mdx @@ -0,0 +1,9 @@ +The Native 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"); +```