feat: add structured JSON logging with structlog#156
Open
eischideraa-unn wants to merge 1 commit into
Open
Conversation
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.
Description
Adds structured JSON logging throughout the backend using structlog. All existing unstructured logging.getLogger / f-string log calls have been replaced with key=value structured calls. A new web_app/utils/logger.py module centralises logging configuration, wallet masking, and logger instantiation. A request_id middleware ensures every log entry emitted during a request lifecycle is traceable by a unique ID.
Key behaviours:
JSON output in production (ENV_VERSION=PROD), human-readable coloured output in development
Every log entry carries: timestamp, level, logger, request_id, event
wallet_id is automatically masked (GABCDE****WXYZ) in all log entries — Stellar public keys embedded in message strings are also scrubbed via regex
X-Request-Id header is accepted from the client or auto-generated (UUID), bound to the structlog context, and echoed in the response
Related Issue
Closes #81 (obs: Add structured JSON logging throughout backend)
Change Type
feat — new feature
fix — bug fix
docs — documentation
refactor — code refactoring
test — adding or updating tests
ci — CI/CD changes
Testing Done
Unit tests added in web_app/tests/test_structured_logging.py:
TestMaskWalletId — verifies correct masking for normal keys, short strings, empty strings, and 12-char boundary inputs
TestMaskWalletProcessor — verifies wallet_id field masking, in-message Stellar key scrubbing, and safe pass-through for messages with no wallet data
TestConfigureLoggingJson — verifies JSON output is valid and contains required fields (level, timestamp) in production mode
TestGetLogger — verifies get_logger() returns valid logger instances
TestRequestIdMiddleware — verifies X-Request-Id is present on every response, that a client-supplied ID is echoed back unchanged, and that auto-generated IDs are valid UUIDs
All existing test suites remain unmodified and passing.
Screenshots (if UI changes)
N/A — backend logging only, no UI changes.