@@ -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,35 @@ 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
+ // TODO: This is a temporary workaround to make sure that outbound task is instrumented.
710
+ // Once Wasmtime gives us the ability to do the spawn ourselves we can just call .instrument
711
+ // and won't have to do this workaround.
712
+ let response_handle = wasmtime_wasi_http:: types:: default_send_request ( data, request) ?;
713
+ let response = data. table ( ) . get_mut ( & response_handle) ?;
714
+ * response = match std:: mem:: replace ( response, HostFutureIncomingResponse :: Consumed ) {
715
+ HostFutureIncomingResponse :: Pending ( handle) => {
716
+ HostFutureIncomingResponse :: Pending ( wasmtime_wasi:: preview2:: spawn (
717
+ async move {
718
+ let res: std:: prelude:: v1:: Result <
719
+ std:: prelude:: v1:: Result <
720
+ wasmtime_wasi_http:: types:: IncomingResponseInternal ,
721
+ wasmtime_wasi_http:: bindings:: http:: types:: ErrorCode ,
722
+ > ,
723
+ anyhow:: Error ,
724
+ > = handle. await ;
725
+ if let Ok ( Ok ( res) ) = & res {
726
+ tracing:: Span :: current ( )
727
+ . record ( "http.response.status_code" , res. resp . status ( ) . as_u16 ( ) ) ;
728
+ }
729
+ res
730
+ }
731
+ . instrument ( tracing:: Span :: current ( ) ) ,
732
+ ) )
733
+ }
734
+ other => other,
735
+ } ;
736
+
737
+ Ok ( response_handle)
710
738
}
711
739
}
712
740
0 commit comments