Skip to content

Commit 3cdf49e

Browse files
authored
Improve client tracing spans (#2044)
* Emit spans for implementers of map request middleware traits * Instrument dispatch with its own span * Fix trace span hierarchy * Partially flatten the middleware span hierarchy * Make `MapRequest::name` required * Add sub-spans to the `load_response` span
1 parent 577c90b commit 3cdf49e

File tree

17 files changed

+151
-75
lines changed

17 files changed

+151
-75
lines changed

CHANGELOG.next.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,3 +677,15 @@ The Unit type for a Union member is no longer rendered. The serializers and pars
677677
references = ["smithy-rs#1989"]
678678
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "all" }
679679
author = "ysaito1001"
680+
681+
[[aws-sdk-rust]]
682+
message = "Fixed and improved the request `tracing` span hierarchy to improve log messages, profiling, and debuggability."
683+
references = ["smithy-rs#2044", "smithy-rs#371"]
684+
meta = { "breaking" = false, "tada" = true, "bug" = false }
685+
author = "jdisanti"
686+
687+
[[smithy-rs]]
688+
message = "Fixed and improved the request `tracing` span hierarchy to improve log messages, profiling, and debuggability."
689+
references = ["smithy-rs#2044", "smithy-rs#371"]
690+
meta = { "breaking" = false, "tada" = true, "bug" = false, "target" = "client"}
691+
author = "jdisanti"

aws/rust-runtime/aws-config/src/imds/client/token.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ impl AsyncMapRequest for TokenMiddleware {
160160
type Error = ImdsError;
161161
type Future = Pin<Box<dyn Future<Output = Result<Request, Self::Error>> + Send + 'static>>;
162162

163+
fn name(&self) -> &'static str {
164+
"attach_imds_token"
165+
}
166+
163167
fn apply(&self, request: Request) -> Self::Future {
164168
let this = self.clone();
165169
Box::pin(async move { this.add_token(request).await })

aws/rust-runtime/aws-config/src/meta/credentials/lazy_caching.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ impl ProvideCredentials for LazyCachingCredentialsProvider {
8484
// There may be other threads also loading simultaneously, but this is OK
8585
// since the futures are not eagerly executed, and the cache will only run one
8686
// of them.
87-
let span = trace_span!("lazy_load_credentials");
8887
let future = Timeout::new(loader.provide_credentials(), timeout_future);
8988
cache
9089
.get_or_load(|| {
90+
let span = trace_span!("lazy_load_credentials");
9191
async move {
9292
let credentials = future.await.map_err(|_err| {
9393
CredentialsError::provider_timed_out(load_timeout)

aws/rust-runtime/aws-endpoint/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ impl From<AwsAuthStageErrorKind> for AwsAuthStageError {
133133
impl MapRequest for AwsAuthStage {
134134
type Error = AwsAuthStageError;
135135

136+
fn name(&self) -> &'static str {
137+
"resolve_endpoint"
138+
}
139+
136140
fn apply(&self, request: Request) -> Result<Request, Self::Error> {
137141
request.augment(|http_req, props| {
138142
let endpoint = props

aws/rust-runtime/aws-http/src/auth.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ impl AsyncMapRequest for CredentialsStage {
101101
type Error = CredentialsStageError;
102102
type Future = Pin<Box<dyn Future<Output = Result<Request, Self::Error>> + Send + 'static>>;
103103

104+
fn name(&self) -> &'static str {
105+
"retrieve_credentials"
106+
}
107+
104108
fn apply(&self, request: Request) -> BoxFuture<Result<Request, Self::Error>> {
105109
Box::pin(Self::load_creds(request))
106110
}

aws/rust-runtime/aws-http/src/recursion_detection.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ impl RecursionDetectionStage {
3333
impl MapRequest for RecursionDetectionStage {
3434
type Error = std::convert::Infallible;
3535

36+
fn name(&self) -> &'static str {
37+
"recursion_detection"
38+
}
39+
3640
fn apply(&self, request: Request) -> Result<Request, Self::Error> {
3741
request.augment(|mut req, _conf| {
3842
augument_request(&mut req, &self.env);

aws/rust-runtime/aws-http/src/user_agent.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,10 @@ lazy_static::lazy_static! {
582582
impl MapRequest for UserAgentStage {
583583
type Error = UserAgentStageError;
584584

585+
fn name(&self) -> &'static str {
586+
"generate_user_agent"
587+
}
588+
585589
fn apply(&self, request: Request) -> Result<Request, Self::Error> {
586590
request.augment(|mut req, conf| {
587591
let ua = conf

aws/rust-runtime/aws-sig-auth/src/middleware.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ fn signing_config(
155155
impl MapRequest for SigV4SigningStage {
156156
type Error = SigningStageError;
157157

158+
fn name(&self) -> &'static str {
159+
"sigv4_sign_request"
160+
}
161+
158162
fn apply(&self, req: Request) -> Result<Request, Self::Error> {
159163
req.augment(|mut req, config| {
160164
let operation_config = config

aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsFluentClientDecorator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ private fun renderCustomizableOperationSendMethod(
323323
/// Sends this operation's request
324324
pub async fn send<T, E>(self) -> Result<T, SdkError<E>>
325325
where
326-
E: std::error::Error + 'static,
326+
E: std::error::Error + Send + Sync + 'static,
327327
O: #{ParseHttpResponse}<Output = Result<T, E>> + Send + Sync + Clone + 'static,
328328
Retry: #{ClassifyRetry}<#{SdkSuccess}<T>, SdkError<E>> + Send + Sync + Clone,
329329
{

codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class CustomizableOperationGenerator(
160160
/// Sends this operation's request
161161
pub async fn send<T, E>(self) -> Result<T, SdkError<E>>
162162
where
163-
E: std::error::Error + 'static,
163+
E: std::error::Error + Send + Sync + 'static,
164164
O: #{ParseHttpResponse}<Output = Result<T, E>> + Send + Sync + Clone + 'static,
165165
Retry: Send + Sync + Clone,
166166
<R as #{NewRequestPolicy}>::Policy: #{SmithyRetryPolicy}<O, T, E, Retry> + Clone,

0 commit comments

Comments
 (0)