@@ -47,6 +47,7 @@ use tokio::{
47
47
use tracing:: { field:: Empty , log, Instrument } ;
48
48
use wasmtime_wasi_http:: {
49
49
body:: { HyperIncomingBody as Body , HyperOutgoingBody } ,
50
+ types:: HostFutureIncomingResponse ,
50
51
WasiHttpView ,
51
52
} ;
52
53
@@ -569,7 +570,6 @@ impl HttpRuntimeData {
569
570
) -> wasmtime:: Result <
570
571
wasmtime:: component:: Resource < wasmtime_wasi_http:: types:: HostFutureIncomingResponse > ,
571
572
> {
572
- use wasmtime_wasi_http:: types:: HostFutureIncomingResponse ;
573
573
use wasmtime_wasi_http:: types:: IncomingResponseInternal ;
574
574
575
575
let this = data. as_ref ( ) ;
@@ -706,7 +706,44 @@ impl OutboundWasiHttpHandler for HttpRuntimeData {
706
706
return Self :: chain_request ( data, request, component_id) ;
707
707
}
708
708
709
- wasmtime_wasi_http:: types:: default_send_request ( data, request)
709
+ let current_span = tracing:: Span :: current ( ) ;
710
+ let uri = request. request . uri ( ) ;
711
+ if let Some ( authority) = uri. authority ( ) {
712
+ current_span. record ( "server.address" , authority. host ( ) ) ;
713
+ if let Some ( port) = authority. port ( ) {
714
+ current_span. record ( "server.port" , port. as_u16 ( ) ) ;
715
+ }
716
+ }
717
+
718
+ // TODO: This is a temporary workaround to make sure that outbound task is instrumented.
719
+ // Once Wasmtime gives us the ability to do the spawn ourselves we can just call .instrument
720
+ // and won't have to do this workaround.
721
+ let response_handle = wasmtime_wasi_http:: types:: default_send_request ( data, request) ?;
722
+ let response = data. table ( ) . get_mut ( & response_handle) ?;
723
+ * response = match std:: mem:: replace ( response, HostFutureIncomingResponse :: Consumed ) {
724
+ HostFutureIncomingResponse :: Pending ( handle) => {
725
+ HostFutureIncomingResponse :: Pending ( wasmtime_wasi:: preview2:: spawn (
726
+ async move {
727
+ let res: Result <
728
+ Result <
729
+ wasmtime_wasi_http:: types:: IncomingResponseInternal ,
730
+ wasmtime_wasi_http:: bindings:: http:: types:: ErrorCode ,
731
+ > ,
732
+ anyhow:: Error ,
733
+ > = handle. await ;
734
+ if let Ok ( Ok ( res) ) = & res {
735
+ tracing:: Span :: current ( )
736
+ . record ( "http.response.status_code" , res. resp . status ( ) . as_u16 ( ) ) ;
737
+ }
738
+ res
739
+ }
740
+ . in_current_span ( ) ,
741
+ ) )
742
+ }
743
+ other => other,
744
+ } ;
745
+
746
+ Ok ( response_handle)
710
747
}
711
748
}
712
749
0 commit comments