Skip to content

Commit 0463353

Browse files
authored
refactor(actix): improve Actix docs (#13821)
1 parent fa74849 commit 0463353

File tree

3 files changed

+46
-18
lines changed

3 files changed

+46
-18
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
title: Actix Web
Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
11
---
2-
title: actix-web
3-
description: "Learn about using Sentry with Actix Web."
2+
title: Actix Web
3+
description: "Learn about monitoring your Actix Web application with Sentry."
44
---
55

6-
The `sentry-actix` crate adds a middleware for [`actix-web`](https://actix.rs/) that captures errors and report them to `Sentry`.
6+
The Sentry SDK offers a middleware for the [Actix Web](https://actix.rs/) framework that supports:
77

8-
To use this middleware, configure Sentry then add it to your actix web app as a middleware. Because actix is generally working with non sendable objects and is highly concurrent, this middleware creates a new hub per request. As a result, many of the Sentry integrations, such as breadcrumbs, do not work unless you bind the actix hub.
8+
- Capturing server errors returned by Actix Web services.
9+
- Starting a [transaction](https://docs.sentry.io/concepts/key-terms/tracing/) for each request-response cycle.
910

10-
Note: Macros like `#[tokio::main]` and `#[actix_web::main]` are not supported. The Sentry client must be initialized before the async runtime is started so that all threads are correctly connected to the Hub.
11+
## Install
1112

12-
## Example
13-
14-
In your `Cargo.toml`:
13+
To add Sentry with the Actix Web integration to your Rust project, add a new dependency to your `Cargo.toml`:
1514

1615
```toml {filename:Cargo.toml}
1716
[dependencies]
18-
actix-web = "4.3.1"
19-
sentry = "{{@inject packages.version('sentry.rust') }}"
20-
sentry-actix = "{{@inject packages.version('sentry.rust') }}"
17+
actix-web = "4.11.0"
18+
sentry = { version = "{{@inject packages.version('sentry.rust') }}", features = ["actix"] }
2119
```
2220

23-
And your Rust code:
21+
## Configure
22+
23+
Initialize and configure the Sentry client. This will enable a set of default integrations, such as panic reporting.
24+
Then, initialize Actix Web with the Sentry middleware.
25+
26+
<Alert level="warning">
2427

28+
Macros like `#[tokio::main]` and `#[actix_web::main]` are not supported. The Sentry client must be initialized before the async runtime is started, as shown below.
29+
30+
</Alert>
2531

2632
```rust {filename:main.rs}
2733
use std::io;
@@ -38,18 +44,26 @@ fn main() -> io::Result<()> {
3844
"___PUBLIC_DSN___",
3945
sentry::ClientOptions {
4046
release: sentry::release_name!(),
47+
// Capture all traces and spans. Set to a lower value in production
48+
traces_sample_rate: 1.0,
4149
// Capture user IPs and potentially sensitive headers when using HTTP server integrations
4250
// see https://docs.sentry.io/platforms/rust/data-management/data-collected for more info
4351
send_default_pii: true,
52+
// Capture all HTTP request bodies, regardless of size
53+
max_request_body_size: sentry::MaxRequestBodySize::Always,
4454
..Default::default()
4555
},
4656
));
47-
std::env::set_var("RUST_BACKTRACE", "1");
4857

4958
actix_web::rt::System::new().block_on(async {
5059
HttpServer::new(|| {
5160
App::new()
52-
.wrap(sentry_actix::Sentry::new())
61+
.wrap(
62+
sentry::integrations::actix::Sentry::builder()
63+
.capture_server_errors(true) // Capture server errors
64+
.start_transaction(true) // Start a transaction (Sentry root span) for each request
65+
.finish(),
66+
)
5367
.service(failing)
5468
})
5569
.bind("127.0.0.1:3001")?
@@ -61,7 +75,20 @@ fn main() -> io::Result<()> {
6175
}
6276
```
6377

64-
## Reusing the Hub
78+
## Verify
79+
80+
The snippet above sets up a service that always fails, so you can test that everything is working as soon as you set it up.
81+
82+
Send a request to the application. The response error will be captured by Sentry.
83+
84+
```bash
85+
curl http://localhost:3001/
86+
```
87+
88+
<Alert>
89+
90+
Learn more about manually capturing an error or message in our <PlatformLink to="/usage/">Usage documentation</PlatformLink>.
91+
92+
</Alert>
6593

66-
When using the actix integration, a new per-request Hub will be created from the main Hub, and will be set automatically as the current Hub (`Hub::current()`).
67-
No manual intervention in needed.
94+
To view and resolve the recorded error, log into [sentry.io](https://sentry.io) and select your project. Clicking on the error's title will open a page where you can see detailed information and mark it as resolved.

docs/platforms/rust/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Using a framework? Check out the other SDKs we support in the left-hand dropdown
2121

2222
## Install
2323

24-
To add Sentry to your Rust project, just add a new dependency to your `Cargo.toml`:
24+
To add Sentry to your Rust project, add a new dependency to your `Cargo.toml`:
2525

2626
```toml {filename:Cargo.toml}
2727
[dependencies]

0 commit comments

Comments
 (0)