Skip to content

Gate response body debug log behind log_requests - #371

Open
adityaanikam wants to merge 1 commit into
bybit-exchange:masterfrom
adityaanikam:fix-check-status-code-log-gating-368
Open

Gate response body debug log behind log_requests#371
adityaanikam wants to merge 1 commit into
bybit-exchange:masterfrom
adityaanikam:fix-check-status-code-log-gating-368

Conversation

@adityaanikam

Copy link
Copy Markdown

_check_status_code logged the full response body at DEBUG on every non 200 response unconditionally, unlike the sibling debug log sites in the same class (_log_request and the "Response headers" line in _handle_response), which are both gated behind log_requests. A consumer that never sets log_requests, or sets it False, still got the response body dumped to the pybit logger on any non-200, and could only silence it by raising the logger level rather than through log_requests. The body can contain sensitive account data on some endpoints.

Wrapped the one log call in the same if self.log_requests check used everywhere else in this class.

Added two tests exercising _check_status_code directly: one confirms the log is absent when log_requests is not set, the other confirms it still fires when log_requests=True. Verified the first test actually catches the regression by reverting the fix locally and confirming it fails.

Closes #368

_check_status_code logged the full response body at DEBUG on every non-200 response unconditionally, unlike the sibling debug log sites in the same class (_log_request and the "Response headers" line in _handle_response), which are both gated behind log_requests. A consumer that never sets log_requests, or sets it False, still got the response body dumped to the pybit logger on any non-200, and could only silence it by raising the logger level rather than through log_requests. The body can contain sensitive account data on some endpoints.

Wrapped the one log call in the same if self.log_requests check used everywhere else in this class.

Added two tests exercising _check_status_code directly: one confirms the log is absent when log_requests is not set, the other confirms it still fires when log_requests=True. Verified the first test actually catches the regression by reverting the fix locally and confirming it fails.

Closes bybit-exchange#368
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_check_status_code logs Response text at DEBUG regardless of log_requests

1 participant