Skip to content

feat: add structured JSON logging with structlog#156

Open
eischideraa-unn wants to merge 1 commit into
Quantarq:mainfrom
eischideraa-unn:feature/structured-json-logging
Open

feat: add structured JSON logging with structlog#156
eischideraa-unn wants to merge 1 commit into
Quantarq:mainfrom
eischideraa-unn:feature/structured-json-logging

Conversation

@eischideraa-unn

@eischideraa-unn eischideraa-unn commented Jun 21, 2026

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

obs: Add structured JSON logging throughout backend

1 participant