diff --git a/rust-runtime/smithy-http-tower/src/dispatch.rs b/rust-runtime/smithy-http-tower/src/dispatch.rs index c9f82f5754..481151eaab 100644 --- a/rust-runtime/smithy-http-tower/src/dispatch.rs +++ b/rust-runtime/smithy-http-tower/src/dispatch.rs @@ -4,19 +4,13 @@ */ use crate::SendOperationError; -use pin_project::pin_project; use smithy_http::body::SdkBody; use smithy_http::operation; use std::future::Future; use std::pin::Pin; use std::task::{Context, Poll}; use tower::{BoxError, Layer, Service}; - -#[pin_project] -pub struct DispatchFuture { - #[pin] - f: F, -} +use tracing::trace; /// Connects Operation driven middleware to an HTTP implementation. /// @@ -27,29 +21,17 @@ pub struct DispatchService { inner: S, } -impl Future for DispatchFuture -where - F: Future>, - E: Into, -{ - type Output = Result; - - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - let this = self.project(); - this.f - .poll(cx) - .map_err(|e| SendOperationError::RequestDispatchError(e.into())) - } -} +type BoxedResultFuture = Pin> + Send>>; impl Service for DispatchService where - S: Service>, + S: Service> + Clone + Send + 'static, S::Error: Into, + S::Future: Send + 'static, { type Response = S::Response; type Error = SendOperationError; - type Future = DispatchFuture; + type Future = BoxedResultFuture; fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { self.inner @@ -59,9 +41,15 @@ where fn call(&mut self, req: operation::Request) -> Self::Future { let (req, _property_bag) = req.into_parts(); - DispatchFuture { - f: self.inner.call(req), - } + let mut inner = self.inner.clone(); + let future = async move { + trace!(request = ?req); + inner + .call(req) + .await + .map_err(|e| SendOperationError::RequestDispatchError(e.into())) + }; + Box::pin(future) } } diff --git a/rust-runtime/smithy-http/Cargo.toml b/rust-runtime/smithy-http/Cargo.toml index 585f578275..f9e03af6e3 100644 --- a/rust-runtime/smithy-http/Cargo.toml +++ b/rust-runtime/smithy-http/Cargo.toml @@ -13,6 +13,7 @@ http = "0.2.3" thiserror = "1" pin-project = "1" percent-encoding = "2.1.0" +tracing = "0.1.24" # We are using hyper for our streaming body implementation, but this is an internal detail. hyper = "0.14.5" diff --git a/rust-runtime/smithy-http/src/middleware.rs b/rust-runtime/smithy-http/src/middleware.rs index 91eb330bdc..26f0246540 100644 --- a/rust-runtime/smithy-http/src/middleware.rs +++ b/rust-runtime/smithy-http/src/middleware.rs @@ -17,6 +17,7 @@ use bytes::{Buf, Bytes}; use http::Response; use http_body::Body; use std::error::Error; +use tracing::trace; type BoxError = Box; @@ -78,8 +79,10 @@ where if let Some(parsed_response) = handler.parse_unloaded(&mut response) { return sdk_result(parsed_response, response); } - let (parts, body) = response.into_parts(); + trace!(response = ?response); + + let (parts, body) = response.into_parts(); let body = match read_body(body).await { Ok(body) => body, Err(err) => {