1- use crate :: { DefaultRootSpanBuilder , RequestId , RootSpan , RootSpanBuilder } ;
2- use actix_web:: body:: { BodySize , MessageBody } ;
3- use actix_web:: dev:: { Service , ServiceRequest , ServiceResponse , Transform } ;
4- use actix_web:: http:: StatusCode ;
5- use actix_web:: web:: Bytes ;
6- use actix_web:: { Error , HttpMessage , ResponseError } ;
7- use std:: future:: { ready, Future , Ready } ;
8- use std:: pin:: Pin ;
9- use std:: task:: { Context , Poll } ;
1+ use std:: {
2+ future:: { ready, Future , Ready } ,
3+ pin:: Pin ,
4+ task:: { Context , Poll } ,
5+ } ;
6+
7+ use actix_web:: {
8+ body:: { BodySize , MessageBody } ,
9+ dev:: { Service , ServiceRequest , ServiceResponse , Transform } ,
10+ web:: Bytes ,
11+ Error , HttpMessage ,
12+ } ;
1013use tracing:: Span ;
1114
15+ use crate :: { DefaultRootSpanBuilder , RequestId , RootSpan , RootSpanBuilder } ;
16+
1217/// `TracingLogger` is a middleware to capture structured diagnostic when processing an HTTP request.
1318/// Check the crate-level documentation for an in-depth introduction.
1419///
1520/// `TracingLogger` is designed as a drop-in replacement of [`actix-web`]'s [`Logger`].
1621///
1722/// # Usage
1823///
19- /// Register `TracingLogger` as a middleware for your application using `.wrap` on `App`.
24+ /// Register `TracingLogger` as a middleware for your application using `.wrap` on `App`.
2025/// In this example we add a [`tracing::Subscriber`] to output structured logs to the console.
2126///
2227/// ```rust
@@ -235,6 +240,7 @@ where
235240 }
236241}
237242
243+ #[ cfg( feature = "emit_event_on_error" ) ]
238244fn emit_event_on_error < B : ' static > ( outcome : & Result < ServiceResponse < B > , actix_web:: Error > ) {
239245 match outcome {
240246 Ok ( response) => {
@@ -250,7 +256,11 @@ fn emit_event_on_error<B: 'static>(outcome: &Result<ServiceResponse<B>, actix_we
250256 }
251257}
252258
253- fn emit_error_event ( response_error : & dyn ResponseError , status_code : StatusCode ) {
259+ #[ cfg( feature = "emit_event_on_error" ) ]
260+ fn emit_error_event (
261+ response_error : & dyn actix_web:: ResponseError ,
262+ status_code : actix_web:: http:: StatusCode ,
263+ ) {
254264 let error_msg_prefix = "Error encountered while processing the incoming HTTP request" ;
255265 if status_code. is_client_error ( ) {
256266 tracing:: warn!( "{}: {:?}" , error_msg_prefix, response_error) ;
0 commit comments