[MNT] Replace traceback.print_exc() with logging.exception() for structured logging#740
Open
aryan-2255 wants to merge 1 commit intoaiondemand:developfrom
Open
Conversation
…ctured logging Replace all traceback.print_exc() calls with logging.exception() in production code. print_exc() writes to stderr which can be lost in Docker containers, while logging.exception() goes through the configured logging pipeline (Logstash → Grafana) and includes the full traceback automatically. Files changed: - src/error_handling/error_handling.py - src/routers/resource_router.py - src/routers/resource_routers/platform_router.py
There was a problem hiding this comment.
Pull request overview
This PR improves production observability by routing unexpected exception tracebacks through the configured Python logging pipeline (instead of stderr) so they are captured by centralized logging/monitoring (e.g., Logstash/Grafana).
Changes:
- Replaced
traceback.print_exc()withlogging.exception(...)in three production locations to preserve full tracebacks in structured logs. - Removed
tracebackimports where they are no longer used and addedloggingimports where needed.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/error_handling/error_handling.py |
Logs unexpected exceptions via logging.exception inside as_http_exception instead of printing to stderr. |
src/routers/resource_router.py |
Uses logging.exception when an unexpected exception has no args during resource operations. |
src/routers/resource_routers/platform_router.py |
Uses logging.exception when an unexpected exception has no args during platform operations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Replace all traceback.print_exc() calls with logging.exception() in production code. print_exc() writes to stderr which can be lost in Docker containers, while logging.exception() goes through the configured logging pipeline (Logstash, Grafana) and includes the full traceback automatically.
Files changed:
Change(s)
Change Type: Fixed
Change Category: Internal
Changelog Entry: Replace traceback.print_exc() with logging.exception() in 3 production files for proper structured logging.
Currently, when an unexpected exception with no args hits _raise_clean_http_exception() or as_http_exception(), the traceback is printed to stderr via print_exc(). In Docker, stderr output can be lost and is not captured by the Logstash shipper. logging.exception() produces the same full traceback but routes it through the Python logging system, making errors visible in Grafana.
How to Test
Run pytest src/tests/ and verify all tests pass. No special setup needed since logging.exception() is a drop-in replacement that produces the same traceback output.
Checklist
Related Issues
Closes #739