Rewrite every log call as an event name with typed fields
Prose f-strings become past-tense events with consistent field names across services (account_id, transaction_id, amount_minor, risk_score, status_code, consumer_group, message_id, chaos_flag). The orchestrator and both consumers move from logging.getLogger to structlog so they can pass fields. New events cover what was silent before: the gateway's UpstreamFailure path (transaction_failed, with the underlying cause), fraud's score and sanctions' screening outcomes, and each successfully processed stream message. holder_name is no longer logged at all. "lookup" and "healthz" still appear in exactly one event each, so the pathology tests' log-line counts are unchanged until they move to LogQL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
560e3afa0e
commit
bc11638a15
+11
-6
@@ -52,7 +52,7 @@ class SettleRequest(BaseModel):
|
||||
|
||||
@app.exception_handler(Exception)
|
||||
async def unhandled_exception_handler(request: Request, exc: Exception):
|
||||
logger.exception(f"unhandled exception on {request.url.path}: {exc}")
|
||||
logger.exception("unhandled_exception", path=request.url.path)
|
||||
return JSONResponse(status_code=500, content={"error": "internal error"})
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ async def root():
|
||||
@app.get("/healthz")
|
||||
async def healthz(request: Request):
|
||||
if request.headers.get("X-Ledgerline-Probe") == "chatty-health":
|
||||
logger.info("received chatty-health healthz probe from gateway")
|
||||
logger.info("healthz_probe_received", probe="chatty-health")
|
||||
return {"status": "ok", "service": SERVICE_NAME}
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ async def readyz():
|
||||
span = trace.get_current_span()
|
||||
span.record_exception(exc)
|
||||
span.set_status(StatusCode.ERROR, str(exc))
|
||||
logger.exception(f"readyz check failed: {exc}")
|
||||
logger.exception("readyz_check_failed")
|
||||
return JSONResponse(status_code=503, content={"status": "unavailable"})
|
||||
return {"status": "ok"}
|
||||
|
||||
@@ -91,7 +91,12 @@ async def list_accounts():
|
||||
|
||||
@app.post("/internal/transactions")
|
||||
async def create_transaction(body: CreateTransactionRequest):
|
||||
logger.info(f"processing tx for account {body.account_id}, amount {body.amount_minor}")
|
||||
logger.info(
|
||||
"transaction_received",
|
||||
account_id=body.account_id,
|
||||
kind=body.kind,
|
||||
amount_minor=body.amount_minor,
|
||||
)
|
||||
|
||||
starved = await chaos.pool_starvation_enabled()
|
||||
poison_enabled = await chaos.poison_data_enabled()
|
||||
@@ -151,7 +156,7 @@ async def settle(tx_id: str, body: SettleRequest):
|
||||
use_lock = row_lock and bool(account.is_hot)
|
||||
balance = await repository.settle_transaction(session, tx=tx, risk_score=body.risk_score, use_row_lock=use_lock)
|
||||
|
||||
logger.info(f"settled transaction {tx_id}")
|
||||
logger.info("transaction_settled", transaction_id=tx_id, risk_score=body.risk_score)
|
||||
return {"status": "settled", "balance_minor": balance}
|
||||
|
||||
|
||||
@@ -165,5 +170,5 @@ async def reject(tx_id: str, body: SettleRequest):
|
||||
return JSONResponse(status_code=404, content={"error": "transaction not found"})
|
||||
balance = await repository.reject_transaction(session, tx=tx, risk_score=body.risk_score)
|
||||
|
||||
logger.info(f"rejected transaction {tx_id}")
|
||||
logger.info("transaction_rejected", transaction_id=tx_id, risk_score=body.risk_score)
|
||||
return {"status": "rejected", "balance_minor": balance}
|
||||
|
||||
Reference in New Issue
Block a user