File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
examples/http-tower-trace Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ [package ]
2+ name = " http-tower-trace"
3+ version = " 0.1.0"
4+ edition = " 2021"
5+
6+
7+ # Use cargo-edit(https://github.com/killercup/cargo-edit#installation)
8+ # to manage dependencies.
9+ # Running `cargo add DEPENDENCY_NAME` will
10+ # add the latest version of a dependency to the list,
11+ # and it will keep the alphabetic ordering for you.
12+
13+ [dependencies ]
14+ lambda_http = { path = " ../../lambda-http" }
15+ lambda_runtime = " 0.5.1"
16+ tokio = { version = " 1" , features = [" macros" ] }
17+ tower-http = { version = " 0.3.4" , features = [" trace" ] }
18+ tracing = { version = " 0.1" , features = [" log" ] }
19+ tracing-subscriber = { version = " 0.3" , default-features = false , features = [" fmt" ] }
Original file line number Diff line number Diff line change 1+ use lambda_http:: { run, tower:: ServiceBuilder , Error } ;
2+ use lambda_http:: { Request , Response } ;
3+ use tower_http:: trace:: { DefaultOnRequest , DefaultOnResponse , TraceLayer } ;
4+ use tracing:: Level ;
5+
6+ async fn handler ( _req : Request ) -> Result < Response < String > , Error > {
7+ Ok ( Response :: new ( "Success" . into ( ) ) )
8+ }
9+
10+ #[ tokio:: main]
11+ async fn main ( ) -> Result < ( ) , Error > {
12+ tracing_subscriber:: fmt ( ) . without_time ( ) . init ( ) ;
13+
14+ let layer = TraceLayer :: new_for_http ( )
15+ . on_request ( DefaultOnRequest :: new ( ) . level ( Level :: INFO ) )
16+ . on_response ( DefaultOnResponse :: new ( ) . level ( Level :: INFO ) ) ;
17+
18+ let service = ServiceBuilder :: new ( ) . layer ( layer) . service_fn ( handler) ;
19+
20+ run ( service) . await ?;
21+ Ok ( ( ) )
22+ }
You can’t perform that action at this time.
0 commit comments