-
Notifications
You must be signed in to change notification settings - Fork 24
Add basic logging #396
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
Changes from all commits
e2096c1
36b28c7
c9ff85c
7d90ac5
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 |
|---|---|---|
|
|
@@ -153,6 +153,7 @@ def _classify_error( | |
| error: Exception, | ||
| context: InterceptorContext[Input, Output, $1T, $2T | None] | ||
| ) -> RetryErrorInfo: | ||
| logger.debug("Classifying error: %s", error) | ||
| """, transportRequest, transportResponse); | ||
| writer.indent(); | ||
|
|
||
|
|
@@ -229,7 +230,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, | ||
|
|
@@ -276,9 +277,11 @@ async def _handle_execution( | |
| context_with_transport_request = cast( | ||
| InterceptorContext[Input, None, $2T, None], context | ||
| ) | ||
| logger.debug("Serializing request for: %s", context_with_transport_request.request) | ||
| context_with_transport_request._transport_request = await serialize( | ||
| context_with_transport_request.request, config | ||
| ) | ||
| logger.debug("Serialization complete. Transport request: %s", context_with_transport_request._transport_request) | ||
|
|
||
| # Step 5: Invoke read_after_serialization | ||
| for interceptor in interceptors: | ||
|
|
@@ -326,6 +329,11 @@ async def _handle_execution( | |
| ) | ||
| except SmithyRetryException: | ||
| raise context_with_response.response | ||
| logger.debug( | ||
| "Retry needed. Attempting request #%s in %.4f seconds.", | ||
| 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: | ||
|
|
@@ -336,7 +344,7 @@ await seek(0) | |
| 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) | ||
|
Contributor
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?
Contributor
Author
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 +451,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
+454
to
+455
Contributor
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.
Contributor
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)
Contributor
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,11 +494,17 @@ 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
+497
to
+501
Contributor
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.
Contributor
Author
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. The
@dataclass(kw_only=True)
class HTTPAuthOption:
"""Auth scheme used for signing and identity resolution."""
# The ID of the scheme to use. This string matches the one returned by
# HttpAuthScheme.scheme_id
scheme_id: str
# Parameters to pass to IdentityResolver.get_identity.
identity_properties: dict[str, Any]
# Parameters to pass to HttpSigner.sign.
signer_properties: dict[str, Any] |
||
| context._transport_request = await signer.sign( | ||
| http_request=context.transport_request, | ||
| identity=identity, | ||
| signing_properties=auth_option.signer_properties, | ||
| ) | ||
| logger.debug("Signed HTTP request: %s", context._transport_request) | ||
| """); | ||
| } | ||
| writer.popState(); | ||
|
|
@@ -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
Contributor
Author
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:
Contributor
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.
Contributor
Author
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. Yea, that seems reasonable. Out of curiosity, why modify the
Seems like
|
||
| 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) | ||
|
Contributor
Author
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); | ||
| } | ||
|
|
@@ -547,16 +566,18 @@ async def _handle_attempt( | |
| InterceptorContext[Input, Output, $1T, $2T], | ||
| context_with_response, | ||
| ) | ||
| logger.debug("Deserializing transport response: %s", context_with_output._transport_response) | ||
| context_with_output._response = await deserialize( | ||
| context_with_output._transport_response, config | ||
| ) | ||
| logger.debug("Deserialization complete. Response: %s", context_with_output._response) | ||
|
|
||
| # Step 7r: Invoke read_after_deserialization | ||
| for interceptor in interceptors: | ||
| 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 +603,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 +613,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 +634,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 +648,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: