@@ -24,6 +24,7 @@ import aws.smithy.kotlin.runtime.io.Closeable
2424import aws.smithy.kotlin.runtime.io.closeIfCloseable
2525import aws.smithy.kotlin.runtime.io.middleware.Phase
2626import aws.smithy.kotlin.runtime.operation.ExecutionContext
27+ import aws.smithy.kotlin.runtime.telemetry.logging.logger
2728import aws.smithy.kotlin.runtime.time.Clock
2829import aws.smithy.kotlin.runtime.util.PlatformProvider
2930import kotlin.coroutines.coroutineContext
@@ -111,11 +112,13 @@ public class ImdsClient private constructor(builder: Builder) : InstanceMetadata
111112 * ```
112113 */
113114 public override suspend fun get (path : String ): String {
115+ val logger = coroutineContext.logger<ImdsClient >()
114116 val op = SdkHttpOperation .build<Unit , String > {
115117 serializeWith = HttpSerializer .Unit
116118 deserializeWith = object : HttpDeserializer .NonStreaming <String > {
117119 override fun deserialize (context : ExecutionContext , call : HttpCall , payload : ByteArray? ): String {
118120 val response = call.response
121+ logger.trace { call.toTraceString() }
119122 if (response.status.isSuccess()) {
120123 return payload!! .decodeToString()
121124 } else {
@@ -240,3 +243,17 @@ public class EC2MetadataError(public val status: HttpStatusCode, message: String
240243 @Deprecated(" This property is now deprecated and should be fetched from status.value. This declaration will be removed in version 1.6.x." )
241244 public val statusCode: Int = status.value
242245}
246+
247+ /* *
248+ * Formats an executed [HttpCall] into a form suitable for TRACE logging. Example output:
249+ *
250+ * `HTTP GET http://169.254.169.254/latest/meta-data/iam/security-credentials/ --> 200 OK`
251+ */
252+ internal fun HttpCall.toTraceString () = listOf (
253+ " HTTP" ,
254+ request.method,
255+ request.url,
256+ " -->" ,
257+ response.status.value,
258+ response.status.description,
259+ ).joinToString(" " )
0 commit comments