Add logger framework for the sdk#171
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2eeec94d4d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
Adds a stdlib logging-based logging framework to the pyTFE SDK, including transport-level HTTP tracing with redaction/truncation controls and accompanying documentation/tests.
Changes:
- Introduces
pytfe._loggingwithsetup_logging(), header/body redaction, andRoundTriprequest/response formatting. - Integrates transport logging into
HTTPTransport(DEBUG round-trips, INFO retry decisions, DEBUG transport exceptions). - Adds documentation (
README.md,docs/LOGGING.md,AGENTS.md) and unit tests covering namespace, env config, redaction, truncation, and transport behavior.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/units/test_logging.py | Adds unit tests for logger naming, env-driven config, redaction/truncation, and transport logging behavior. |
| src/pytfe/_logging.py | Implements logging primitives: env-based setup, redaction helpers, and RoundTrip formatter. |
| src/pytfe/_http.py | Emits transport logs (retry/exception) and adds DEBUG round-trip logging via RoundTrip. |
| src/pytfe/init.py | Exports setup_logging from the package root. |
| README.md | Documents how to enable/configure logging and links to LOGGING.md. |
| docs/LOGGING.md | Adds detailed internal/reference documentation for the logging framework. |
| AGENTS.md | Updates contributor guidance to use the new logging framework instead of print()/ad-hoc loggers. |
Comments suppressed due to low confidence (1)
src/pytfe/_http.py:125
- This INFO retry log prints the full
urlstring. For requests to presigned blob URLs (state version downloads/uploads, redirectLocationtargets), the URL query often contains signatures/credentials; logging it at INFO can leak secrets in normal production logs. Consider logging a sanitized URL (path only, or redacted query) here, consistent with the redaction guarantees described in LOGGING.md.
transport_logger.info(
"retrying %s %s after %s (status=%d, attempt=%d)",
method,
url,
f"{retry_after:.2f}s" if retry_after else "backoff",
resp.status_code,
attempt,
)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # httpx.URL has .path / .query (bytes) — render in a way matching | ||
| # what the wire saw, but with query unquoted for human reading. | ||
| from urllib.parse import unquote, urlparse | ||
|
|
||
| url = urlparse(str(request.url)) | ||
| query = f"?{unquote(url.query)}" if url.query else "" | ||
| path = unquote(url.path) or "/" | ||
|
|
||
| sb: list[str] = [f"> {request.method} {path}{query}"] |
| transport_logger.debug( | ||
| "transport exception on %s %s (attempt %d): %s", | ||
| method, | ||
| url, | ||
| attempt, | ||
| e, | ||
| ) |
| | `PYTFE_LOG_HEADERS` | `false` | When truthy, include request/response headers in `RoundTrip` output. Sensitive ones are still redacted; this just turns on the `> * Header: value` lines at all. | | ||
| | `PYTFE_LOG_TRUNCATE_BYTES` | `1024` | Truncation budget for any single string in a logged body. Values below 96 are clamped up. | | ||
|
|
||
| All three are read at call time, not at import — switching `PYTFE_LOG_HEADERS=true` in the middle of a long-running process takes effect on the next request. |
JIRA