Unverified Commit d5bcd4f3 authored by John DiSanti's avatar John DiSanti Committed by GitHub
Browse files

Improve credentials tracing (#2062)

* Add `info` event for credentials cache miss
* Remove duplicate credential provider spans
* Touch up some credentials events/spans
parent bf6cf750
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -701,3 +701,9 @@ message = "Add more `tracing` events to signing and event streams"
references = ["smithy-rs#2057", "smithy-rs#371"]
meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client"}
author = "jdisanti"

[[aws-sdk-rust]]
message = "Log an `info` on credentials cache miss and adjust level of some credential `tracing` spans/events."
references = ["smithy-rs#2062"]
meta = { "breaking" = false, "tada" = false, "bug" = false }
author = "jdisanti"
+1 −1
Original line number Diff line number Diff line
@@ -152,7 +152,7 @@ impl ImdsCredentialsProvider {
            Err(ImdsError::ErrorResponse(context))
                if context.response().status().as_u16() == 404 =>
            {
                tracing::info!(
                tracing::warn!(
                    "received 404 from IMDS when loading profile information. \
                    Hint: This instance may not have an IAM role associated."
                );
+12 −6
Original line number Diff line number Diff line
@@ -6,11 +6,11 @@
//! Lazy, caching, credentials provider implementation

use std::sync::Arc;
use std::time::Duration;
use std::time::{Duration, Instant};

use aws_smithy_async::future::timeout::Timeout;
use aws_smithy_async::rt::sleep::AsyncSleep;
use tracing::{trace_span, Instrument};
use tracing::{debug, info, info_span, Instrument};

use aws_types::credentials::{future, CredentialsError, ProvideCredentials};
use aws_types::os_shim_internal::TimeSource;
@@ -77,7 +77,7 @@ impl ProvideCredentials for LazyCachingCredentialsProvider {
        future::ProvideCredentials::new(async move {
            // Attempt to get cached credentials, or clear the cache if they're expired
            if let Some(credentials) = cache.yield_or_clear_if_expired(now).await {
                tracing::debug!("loaded credentials from cache");
                debug!("loaded credentials from cache");
                Ok(credentials)
            } else {
                // If we didn't get credentials from the cache, then we need to try and load.
@@ -85,9 +85,10 @@ impl ProvideCredentials for LazyCachingCredentialsProvider {
                // since the futures are not eagerly executed, and the cache will only run one
                // of them.
                let future = Timeout::new(loader.provide_credentials(), timeout_future);
                cache
                let start_time = Instant::now();
                let result = cache
                    .get_or_load(|| {
                        let span = trace_span!("lazy_load_credentials");
                        let span = info_span!("lazy_load_credentials");
                        async move {
                            let credentials = future.await.map_err(|_err| {
                                CredentialsError::provider_timed_out(load_timeout)
@@ -102,7 +103,12 @@ impl ProvideCredentials for LazyCachingCredentialsProvider {
                        // is opened if the cache decides not to execute it.
                        .instrument(span)
                    })
                    .await
                    .await;
                info!(
                    "credentials cache miss occurred; retrieved new AWS credentials (took {:?})",
                    start_time.elapsed()
                );
                result
            }
        })
    }
+1 −4
Original line number Diff line number Diff line
@@ -46,10 +46,7 @@ impl ProvideCredentials for ProfileFileCredentialsProvider {
    where
        Self: 'a,
    {
        future::ProvideCredentials::new(self.load_credentials().instrument(tracing::debug_span!(
            "load_credentials",
            provider = %"Profile"
        )))
        future::ProvideCredentials::new(self.load_credentials())
    }
}

+1 −3
Original line number Diff line number Diff line
@@ -235,8 +235,6 @@ impl AssumeRoleProviderBuilder {

impl Inner {
    async fn credentials(&self) -> credentials::Result {
        tracing::info!("assuming role");

        tracing::debug!("retrieving assumed credentials");
        let op = self
            .op
@@ -281,7 +279,7 @@ impl ProvideCredentials for Inner {
    {
        future::ProvideCredentials::new(
            self.credentials()
                .instrument(tracing::info_span!("assume_role")),
                .instrument(tracing::debug_span!("assume_role")),
        )
    }
}
Loading