Skip to content

Commit 0b44c25

Browse files
Merge branch 'master' into cursor/add-logs-beta-checkbox-for-sdks-73b7
2 parents b6e37e7 + 9095c6a commit 0b44c25

File tree

4 files changed

+102
-3
lines changed

4 files changed

+102
-3
lines changed

develop-docs/sdk/telemetry/logs.mdx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,6 @@ If a log is generated by an SDK integration, the SDK should also set the `sentry
311311

312312
#### User Attributes
313313

314-
If `sendDefaultPii`/`send_default_pii` is set to `true` in the SDK, the SDK should attach the following user data if available:
315-
316314
1. `user.id`: The user ID. Maps to `id` in the [User](/sdk/data-model/event-payloads/user/) payload.
317315
2. `user.name`: The username. Maps to `username` in the [User](/sdk/data-model/event-payloads/user/) payload.
318316
3. `user.email`: The email address. Maps to `email` in the [User](/sdk/data-model/event-payloads/user/) payload.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
title: Set Up Logs in Rust
3+
sidebar_title: Logs
4+
description: "Structured logs allow you to send, view, and query logs sent from your applications within Sentry."
5+
sidebar_order: 5600
6+
---
7+
8+
<Include name="feature-stage-beta-logs.mdx" />
9+
10+
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.
11+
12+
## Requirements
13+
14+
Logs in Rust are supported in Sentry Rust SDK version `0.39.0` and above.
15+
Additionally, the `logs` feature flag needs to be enabled.
16+
17+
```toml {filename:Cargo.toml}
18+
[dependencies]
19+
sentry = { version = "{{@inject packages.version('sentry.rust') }}", features = ["logs"] }
20+
```
21+
22+
## Setup
23+
24+
To enable logging, you need to initialize the SDK with the `enable_logs` option set to `true`.
25+
26+
```rust
27+
let _guard = sentry::init(("___PUBLIC_DSN___", sentry::ClientOptions {
28+
release: sentry::release_name!(),
29+
enable_logs: true,
30+
..Default::default()
31+
}));
32+
```
33+
34+
## Usage
35+
36+
Once the feature is enabled on the SDK and the SDK is initialized, you can send logs by using the logging macros.
37+
The `sentry` crate exposes macros that support six different log levels:
38+
`logger_trace`, `logger_debug`, `logger_info`, `logger_warn`, `logger_error` and `logger_fatal`.
39+
The macros support logging a simple message, or a message with parameters, with `format` syntax:
40+
41+
```rust
42+
use sentry::logger_info;
43+
44+
logger_info!("Hello, world!");
45+
logger_info!("Hello, {}!", "world");
46+
```
47+
48+
You can also attach additional attributes to a log using the `key = value` syntax before the message:
49+
50+
```rust
51+
use sentry::logger_error;
52+
53+
logger_error!(
54+
database.host = "prod-db-01",
55+
database.port = 5432,
56+
database.name = "user_service",
57+
retry_attempt = 2,
58+
beta_features = false,
59+
"Database connection failed"
60+
);
61+
```
62+
63+
The supported attribute keys consist of any number of valid Rust identifiers, separated by dots.
64+
Attributes containing dots will be nested under their common prefix when displayed in the UI.
65+
66+
The supported attribute values correspond to the values that can be converted to a `serde_json::Value`,
67+
which include primitive types for numbers, `bool`, and string types.
68+
As of today, array and object types will be converted to strings using their JSON representation.
69+
70+
## Integrations
71+
72+
We're actively working on adding integration support for Logs.
73+
Currently, we're looking at adding support for the `tracing` and `log` crates.
74+
You can follow progress on the following GitHub issues or open a [new one](https://github.com/getsentry/sentry-rust/issues/new/choose) for any additional integration you would like to see.
75+
- [`tracing`](https://github.com/getsentry/sentry-rust/issues/799)
76+
- [`log`](https://github.com/getsentry/sentry-rust/issues/818)
77+
78+
## Options
79+
80+
### `before_send_log`
81+
82+
To filter logs, or update them before they are sent to Sentry, you can use the `before_send_log` client option.
83+
84+
```rust
85+
let _guard = sentry::init(("___PUBLIC_DSN___", sentry::ClientOptions {
86+
release: sentry::release_name!(),
87+
enable_logs: true,
88+
before_send_log: Some(std::sync::Arc::new(|log| {
89+
// filter out all trace level logs
90+
if log.level == sentry::protocol::LogLevel::Trace {
91+
return None;
92+
}
93+
Some(log)
94+
})),
95+
..Default::default()
96+
}));
97+
```

docs/product/ai-in-sentry/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ Seer is Sentry's AI debugging agent that helps resolve errors and performance is
1414

1515
- **[Issue Fix](/product/ai-in-sentry/seer/issue-fix/)**: Automated root cause analysis and suggested code fixes.
1616
- **Issue Scan**: Scans issues as they are ingested in Sentry to determine an actionability score and run Seer's Issue Fix on them automatically.
17-
1817
- **[Privacy &amp; Security](/product/ai-in-sentry/seer/seer-privacy-security/)**: Understanding how Seer handles your data securely.
1918

19+
2020
## Issue Summary
2121

2222
Issue Summary provides a quick overview of an issue by highlighting key insights taken from event and issue-level metadata. You'll see a quick overview of what's going wrong, a potential cause, and if relevant, insights from trace-connected issues.

docs/product/explore/logs/getting-started/index.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ To set up Sentry Logs, use the links below for supported SDKs. After it's been s
227227

228228
- <LinkWithPlatformIcon platform="go" label="Go" url="/platforms/go/logs/" />
229229

230+
### Rust
231+
232+
- <LinkWithPlatformIcon platform="rust" label="Rust" url="/platforms/rust/logs/" />
233+
230234
## Upcoming SDKs
231235

232236
We're actively working on adding Log functionality to additional SDKs. Check out these GitHub issues for the latest updates:

0 commit comments

Comments
 (0)