fix(exceptions): log the full stack trace in the global exception handler - #204
Closed
tmgbedu wants to merge 1 commit into
Closed
fix(exceptions): log the full stack trace in the global exception handler#204tmgbedu wants to merge 1 commit into
tmgbedu wants to merge 1 commit into
Conversation
report_exception() built its log context via _build_context(), which only appended the traceback when the app was in debug mode. In production the ERROR log carried just 'ExcType: message' (e.g. 'ModuleNotFoundError: No module named app.agents.chat') with no stack trace, making failures hard to diagnose. Always include the full traceback in the logged/stderr context. Exposing the trace to the HTTP client stays a separate, debug-gated decision in the FastAPI render layer, so this doesn't leak internals to users. Add tests asserting the traceback is logged in both non-debug and debug modes, and printed to stderr when no logger is bound.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
Author
|
Code review — PASS (task #1349) Reviewed the diff, the render-layer for client exposure, and the new tests. (Note: posting as a comment, not an approval review, since GitHub won't let this account approve its own PR.) Correctness
No client-facing leakage
Tests
LGTM. Holding off on merge until QA (task #1348) signs off, per the coordination task. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The global
ExceptionHandler.report_exception()builds its log message via_build_context(), which only appended the traceback when the app was in debug mode. In production the ERROR log carried just the exception summary — e.g.ModuleNotFoundError: No module named 'app.agents.chat'— with no stack trace, so failures were effectively undiagnosable from logs.Fix
_build_context()now always returns the fulltraceback.format_exception(...)output (matching the module's existing traceback convention). Whether the trace is shown to the HTTP client remains a separate, debug-gated decision in the FastAPI render layer (fastapi/exceptions.py), so this does not leak internals to end users — it only enriches server-side logs / stderr.Tests
New
tests/exceptions/test_handler.py:uv run pytest(excl. live-Postgres): 2053 passed, 7 skipped. Ruff clean.Task #1347.