Skip to content

Commit d5bcd4f

Browse files
authored
Improve credentials tracing (#2062)
* Add `info` event for credentials cache miss * Remove duplicate credential provider spans * Touch up some credentials events/spans
1 parent bf6cf75 commit d5bcd4f

File tree

6 files changed

+22
-20
lines changed

6 files changed

+22
-20
lines changed

CHANGELOG.next.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,4 +700,10 @@ author = "jdisanti"
700700
message = "Add more `tracing` events to signing and event streams"
701701
references = ["smithy-rs#2057", "smithy-rs#371"]
702702
meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client"}
703-
author = "jdisanti"
703+
author = "jdisanti"
704+
705+
[[aws-sdk-rust]]
706+
message = "Log an `info` on credentials cache miss and adjust level of some credential `tracing` spans/events."
707+
references = ["smithy-rs#2062"]
708+
meta = { "breaking" = false, "tada" = false, "bug" = false }
709+
author = "jdisanti"

aws/rust-runtime/aws-config/src/imds/credentials.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl ImdsCredentialsProvider {
152152
Err(ImdsError::ErrorResponse(context))
153153
if context.response().status().as_u16() == 404 =>
154154
{
155-
tracing::info!(
155+
tracing::warn!(
156156
"received 404 from IMDS when loading profile information. \
157157
Hint: This instance may not have an IAM role associated."
158158
);

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
//! Lazy, caching, credentials provider implementation
77
88
use std::sync::Arc;
9-
use std::time::Duration;
9+
use std::time::{Duration, Instant};
1010

1111
use aws_smithy_async::future::timeout::Timeout;
1212
use aws_smithy_async::rt::sleep::AsyncSleep;
13-
use tracing::{trace_span, Instrument};
13+
use tracing::{debug, info, info_span, Instrument};
1414

1515
use aws_types::credentials::{future, CredentialsError, ProvideCredentials};
1616
use aws_types::os_shim_internal::TimeSource;
@@ -77,17 +77,18 @@ impl ProvideCredentials for LazyCachingCredentialsProvider {
7777
future::ProvideCredentials::new(async move {
7878
// Attempt to get cached credentials, or clear the cache if they're expired
7979
if let Some(credentials) = cache.yield_or_clear_if_expired(now).await {
80-
tracing::debug!("loaded credentials from cache");
80+
debug!("loaded credentials from cache");
8181
Ok(credentials)
8282
} else {
8383
// If we didn't get credentials from the cache, then we need to try and load.
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.
8787
let future = Timeout::new(loader.provide_credentials(), timeout_future);
88-
cache
88+
let start_time = Instant::now();
89+
let result = cache
8990
.get_or_load(|| {
90-
let span = trace_span!("lazy_load_credentials");
91+
let span = info_span!("lazy_load_credentials");
9192
async move {
9293
let credentials = future.await.map_err(|_err| {
9394
CredentialsError::provider_timed_out(load_timeout)
@@ -102,7 +103,12 @@ impl ProvideCredentials for LazyCachingCredentialsProvider {
102103
// is opened if the cache decides not to execute it.
103104
.instrument(span)
104105
})
105-
.await
106+
.await;
107+
info!(
108+
"credentials cache miss occurred; retrieved new AWS credentials (took {:?})",
109+
start_time.elapsed()
110+
);
111+
result
106112
}
107113
})
108114
}

aws/rust-runtime/aws-config/src/profile/credentials.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@ impl ProvideCredentials for ProfileFileCredentialsProvider {
4646
where
4747
Self: 'a,
4848
{
49-
future::ProvideCredentials::new(self.load_credentials().instrument(tracing::debug_span!(
50-
"load_credentials",
51-
provider = %"Profile"
52-
)))
49+
future::ProvideCredentials::new(self.load_credentials())
5350
}
5451
}
5552

aws/rust-runtime/aws-config/src/sts/assume_role.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,6 @@ impl AssumeRoleProviderBuilder {
235235

236236
impl Inner {
237237
async fn credentials(&self) -> credentials::Result {
238-
tracing::info!("assuming role");
239-
240238
tracing::debug!("retrieving assumed credentials");
241239
let op = self
242240
.op
@@ -281,7 +279,7 @@ impl ProvideCredentials for Inner {
281279
{
282280
future::ProvideCredentials::new(
283281
self.credentials()
284-
.instrument(tracing::info_span!("assume_role")),
282+
.instrument(tracing::debug_span!("assume_role")),
285283
)
286284
}
287285
}

aws/rust-runtime/aws-config/src/web_identity_token.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ use aws_types::credentials::{self, future, CredentialsError, ProvideCredentials}
7171
use aws_types::os_shim_internal::{Env, Fs};
7272
use std::borrow::Cow;
7373
use std::path::{Path, PathBuf};
74-
use tracing::Instrument;
7574

7675
const ENV_VAR_TOKEN_FILE: &str = "AWS_WEB_IDENTITY_TOKEN_FILE";
7776
const ENV_VAR_ROLE_ARN: &str = "AWS_ROLE_ARN";
@@ -161,10 +160,6 @@ impl WebIdentityTokenCredentialsProvider {
161160
&conf.role_arn,
162161
&conf.session_name,
163162
)
164-
.instrument(tracing::debug_span!(
165-
"load_credentials",
166-
provider = "WebIdentityToken"
167-
))
168163
.await
169164
}
170165
}

0 commit comments

Comments
 (0)