Skip to content

feat: add structured JSON logging with structlog#156

Merged
YaronZaki merged 6 commits into
Quantarq:mainfrom
eischideraa-unn:feature/structured-json-logging
Jun 23, 2026
Merged

feat: add structured JSON logging with structlog#156
YaronZaki merged 6 commits into
Quantarq:mainfrom
eischideraa-unn:feature/structured-json-logging

Conversation

@eischideraa-unn

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

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor

Hi @eischideraa-unn — solid structlog migration overall: structured event names, request_id middleware, and the wallet masking processor are exactly what we want. CI is failing at install though, because pyproject.toml (now depending on structlog >=24.1.0) drifted from poetry.lock:

pyproject.toml changed significantly since poetry.lock was last generated. Run poetry lock to fix the lock file.

Quick fix: run poetry lock locally and commit the updated lockfile. Once CI turns green, happy to merge. ✅

@eischideraa-unn

Copy link
Copy Markdown
Contributor Author

Hello @YaronZaki I am on it.

@eischideraa-unn

Copy link
Copy Markdown
Contributor Author

Hello @YaronZaki all CI have been passed, please you can merge now.

@YaronZaki YaronZaki left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@YaronZaki YaronZaki merged commit e2aaef9 into Quantarq:main Jun 23, 2026
3 checks passed
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

2 participants