You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: "Learn about using Sentry with Actix Web."
2
+
title: Actix Web
3
+
description: "Learn about monitoring your Actix Web application with Sentry."
4
4
---
5
5
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:
7
7
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.
9
10
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
11
12
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`:
sentry = { version = "{{@inject packages.version('sentry.rust') }}", features = ["actix"] }
21
19
```
22
20
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
+
<Alertlevel="warning">
24
27
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>
25
31
26
32
```rust {filename:main.rs}
27
33
usestd::io;
@@ -38,18 +44,26 @@ fn main() -> io::Result<()> {
38
44
"___PUBLIC_DSN___",
39
45
sentry::ClientOptions {
40
46
release:sentry::release_name!(),
47
+
// Capture all traces and spans. Set to a lower value in production
48
+
traces_sample_rate:1.0,
41
49
// Capture user IPs and potentially sensitive headers when using HTTP server integrations
42
50
// see https://docs.sentry.io/platforms/rust/data-management/data-collected for more info
43
51
send_default_pii:true,
52
+
// Capture all HTTP request bodies, regardless of size
.capture_server_errors(true) // Capture server errors
64
+
.start_transaction(true) // Start a transaction (Sentry root span) for each request
65
+
.finish(),
66
+
)
53
67
.service(failing)
54
68
})
55
69
.bind("127.0.0.1:3001")?
@@ -61,7 +75,20 @@ fn main() -> io::Result<()> {
61
75
}
62
76
```
63
77
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 <PlatformLinkto="/usage/">Usage documentation</PlatformLink>.
91
+
92
+
</Alert>
65
93
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.
0 commit comments