Skip to content

Commit

Permalink
share logging
Browse files Browse the repository at this point in the history
  • Loading branch information
richardm-stripe committed Dec 14, 2023
1 parent b2a2945 commit ced75f8
Show file tree
Hide file tree
Showing 2 changed files with 345 additions and 29 deletions.
39 changes: 16 additions & 23 deletions stripe/_api_requestor.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,20 @@ def _get_request_raw_args(

return abs_url, headers, post_data, my_api_key

@staticmethod
def log_response(abs_url, rcode, rcontent, rheaders):
_util.log_info(
"Stripe API response", path=abs_url, response_code=rcode
)
_util.log_debug("API response body", body=rcontent)

if "Request-Id" in rheaders:
request_id = rheaders["Request-Id"]
_util.log_debug(
"Dashboard link for request",
link=_util.dashboard_link(request_id),
)

def request_raw(
self,
method: str,
Expand Down Expand Up @@ -493,17 +507,7 @@ def request_raw(
method, abs_url, headers, post_data, _usage=_usage
)

_util.log_info(
"Stripe API response", path=abs_url, response_code=rcode
)
_util.log_debug("API response body", body=rcontent)

if "Request-Id" in rheaders:
request_id = rheaders["Request-Id"]
_util.log_debug(
"Dashboard link for request",
link=_util.dashboard_link(request_id),
)
self.log_response(abs_url, rcode, rcontent, rheaders)

return rcontent, rcode, rheaders, my_api_key

Expand Down Expand Up @@ -539,18 +543,7 @@ async def request_raw_async(
method, abs_url, headers, post_data, _usage=_usage
)

_util.log_info(
"Stripe API response", path=abs_url, response_code=rcode
)
_util.log_debug("API response body", body=rcontent)

if "Request-Id" in rheaders:
request_id = rheaders["Request-Id"]
_util.log_debug(
"Dashboard link for request",
link=_util.dashboard_link(request_id),
)

self.log_response(abs_url, rcode, rcontent, rheaders)
return rcontent, rcode, rheaders, my_api_key

def _should_handle_code_as_error(self, rcode):
Expand Down
Loading

0 comments on commit ced75f8

Please sign in to comment.