Add request/response debug logging#23
Conversation
Introduce ShadeClient with debug mode and global config so developers can inspect masked HTTP traffic during integration troubleshooting.
Resolve conflicts in __init__.py (combine exports), test_gateway.py (keep patch import, drop unused pytest), and regenerate poetry.lock.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds ChangesRequest/response debug logging
Sequence Diagram(s)sequenceDiagram
participant ShadeClient
participant shade._debug.log_request
participant httpx.Client
participant shade._debug.log_response
participant logger
ShadeClient->>shade._debug.log_request: log_request(method, url, masked headers, body)
ShadeClient->>httpx.Client: request(method, url, headers, json, content)
httpx.Client-->>ShadeClient: httpx.Response
ShadeClient->>shade._debug.log_response: log_response(status_code, masked headers, body)
shade._debug.log_request->>logger: logger.debug(message)
shade._debug.log_response->>logger: logger.debug(message)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/shade/client.py`:
- Line 50: The URL composition in Client should normalize the path before
joining it with base_url, because using a raw path can produce invalid URLs when
the path is missing a leading slash. Update the logic around the url assignment
in Client to ensure path is normalized consistently before concatenation, and
keep the fix localized to the URL-building code in this method.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: add01f4d-79ca-40d3-9a34-a54efac4e31e
⛔ Files ignored due to path filters (1)
poetry.lockis excluded by!**/*.lock
📒 Files selected for processing (7)
pyproject.tomlsrc/shade/__init__.pysrc/shade/_debug.pysrc/shade/client.pysrc/shade/config.pytests/test_debug_logging.pytests/test_gateway.py
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Overview
This PR adds request/response debug logging to the Shade Python SDK so developers can troubleshoot integration issues with visibility into outgoing requests and incoming responses. It introduces
ShadeClientwith adebugflag, a globalconfig.debugsetting, and structuredlogging.DEBUGoutput under theshadelogger with sensitive values masked.Related Issue
Closes #13
Changes
🔍 Debug Logging System
[ADD]
src/shade/client.pyAdded
ShadeClientwithdebug: bool = Falseand an HTTPrequest()method.Emits debug logs for outgoing requests (method, URL, headers, body) and incoming responses (status, headers, body) when debug mode is enabled.
Supports both per-client
debug=Trueand globalconfig.debug = True.[ADD]
src/shade/_debug.pyAdded helpers to mask
Authorizationheader values (only last 4 characters visible).Added response body truncation at 2000 characters with a
[truncated]suffix.Added structured request/response logging via Python's
loggingmodule atDEBUGlevel under theshadelogger.[ADD]
src/shade/config.pyAdded global SDK configuration with
debug: bool = False.[MODIFY]
src/shade/__init__.pyExported
ShadeClientandconfigfrom the public API.🧪 Tests
[ADD]
tests/test_debug_logging.pyAdded tests for authorization header masking.
Added tests for response body truncation.
Added tests verifying debug logs are emitted when
debug=True.Added tests verifying no request/response content is logged when
debug=False.Added tests verifying global
config.debugenables logging.[MODIFY]
tests/test_gateway.pyRemoved unused
pytestimport.🔧 Dependencies
[MODIFY]
pyproject.tomlAdded
httpxas an HTTP client dependency forShadeClient.[MODIFY]
poetry.lockUpdated lockfile for the new
httpxdependency.Verification Results
debug=True, each request logs method, URL, and masked headersdebug=False(default), no request/response content is loggedlogging.DEBUGlevel under theshadelogger[truncated]Summary by CodeRabbit
ShadeClientfor API requests with configurable base URL, context-manager support, and optional debug logging.shade.config.debug) and exported it at the package level.httpxruntime dependency.