Add business spans and silence the frontend health poll
Manual INTERNAL spans for the business steps the auto-instrumentation can't name: fraud.score_transaction, sanctions.lookup_watchlist, ledger.settle and insights.aggregate_120d, with ledgerline.* attributes (account, amount, risk score, match outcome). holder_name stays off the spans. Each span starts after its handler's chaos flag reads and injection points, and no chaos-derived values become attributes. The gateway's /api/health/all fan-out now runs under suppress_instrumentation: with the route excluded, its five downstream /healthz calls were each a parentless root trace. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
d1c158c835
commit
d52a19965a
@@ -1,4 +1,5 @@
|
||||
import sqlalchemy as sa
|
||||
from opentelemetry import trace
|
||||
|
||||
# Deliberately the same shape of query the test suite's own EXPLAIN check runs
|
||||
# against the schema directly (tests/test_pathologies.py, 6.4) -- kept here
|
||||
@@ -6,6 +7,8 @@ import sqlalchemy as sa
|
||||
|
||||
_N_PLUS_ONE_ROW_CAP = 1500
|
||||
|
||||
tracer = trace.get_tracer(__name__)
|
||||
|
||||
|
||||
async def account_exists(session, account_id: str) -> bool:
|
||||
result = await session.execute(sa.text("SELECT 1 FROM accounts WHERE id = :id"), {"id": account_id})
|
||||
@@ -13,29 +16,34 @@ async def account_exists(session, account_id: str) -> bool:
|
||||
|
||||
|
||||
async def compute_summary(session, account_id: str, *, n_plus_one: bool) -> dict:
|
||||
if n_plus_one:
|
||||
rows = await _n_plus_one_summary(session, account_id)
|
||||
else:
|
||||
rows = await _joined_summary(session, account_id)
|
||||
with tracer.start_as_current_span(
|
||||
"insights.aggregate_120d",
|
||||
attributes={"ledgerline.account.id": account_id, "ledgerline.summary.window_days": 120},
|
||||
) as span:
|
||||
if n_plus_one:
|
||||
rows = await _n_plus_one_summary(session, account_id)
|
||||
else:
|
||||
rows = await _joined_summary(session, account_id)
|
||||
|
||||
total_count = 0
|
||||
total_amount = 0
|
||||
by_category: dict = {}
|
||||
for r in rows:
|
||||
total_count += 1
|
||||
total_amount += r["amount_minor"]
|
||||
label = r["label"] or "uncategorized"
|
||||
entry = by_category.setdefault(label, {"count": 0, "total_amount_minor": 0})
|
||||
entry["count"] += 1
|
||||
entry["total_amount_minor"] += r["amount_minor"]
|
||||
total_count = 0
|
||||
total_amount = 0
|
||||
by_category: dict = {}
|
||||
for r in rows:
|
||||
total_count += 1
|
||||
total_amount += r["amount_minor"]
|
||||
label = r["label"] or "uncategorized"
|
||||
entry = by_category.setdefault(label, {"count": 0, "total_amount_minor": 0})
|
||||
entry["count"] += 1
|
||||
entry["total_amount_minor"] += r["amount_minor"]
|
||||
|
||||
return {
|
||||
"account_id": account_id,
|
||||
"window_days": 120,
|
||||
"transaction_count": total_count,
|
||||
"total_amount_minor": total_amount,
|
||||
"by_category": by_category,
|
||||
}
|
||||
span.set_attribute("ledgerline.summary.transaction_count", total_count)
|
||||
return {
|
||||
"account_id": account_id,
|
||||
"window_days": 120,
|
||||
"transaction_count": total_count,
|
||||
"total_amount_minor": total_amount,
|
||||
"by_category": by_category,
|
||||
}
|
||||
|
||||
|
||||
async def _joined_summary(session, account_id: str) -> list[dict]:
|
||||
|
||||
Reference in New Issue
Block a user