Skip to content

feat(observability): metrics, alarms, error tracking, cache verification (fixes #17)#27

Merged
ianpatrickhines merged 3 commits into
mainfrom
claude/issue-17-observability
Jun 22, 2026
Merged

feat(observability): metrics, alarms, error tracking, cache verification (fixes #17)#27
ianpatrickhines merged 3 commits into
mainfrom
claude/issue-17-observability

Conversation

@ianpatrickhines

Copy link
Copy Markdown
Owner

Closes #17.

What

  • CloudWatch custom metrics (shared/metrics.py): subscription verifications, query-limit hits, NB API errors, token-refresh failures, agent latency.
  • Alarms (template.yaml): elevated error rate, Stripe webhook failures, token-refresh failures, "nation not found" spikes.
  • Error tracking (shared/observability.py): Sentry wired into all Lambda handlers; no-ops when SENTRY_DSN is unset (so it's safe to deploy before provisioning Sentry — DSN goes in under Consolidate to one domain, replace placeholder URLs, load real secrets #14 secrets).
  • Cache verification: logs cache hit/miss from the Anthropic response usage so we can finally confirm the documented ~87% prompt-cache savings are real.

Verified

  • pytest -q556 passed (= 542 on clean main + 14 new; no existing tests lost — confirmed by per-file collection diff)
  • mypy src/ → clean (24 files)
  • Adds sentry-sdk>=2.0.0 to requirements.txt (optional at runtime)

Provenance

Authored by a pr-driver Opus drive that hit the 80-turn ceiling before committing; working tree preserved, independently re-verified (tests + mypy + collection-count audit) from the main session, then committed and opened here. No adversarial self-review ran — recommend a careful /ship review of the metric/alarm wiring and the Sentry init path before merge.

…ion (fixes #17)

- shared/metrics.py: CloudWatch custom metrics (subscription verifications,
  query-limit hits, NB API errors, token-refresh failures, agent latency)
- shared/observability.py: Sentry error tracking wired into all Lambda
  handlers; no-ops when SENTRY_DSN is unset (sentry-sdk optional dep)
- CloudWatch alarms in template.yaml (error rate, webhook failures,
  token-refresh failures, nation-not-found spikes)
- Cache hit/miss logged from Anthropic response usage to verify prompt
  caching is actually active
- Tests for metrics + observability (+14)

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
ianpatrickhines and others added 2 commits June 22, 2026 12:10
…vability

# Conflicts:
#	src/lambdas/nat_agent_streaming/handler.py
Independent review of #27 noted the ResultMessage instrumentation (cache
usage + agent latency emit) shipped untested — _FakeResultMessage lacked
usage/duration_ms and no test injected a ResultMessage into the stream.
Added the fields to the fake (mirroring the real SDK) and a test asserting
record_cache_usage receives the usage dict and a latency metric is emitted.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@ianpatrickhines
ianpatrickhines merged commit 7c6ccda into main Jun 22, 2026
3 checks passed
@ianpatrickhines
ianpatrickhines deleted the claude/issue-17-observability branch June 22, 2026 16:26
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.

Add observability: metrics, alarms, error tracking, verify prompt caching

1 participant