Skip to content

Commit 761e27c

Browse files
Swatinemfourbytes
andauthored
ref: Update actix integration to actix-web 4 (#437)
Co-authored-by: Oscar Rainford <[email protected]>
1 parent 871f727 commit 761e27c

File tree

20 files changed

+132
-83
lines changed

20 files changed

+132
-83
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ jobs:
9999
fail-fast: false
100100
matrix:
101101
os: [ubuntu-latest, macos-latest, windows-latest]
102-
rust: [1.53.0]
102+
rust: [1.54.0]
103103

104104
name: Check / Test MSRV ${{ matrix.rust }} on ${{ matrix.os }}
105105
runs-on: ${{ matrix.os }}

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
**Breaking Changes**:
6+
7+
- The minium supported Rust version was bumped to **1.54.0** due to requirements from dependencies.
8+
- Updated the `sentry-actix` integration to `actix-web@4`. ([#437](https://github.com/getsentry/sentry-rust/pull/437))
9+
10+
**Features**:
11+
12+
- Calling `Scope::set_transaction` will override the Transaction name of any currently running performance monitoring transaction. ([#433](https://github.com/getsentry/sentry-rust/pull/433))
13+
14+
**Fixes**:
15+
16+
- Make sure Spans/Transactions have a meaningful/non-empty name. ([#434](https://github.com/getsentry/sentry-rust/pull/434))
17+
18+
**Thank you**:
19+
20+
Features, fixes and improvements in this release have been contributed by:
21+
22+
- [@jessfraz](https://github.com/jessfraz)
23+
- [@fourbytes](https://github.com/fourbytes)
24+
325
## 0.24.3
426

527
**Features**:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ best API and adding new features.
9494
We currently only verify this crate against a recent version of Sentry hosted on [sentry.io](https://sentry.io/) but it
9595
should work with on-prem Sentry versions 20.6 and later.
9696

97-
The **Minimum Supported Rust Version** is currently at _1.53.0_.
97+
The **Minimum Supported Rust Version** is currently at _1.54.0_.
9898
The Sentry crates will support a _6 month_ old Rust version at time of release,
9999
and the MSRV will be increased in accordance with its dependencies.
100100

clippy.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
msrv = "1.53"
1+
msrv = "1.54"

sentry-actix/Cargo.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ Sentry client extension for actix-web 3.
1212
edition = "2018"
1313

1414
[dependencies]
15-
sentry-core = { version = "0.24.3", path = "../sentry-core", default-features = false, features = ["client"] }
16-
actix-web = { version = "3", default-features = false }
15+
actix-web = { version = "4", default-features = false }
1716
futures-util = { version = "0.3.5", default-features = false }
17+
sentry-core = { version = "0.24.3", path = "../sentry-core", default-features = false, features = ["client"] }
1818

1919
[dev-dependencies]
20-
sentry = { path = "../sentry", features = ["test"] }
21-
actix-rt = "2.1.0"
20+
actix-web = { version = "4" }
2221
futures = "0.3"
22+
sentry = { path = "../sentry", features = ["test"] }
23+
tokio = { version = "1.0", features = ["full"] }

sentry-actix/examples/basic.rs

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,35 @@ async fn captures_message(_req: HttpRequest) -> Result<String, Error> {
2121
}
2222

2323
// cargo run -p sentry-actix --example basic
24-
#[actix_web::main]
25-
async fn main() -> io::Result<()> {
24+
fn main() -> io::Result<()> {
2625
let _guard = sentry::init(sentry::ClientOptions {
26+
release: sentry::release_name!(),
2727
auto_session_tracking: true,
2828
traces_sample_rate: 1.0,
2929
session_mode: sentry::SessionMode::Request,
30+
debug: true,
3031
..Default::default()
3132
});
3233
env::set_var("RUST_BACKTRACE", "1");
3334

34-
let addr = "127.0.0.1:3001";
35-
36-
println!("Starting server on http://{}", addr);
37-
38-
HttpServer::new(|| {
39-
App::new()
40-
.wrap(sentry_actix::Sentry::with_transaction())
41-
.service(healthy)
42-
.service(errors)
43-
.service(captures_message)
35+
let runtime = tokio::runtime::Builder::new_multi_thread()
36+
.enable_all()
37+
.build()?;
38+
39+
runtime.block_on(async move {
40+
let addr = "127.0.0.1:3001";
41+
42+
println!("Starting server on http://{}", addr);
43+
44+
HttpServer::new(|| {
45+
App::new()
46+
.wrap(sentry_actix::Sentry::with_transaction())
47+
.service(healthy)
48+
.service(errors)
49+
.service(captures_message)
50+
})
51+
.bind(addr)?
52+
.run()
53+
.await
4454
})
45-
.bind(addr)?
46-
.run()
47-
.await?;
48-
49-
Ok(())
5055
}

sentry-actix/src/lib.rs

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,26 @@
1818
//! Err(io::Error::new(io::ErrorKind::Other, "An error happens here").into())
1919
//! }
2020
//!
21-
//! #[actix_web::main]
22-
//! async fn main() -> io::Result<()> {
23-
//! let _guard = sentry::init(());
21+
//! fn main() -> io::Result<()> {
22+
//! let _guard = sentry::init(sentry::ClientOptions {
23+
//! release: sentry::release_name!(),
24+
//! ..Default::default()
25+
//! });
2426
//! std::env::set_var("RUST_BACKTRACE", "1");
2527
//!
26-
//! HttpServer::new(|| {
27-
//! App::new()
28-
//! .wrap(sentry_actix::Sentry::new())
29-
//! .service(failing)
28+
//! let runtime = tokio::runtime::Builder::new_multi_thread()
29+
//! .enable_all()
30+
//! .build()?;
31+
//! runtime.block_on(async move {
32+
//! HttpServer::new(|| {
33+
//! App::new()
34+
//! .wrap(sentry_actix::Sentry::new())
35+
//! .service(failing)
36+
//! })
37+
//! .bind("127.0.0.1:3001")?
38+
//! .run()
39+
//! .await
3040
//! })
31-
//! .bind("127.0.0.1:3001")?
32-
//! .run()
33-
//! .await?;
34-
//!
35-
//! Ok(())
3641
//! }
3742
//! ```
3843
//!
@@ -44,6 +49,7 @@
4449
//!
4550
//! ```
4651
//! let _sentry = sentry::init(sentry::ClientOptions {
52+
//! release: sentry::release_name!(),
4753
//! session_mode: sentry::SessionMode::Request,
4854
//! auto_session_tracking: true,
4955
//! ..Default::default()
@@ -172,12 +178,11 @@ impl Default for Sentry {
172178
}
173179
}
174180

175-
impl<S, B> Transform<S> for Sentry
181+
impl<S, B> Transform<S, ServiceRequest> for Sentry
176182
where
177-
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
183+
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
178184
S::Future: 'static,
179185
{
180-
type Request = ServiceRequest;
181186
type Response = ServiceResponse<B>;
182187
type Error = Error;
183188
type Transform = SentryMiddleware<S>;
@@ -198,24 +203,23 @@ pub struct SentryMiddleware<S> {
198203
inner: Sentry,
199204
}
200205

201-
impl<S, B> Service for SentryMiddleware<S>
206+
impl<S, B> Service<ServiceRequest> for SentryMiddleware<S>
202207
where
203-
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
208+
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
204209
S::Future: 'static,
205210
{
206-
type Request = ServiceRequest;
207211
type Response = ServiceResponse<B>;
208212
type Error = Error;
209213
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>>>>;
210214

211215
fn poll_ready(
212-
&mut self,
216+
&self,
213217
cx: &mut std::task::Context<'_>,
214218
) -> std::task::Poll<Result<(), Self::Error>> {
215219
self.service.poll_ready(cx)
216220
}
217221

218-
fn call(&mut self, req: ServiceRequest) -> Self::Future {
222+
fn call(&self, req: ServiceRequest) -> Self::Future {
219223
let inner = self.inner.clone();
220224
let hub = Arc::new(Hub::new_from_top(
221225
inner.hub.clone().unwrap_or_else(Hub::main),
@@ -412,7 +416,7 @@ mod tests {
412416
}
413417

414418
/// Test explicit events sent to the current Hub inside an Actix service.
415-
#[actix_rt::test]
419+
#[actix_web::test]
416420
async fn test_explicit_events() {
417421
let events = sentry::test::with_captured_events(|| {
418422
block_on(async {
@@ -428,7 +432,7 @@ mod tests {
428432
HttpResponse::Ok()
429433
};
430434

431-
let mut app = init_service(
435+
let app = init_service(
432436
App::new()
433437
.wrap(Sentry::builder().with_hub(Hub::current()).finish())
434438
.service(web::resource("/test").to(service)),
@@ -438,7 +442,7 @@ mod tests {
438442
// Call the service twice (sequentially) to ensure the middleware isn't sticky
439443
for _ in 0..2 {
440444
let req = TestRequest::get().uri("/test").to_request();
441-
let res = call_service(&mut app, req).await;
445+
let res = call_service(&app, req).await;
442446
assert!(res.status().is_success());
443447
}
444448
})
@@ -455,7 +459,7 @@ mod tests {
455459
}
456460

457461
/// Ensures errors returned in the Actix service trigger an event.
458-
#[actix_rt::test]
462+
#[actix_web::test]
459463
async fn test_response_errors() {
460464
let events = sentry::test::with_captured_events(|| {
461465
block_on(async {
@@ -467,7 +471,7 @@ mod tests {
467471
Err(io::Error::new(io::ErrorKind::Other, "Test Error").into())
468472
}
469473

470-
let mut app = init_service(
474+
let app = init_service(
471475
App::new()
472476
.wrap(Sentry::builder().with_hub(Hub::current()).finish())
473477
.service(failing),
@@ -477,7 +481,7 @@ mod tests {
477481
// Call the service twice (sequentially) to ensure the middleware isn't sticky
478482
for _ in 0..2 {
479483
let req = TestRequest::get().uri("/test").to_request();
480-
let res = call_service(&mut app, req).await;
484+
let res = call_service(&app, req).await;
481485
assert!(res.status().is_server_error());
482486
}
483487
})
@@ -496,21 +500,21 @@ mod tests {
496500
}
497501

498502
/// Ensures client errors (4xx) are not captured.
499-
#[actix_rt::test]
503+
#[actix_web::test]
500504
async fn test_client_errors_discarded() {
501505
let events = sentry::test::with_captured_events(|| {
502506
block_on(async {
503507
let service = HttpResponse::NotFound;
504508

505-
let mut app = init_service(
509+
let app = init_service(
506510
App::new()
507511
.wrap(Sentry::builder().with_hub(Hub::current()).finish())
508512
.service(web::resource("/test").to(service)),
509513
)
510514
.await;
511515

512516
let req = TestRequest::get().uri("/test").to_request();
513-
let res = call_service(&mut app, req).await;
517+
let res = call_service(&app, req).await;
514518
assert!(res.status().is_client_error());
515519
})
516520
});
@@ -519,7 +523,7 @@ mod tests {
519523
}
520524

521525
/// Ensures transaction name can be overridden in handler scope.
522-
#[actix_rt::test]
526+
#[actix_web::test]
523527
async fn test_override_transaction_name() {
524528
let events = sentry::test::with_captured_events(|| {
525529
block_on(async {
@@ -530,15 +534,15 @@ mod tests {
530534
Err(io::Error::new(io::ErrorKind::Other, "Test Error").into())
531535
}
532536

533-
let mut app = init_service(
537+
let app = init_service(
534538
App::new()
535539
.wrap(Sentry::builder().with_hub(Hub::current()).finish())
536540
.service(original_transaction),
537541
)
538542
.await;
539543

540544
let req = TestRequest::get().uri("/test").to_request();
541-
let res = call_service(&mut app, req).await;
545+
let res = call_service(&app, req).await;
542546
assert!(res.status().is_server_error());
543547
})
544548
});
@@ -554,7 +558,7 @@ mod tests {
554558
assert_eq!(request.method, Some("GET".into()));
555559
}
556560

557-
#[actix_rt::test]
561+
#[actix_web::test]
558562
async fn test_track_session() {
559563
let envelopes = sentry::test::with_captured_envelopes_options(
560564
|| {
@@ -566,11 +570,11 @@ mod tests {
566570

567571
let middleware = Sentry::builder().with_hub(Hub::current()).finish();
568572

569-
let mut app = init_service(App::new().wrap(middleware).service(hello)).await;
573+
let app = init_service(App::new().wrap(middleware).service(hello)).await;
570574

571575
for _ in 0..5 {
572576
let req = TestRequest::get().uri("/").to_request();
573-
call_service(&mut app, req).await;
577+
call_service(&app, req).await;
574578
}
575579
})
576580
},

sentry-core/src/session.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ impl Session {
4343
.and_then(|user| {
4444
user.id
4545
.as_ref()
46-
.or_else(|| user.email.as_ref())
47-
.or_else(|| user.username.as_ref())
46+
.or(user.email.as_ref())
47+
.or(user.username.as_ref())
4848
})
4949
.cloned();
5050
Some(Self {

sentry-tower/src/lib.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,25 @@
7070
//! # mod hello_world {
7171
//! # include!("helloworld.rs");
7272
//! # }
73+
//! use hello_world::{greeter_server::*, *};
7374
//! use sentry_tower::NewSentryLayer;
74-
//! use hello_world::{*, greeter_server::*};
7575
//!
7676
//! struct GreeterService;
7777
//!
7878
//! #[tonic::async_trait]
7979
//! impl Greeter for GreeterService {
80-
//! async fn say_hello(&self, req: Request<HelloRequest>) -> Result<Response<HelloReply>, Status> {
80+
//! async fn say_hello(
81+
//! &self,
82+
//! req: Request<HelloRequest>,
83+
//! ) -> Result<Response<HelloReply>, Status> {
8184
//! let HelloRequest { name } = req.into_inner();
8285
//! if name == "world" {
8386
//! capture_anyhow(&anyhow!("Trying to greet a planet"));
8487
//! return Err(Status::invalid_argument("Cannot greet a planet"));
8588
//! }
86-
//! Ok(Response::new(HelloReply { message: format!("Hello {}", name) }))
89+
//! Ok(Response::new(HelloReply {
90+
//! message: format!("Hello {}", name),
91+
//! }))
8792
//! }
8893
//! }
8994
//!

0 commit comments

Comments
 (0)