Skip to content

Commit

Permalink
Lukas/log request params on error (#33)
Browse files Browse the repository at this point in the history
* fix(verbose_logging): exclude auth and headers on errors

also json dump params

* chore(version): release 0.16.2
  • Loading branch information
lucas03 authored Aug 20, 2024
1 parent 9c0317c commit f1adc40
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
26 changes: 17 additions & 9 deletions request_session/request_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def _process(
max_runs = 1 + (self.max_retries if max_retries is None else max_retries)
run, retries_on_econnreset = 0, 0
# this will set maximum number of retries to max_runs where econnreset retries
# are not counting and maximum number of of retries on econnreset is also
# are not counting and maximum number of retries on econnreset is also
# set to max_runs
while run < max_runs + retries_on_econnreset:
run += 1
Expand Down Expand Up @@ -480,11 +480,13 @@ def _log_with_params(
"""
extra_params = (
{
"request_params": {
k: v
for k, v in deepcopy(request_params).items()
if k not in self.request_param_logging_blacklist
},
"request_params": json.dumps(
{
k: v
for k, v in deepcopy(request_params).items()
if k not in self.request_param_logging_blacklist
}
),
"response_text": self.get_response_text(response),
}
if self.verbose_logging
Expand Down Expand Up @@ -557,11 +559,11 @@ def _exception_log_and_metrics(
# type: (...) -> None
"""Assign appropriate metric and log for exception.
:param requests.RequestException error: exception that occured
:param requests.RequestException error: exception that occurred
:param str request_category: String describing request category.
:param Dict request_params: Parameters used to make the HTTP call.
:param List[str] dd_tags: Tags to increment metric with.
:param Union[int, None] Status_code: HTTP status code of the response.
:param Union[int, None] status_code: HTTP status code of the response.
"""
tags = ["status:error"]

Expand All @@ -586,7 +588,13 @@ def _exception_log_and_metrics(
tags.append("error:request_exception")

if self.verbose_logging is True:
extra_params["request_params"] = json.dumps(request_params)
extra_params["request_params"] = json.dumps(
{
k: v
for k, v in deepcopy(request_params).items()
if k not in self.request_param_logging_blacklist
}
)

self.log(
"exception",
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

setup(
name="request_session",
version="0.16.1",
version="0.16.2",
url="https://github.com/kiwicom/request-session",
description="Python HTTP requests on steroids",
long_description=readme,
Expand Down

0 comments on commit f1adc40

Please sign in to comment.