66//! Lazy, caching, credentials provider implementation
77
88use std:: sync:: Arc ;
9- use std:: time:: Duration ;
9+ use std:: time:: { Duration , Instant } ;
1010
1111use aws_smithy_async:: future:: timeout:: Timeout ;
1212use aws_smithy_async:: rt:: sleep:: AsyncSleep ;
13- use tracing:: { trace_span , Instrument } ;
13+ use tracing:: { debug , info , info_span , Instrument } ;
1414
1515use aws_types:: credentials:: { future, CredentialsError , ProvideCredentials } ;
1616use 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 }
0 commit comments