-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add basic logging #396
base: develop
Are you sure you want to change the base?
Add basic logging #396
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -229,7 +229,7 @@ async def _handle_execution( | |||||
event_response_deserializer: DeserializeableShape | None = None, | ||||||
${/hasEventStream} | ||||||
) -> Output: | ||||||
logger.debug(f"Making request for operation {operation_name} with parameters: {input}") | ||||||
logger.debug('Making request for operation "%s" with parameters: %s', operation_name, input) | ||||||
context: InterceptorContext[Input, None, None, None] = InterceptorContext( | ||||||
request=input, | ||||||
response=None, | ||||||
|
@@ -326,17 +326,26 @@ async def _handle_execution( | |||||
) | ||||||
except SmithyRetryException: | ||||||
raise context_with_response.response | ||||||
logger.debug( | ||||||
"Retry needed. Attempting request #%s in %s seconds.", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does retry_count start at 0 or 1 on our first call? i.e. is the first log message request 1 or 2? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Here are our docs on retry_count: int
"""Retry count is the total number of attempts minus the initial attempt.""" Here is an example of the first log message that gets printed when testing this:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok if the first log starts at 2, then this probably fine. I would say let's constrain the formatting a little though for seconds. Something like |
||||||
retry_token.retry_count + 1, | ||||||
retry_token.retry_delay | ||||||
) | ||||||
await sleep(retry_token.retry_delay) | ||||||
current_body = context_with_transport_request.transport_request.body | ||||||
if (seek := getattr(current_body, "seek", None)) is not None: | ||||||
await seek(0) | ||||||
else: | ||||||
# Step 8: Invoke record_success | ||||||
logger.debug( | ||||||
"Attempt %s succeeded. Not retrying request.", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably quantify what attempt succeeded, I don't know if there's enough context here to be immediately clear. I'm also not sure if we need to log this at all as it may produce more noise than value. Generally we want to record exceptional cases rather than noting everything that happened.
Suggested change
|
||||||
retry_token.retry_count + 1 | ||||||
) | ||||||
retry_strategy.record_success(token=retry_token) | ||||||
break | ||||||
except Exception as e: | ||||||
if context.response is not None: | ||||||
logger.exception(f"Exception occurred while handling: {context.response}") | ||||||
logger.exception("Exception occurred while handling: %s", context.response) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What gets logged with this? Do we have an example response payload? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, here is an example response:
|
||||||
pass | ||||||
context._response = e | ||||||
|
||||||
|
@@ -443,10 +452,12 @@ async def _handle_attempt( | |||||
raise $1T( | ||||||
"No endpoint_uri found on the operation config." | ||||||
) | ||||||
|
||||||
endpoint_resolver_parameters = StaticEndpointParams(uri=config.endpoint_uri) | ||||||
logger.debug("Calling endpoint resolver with parameters: %s", endpoint_resolver_parameters) | ||||||
Comment on lines
+455
to
+456
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may need to rationalize this against Alex's other Endpoint work. I hope we don't need to add different log statements for each endpoint resolver. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah - I'm planning on doing a small refactor of the endpoint generator so that this code wouldn't be duplicated between them. (IE - the only thing that should be different between different endpoint generators is the parameter classes and how they are constructed) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See refactoring: 2a4e6f0 This should play nicely with the logging above. |
||||||
endpoint = await config.endpoint_resolver.resolve_endpoint( | ||||||
StaticEndpointParams(uri=config.endpoint_uri) | ||||||
endpoint_resolver_parameters | ||||||
) | ||||||
logger.debug("Endpoint resolver result: %s", endpoint) | ||||||
if not endpoint.uri.path: | ||||||
path = "" | ||||||
elif endpoint.uri.path.endswith("/"): | ||||||
|
@@ -484,6 +495,11 @@ async def _handle_attempt( | |||||
writer.write(""" | ||||||
# Step 7i: sign the request | ||||||
if auth_option and signer: | ||||||
logger.debug("HTTP request to sign: %s", context.transport_request) | ||||||
logger.debug( | ||||||
"Signer properties: %s", | ||||||
auth_option.signer_properties | ||||||
) | ||||||
Comment on lines
+498
to
+502
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can build this to check but if you have a quick answer, what does the output of these look like? I haven't checked our repr's for them. |
||||||
context._transport_request = await signer.sign( | ||||||
http_request=context.transport_request, | ||||||
identity=identity, | ||||||
|
@@ -518,10 +534,13 @@ async def _handle_attempt( | |||||
context_with_response = cast( | ||||||
InterceptorContext[Input, None, $1T, $2T], context | ||||||
) | ||||||
logger.debug("HTTP request config: %s", request_config) | ||||||
logger.debug("Sending HTTP request: %s", context_with_response.transport_request) | ||||||
Comment on lines
+537
to
+538
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Example:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I may need to tweak our reprs for fields and URIs so they're more readable. What we have now isn't great for logging. |
||||||
context_with_response._transport_response = await config.http_client.send( | ||||||
request=context_with_response.transport_request, | ||||||
request_config=request_config, | ||||||
) | ||||||
logger.debug("Received HTTP response: %s", context_with_response.transport_response) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Example:
|
||||||
|
||||||
""", transportRequest, transportResponse); | ||||||
} | ||||||
|
@@ -556,7 +575,7 @@ async def _handle_attempt( | |||||
interceptor.read_after_deserialization(context_with_output) | ||||||
except Exception as e: | ||||||
if context.response is not None: | ||||||
logger.exception(f"Exception occurred while handling: {context.response}") | ||||||
logger.exception("Exception occurred while handling: %s", context.response) | ||||||
pass | ||||||
context._response = e | ||||||
|
||||||
|
@@ -582,7 +601,7 @@ async def _finalize_attempt( | |||||
) | ||||||
except Exception as e: | ||||||
if context.response is not None: | ||||||
logger.exception(f"Exception occurred while handling: {context.response}") | ||||||
logger.exception("Exception occurred while handling: %s", context.response) | ||||||
pass | ||||||
context._response = e | ||||||
|
||||||
|
@@ -592,7 +611,7 @@ async def _finalize_attempt( | |||||
interceptor.read_after_attempt(context) | ||||||
except Exception as e: | ||||||
if context.response is not None: | ||||||
logger.exception(f"Exception occurred while handling: {context.response}") | ||||||
logger.exception("Exception occurred while handling: %s", context.response) | ||||||
pass | ||||||
context._response = e | ||||||
|
||||||
|
@@ -613,11 +632,11 @@ async def _finalize_execution( | |||||
pass | ||||||
except Exception as e: | ||||||
# log and ignore exceptions | ||||||
logger.exception(f"Exception occurred while dispatching trace events: {e}") | ||||||
logger.exception("Exception occurred while dispatching trace events: %s", e) | ||||||
pass | ||||||
except Exception as e: | ||||||
if context.response is not None: | ||||||
logger.exception(f"Exception occurred while handling: {context.response}") | ||||||
logger.exception("Exception occurred while handling: %s", context.response) | ||||||
pass | ||||||
context._response = e | ||||||
|
||||||
|
@@ -627,7 +646,7 @@ async def _finalize_execution( | |||||
interceptor.read_after_execution(context) | ||||||
except Exception as e: | ||||||
if context.response is not None: | ||||||
logger.exception(f"Exception occurred while handling: {context.response}") | ||||||
logger.exception("Exception occurred while handling: %s", context.response) | ||||||
pass | ||||||
context._response = e | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example: