-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat(native): add structured logs documentation #15021
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9de8d9c
add native logs documentation
JoshuaMoelans c9d35ab
fix duplicate sentence
JoshuaMoelans 1abc448
update native from upcoming to supported
JoshuaMoelans 83340b2
Update platform-includes/logs/default-attributes/native.mdx
JoshuaMoelans 5ede2ac
Update includes/logs/default-attributes/core.mdx
JoshuaMoelans 1538c14
Update includes/logs/default-attributes/core.mdx
JoshuaMoelans 052b17a
Merge branch 'master' into feat/native/logs
AbhiPrasad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
includes/logs/default-attributes/message-template-examples/native.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
JoshuaMoelans marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
<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" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh good catch!