Skip to content

Commit 899e4cb

Browse files
committed
Add basic debug log statements; Remove lazy string evaluation
1 parent b53df15 commit 899e4cb

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

codegen/core/src/main/java/software/amazon/smithy/python/codegen/ClientGenerator.java

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ async def _handle_execution(
229229
event_response_deserializer: DeserializeableShape | None = None,
230230
${/hasEventStream}
231231
) -> Output:
232-
logger.debug(f"Making request for operation {operation_name} with parameters: {input}")
232+
logger.debug('Making request for operation "%s" with parameters: %s', operation_name, input)
233233
context: InterceptorContext[Input, None, None, None] = InterceptorContext(
234234
request=input,
235235
response=None,
@@ -326,17 +326,26 @@ async def _handle_execution(
326326
)
327327
except SmithyRetryException:
328328
raise context_with_response.response
329+
logger.debug(
330+
"Retry needed. Attempting request #%s in %s seconds.",
331+
retry_token.retry_count + 1,
332+
retry_token.retry_delay
333+
)
329334
await sleep(retry_token.retry_delay)
330335
current_body = context_with_transport_request.transport_request.body
331336
if (seek := getattr(current_body, "seek", None)) is not None:
332337
await seek(0)
333338
else:
334339
# Step 8: Invoke record_success
340+
logger.debug(
341+
"Attempt %s succeeded. Not retrying request.",
342+
retry_token.retry_count + 1
343+
)
335344
retry_strategy.record_success(token=retry_token)
336345
break
337346
except Exception as e:
338347
if context.response is not None:
339-
logger.exception(f"Exception occurred while handling: {context.response}")
348+
logger.exception("Exception occurred while handling: %s", context.response)
340349
pass
341350
context._response = e
342351
@@ -443,10 +452,12 @@ async def _handle_attempt(
443452
raise $1T(
444453
"No endpoint_uri found on the operation config."
445454
)
446-
455+
endpoint_resolver_parameters = StaticEndpointParams(uri=config.endpoint_uri)
456+
logger.debug("Calling endpoint resolver with parameters: %s", endpoint_resolver_parameters)
447457
endpoint = await config.endpoint_resolver.resolve_endpoint(
448-
StaticEndpointParams(uri=config.endpoint_uri)
458+
endpoint_resolver_parameters
449459
)
460+
logger.debug("Endpoint resolver result: %s", endpoint)
450461
if not endpoint.uri.path:
451462
path = ""
452463
elif endpoint.uri.path.endswith("/"):
@@ -484,6 +495,11 @@ async def _handle_attempt(
484495
writer.write("""
485496
# Step 7i: sign the request
486497
if auth_option and signer:
498+
logger.debug("HTTP request to sign: %s", context.transport_request)
499+
logger.debug(
500+
"Signer properties: %s",
501+
auth_option.signer_properties
502+
)
487503
context._transport_request = await signer.sign(
488504
http_request=context.transport_request,
489505
identity=identity,
@@ -518,10 +534,13 @@ async def _handle_attempt(
518534
context_with_response = cast(
519535
InterceptorContext[Input, None, $1T, $2T], context
520536
)
537+
logger.debug("HTTP request config: %s", request_config)
538+
logger.debug("Sending HTTP request: %s", context_with_response.transport_request)
521539
context_with_response._transport_response = await config.http_client.send(
522540
request=context_with_response.transport_request,
523541
request_config=request_config,
524542
)
543+
logger.debug("Received HTTP response: %s", context_with_response.transport_response)
525544
526545
""", transportRequest, transportResponse);
527546
}
@@ -556,7 +575,7 @@ async def _handle_attempt(
556575
interceptor.read_after_deserialization(context_with_output)
557576
except Exception as e:
558577
if context.response is not None:
559-
logger.exception(f"Exception occurred while handling: {context.response}")
578+
logger.exception("Exception occurred while handling: %s", context.response)
560579
pass
561580
context._response = e
562581
@@ -582,7 +601,7 @@ async def _finalize_attempt(
582601
)
583602
except Exception as e:
584603
if context.response is not None:
585-
logger.exception(f"Exception occurred while handling: {context.response}")
604+
logger.exception("Exception occurred while handling: %s", context.response)
586605
pass
587606
context._response = e
588607
@@ -592,7 +611,7 @@ async def _finalize_attempt(
592611
interceptor.read_after_attempt(context)
593612
except Exception as e:
594613
if context.response is not None:
595-
logger.exception(f"Exception occurred while handling: {context.response}")
614+
logger.exception("Exception occurred while handling: %s", context.response)
596615
pass
597616
context._response = e
598617
@@ -613,11 +632,11 @@ async def _finalize_execution(
613632
pass
614633
except Exception as e:
615634
# log and ignore exceptions
616-
logger.exception(f"Exception occurred while dispatching trace events: {e}")
635+
logger.exception("Exception occurred while dispatching trace events: %s", e)
617636
pass
618637
except Exception as e:
619638
if context.response is not None:
620-
logger.exception(f"Exception occurred while handling: {context.response}")
639+
logger.exception("Exception occurred while handling: %s", context.response)
621640
pass
622641
context._response = e
623642
@@ -627,7 +646,7 @@ async def _finalize_execution(
627646
interceptor.read_after_execution(context)
628647
except Exception as e:
629648
if context.response is not None:
630-
logger.exception(f"Exception occurred while handling: {context.response}")
649+
logger.exception("Exception occurred while handling: %s", context.response)
631650
pass
632651
context._response = e
633652

codegen/core/src/main/java/software/amazon/smithy/python/codegen/generators/StructureGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ def _consumer(schema: Schema, de: ShapeDeserializer) -> None:
412412
match schema.expect_member_index():
413413
${C|}
414414
case _:
415-
logger.debug(f"Unexpected member schema: {schema}")
415+
logger.debug("Unexpected member schema: %s", schema)
416416
417417
deserializer.read_struct($T, consumer=_consumer)
418418
return kwargs

codegen/core/src/main/java/software/amazon/smithy/python/codegen/generators/UnionGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def _consumer(self, schema: Schema, de: ShapeDeserializer) -> None:
162162
match schema.expect_member_index():
163163
${4C|}
164164
case _:
165-
logger.debug(f"Unexpected member schema: {schema}")
165+
logger.debug("Unexpected member schema: %s", schema)
166166
167167
def _set_result(self, value: $2T) -> None:
168168
if self._result is not None:

0 commit comments

Comments
 (0)