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
@@ -1,8 +1,8 @@
|
||||
import logging
|
||||
import time
|
||||
import uuid
|
||||
|
||||
import httpx
|
||||
import structlog
|
||||
from opentelemetry import propagate, trace
|
||||
from opentelemetry.trace import SpanKind
|
||||
|
||||
@@ -12,7 +12,7 @@ from common.settings import settings
|
||||
|
||||
from . import chaos
|
||||
|
||||
logger = logging.getLogger("gateway")
|
||||
logger = structlog.get_logger("gateway")
|
||||
tracer = trace.get_tracer(__name__)
|
||||
|
||||
REJECT_THRESHOLD = 0.8
|
||||
@@ -76,7 +76,12 @@ async def _run_chatty_health_probe(client: httpx.AsyncClient) -> None:
|
||||
|
||||
async def create_transaction(payload: dict) -> dict:
|
||||
start = time.perf_counter()
|
||||
logger.info(f"start transaction for account {payload['account_id']}")
|
||||
logger.info(
|
||||
"transaction_started",
|
||||
account_id=payload["account_id"],
|
||||
kind=payload["kind"],
|
||||
amount_minor=payload["amount_minor"],
|
||||
)
|
||||
|
||||
retry_storm = await chaos.retry_storm_enabled()
|
||||
no_batching = await chaos.no_batching_enabled()
|
||||
@@ -155,7 +160,7 @@ async def create_transaction(payload: dict) -> dict:
|
||||
msg_id = await redis_client.xadd(settings.stream_name, fields)
|
||||
span.set_attribute("messaging.message.id", msg_id)
|
||||
except Exception:
|
||||
logger.exception(f"failed to publish transaction {tx_id} to the stream")
|
||||
logger.exception("stream_publish_failed", transaction_id=tx_id)
|
||||
|
||||
summary = {}
|
||||
try:
|
||||
@@ -165,10 +170,16 @@ async def create_transaction(payload: dict) -> dict:
|
||||
if summary_resp.status_code == 200:
|
||||
summary = summary_resp.json()
|
||||
except httpx.RequestError:
|
||||
logger.exception(f"insights summary unavailable for transaction {tx_id}")
|
||||
logger.exception("insights_summary_unavailable", transaction_id=tx_id)
|
||||
|
||||
elapsed_ms = (time.perf_counter() - start) * 1000
|
||||
logger.info(f"finished transaction {tx_id} status={settled['status']}")
|
||||
logger.info(
|
||||
"transaction_finished",
|
||||
transaction_id=tx_id,
|
||||
status=settled["status"],
|
||||
risk_score=risk_score,
|
||||
duration_ms=round(elapsed_ms, 1),
|
||||
)
|
||||
|
||||
return {
|
||||
"transaction_id": tx_id,
|
||||
|
||||
Reference in New Issue
Block a user