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//!
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
176182where
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 >
202207where
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 } ,
0 commit comments