Skip to content
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

Lukas/log request params on error #33

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading