Record swallowed exceptions on their spans
Where an error is caught and logged under a span that would otherwise stay clean, also record_exception and set ERROR on that span: the CONSUMER span when a stream message fails, fraud.score_transaction when the sanctions call times out or fails, and the SERVER span of every /readyz check (a 503 already made it ERROR, but without the exception). Left alone where instrumentation already records it: ledger's app-wide exception handler (FastAPI SERVER span), caught httpx errors (CLIENT span), and the stream publish failure (PRODUCER span). The consumers' failed reads run outside any span, so they stay log-only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
d52a19965a
commit
1ab425dc44
@@ -3,6 +3,7 @@ from fastapi import FastAPI, Request
|
||||
from fastapi.responses import JSONResponse
|
||||
from pydantic import BaseModel
|
||||
from opentelemetry import trace
|
||||
from opentelemetry.trace import StatusCode
|
||||
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
|
||||
|
||||
from common.http import downstream_client
|
||||
@@ -52,6 +53,9 @@ async def readyz():
|
||||
try:
|
||||
await redis_client.ping()
|
||||
except Exception as exc:
|
||||
span = trace.get_current_span()
|
||||
span.record_exception(exc)
|
||||
span.set_status(StatusCode.ERROR, str(exc))
|
||||
logger.exception(f"readyz check failed: {exc}")
|
||||
return JSONResponse(status_code=503, content={"status": "unavailable"})
|
||||
return {"status": "ok"}
|
||||
@@ -81,10 +85,14 @@ async def score_transaction(body: ScoreRequest):
|
||||
f"{settings.sanctions_url}/internal/lookup",
|
||||
json={"holder_name": body.holder_name, "request_id": body.request_id},
|
||||
)
|
||||
except httpx.TimeoutException:
|
||||
except httpx.TimeoutException as exc:
|
||||
span.record_exception(exc)
|
||||
span.set_status(StatusCode.ERROR, "sanctions lookup timed out")
|
||||
logger.exception(f"sanctions lookup timed out for request_id={body.request_id}")
|
||||
return JSONResponse(status_code=504, content={"error": "sanctions lookup timed out"})
|
||||
except httpx.RequestError as exc:
|
||||
span.record_exception(exc)
|
||||
span.set_status(StatusCode.ERROR, "sanctions lookup failed")
|
||||
logger.exception(f"sanctions lookup failed for request_id={body.request_id}: {exc}")
|
||||
return JSONResponse(status_code=502, content={"error": "sanctions lookup failed"})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user