Skip to content

Replace no-op API counter with production metrics adapter - #1905

Open
dotunv wants to merge 1 commit into
Stellar-Mail:mainfrom
dotunv:victor/metrics-adapter-1509
Open

Replace no-op API counter with production metrics adapter#1905
dotunv wants to merge 1 commit into
Stellar-Mail:mainfrom
dotunv:victor/metrics-adapter-1509

Conversation

@dotunv

@dotunv dotunv commented Jul 29, 2026

Copy link
Copy Markdown

Summary

Replace the in-memory-only API counter with an adapter-based metrics system that produces observable values in production.

Changes

  • MetricsAdapter interface — defines incrementCounter, recordHistogram, and recordAuditEvent
  • InMemoryMetricsAdapter — retains the existing map-based implementation; used by default outside production and in tests
  • ProductionMetricsAdapter — emits structured JSON logs to stdout with a _metric discriminator for log-aggregation pipelines
  • setAdapter/getAdapter — allows tests to swap adapters
  • New metric descriptorsauth_failures_total, rate_limits_total, postage_transitions_total (all documented in METRIC_DESCRIPTORS)
  • Instrumentation — auth failures (401/403), rate limit hits (429), and postage state transitions now emit metrics

Acceptance criteria

  • Counter calls produce observable values in production
  • Tests can inspect an in-memory adapter
  • Metrics failures do not fail requests
  • All emitted metric names are documented in METRIC_DESCRIPTORS

Closes #1509

Define a MetricsAdapter interface with incrementCounter, recordHistogram,
and recordAuditEvent. Implement InMemoryMetricsAdapter (for tests) and
ProductionMetricsAdapter (emits structured JSON logs to stdout).

Instrument request totals, outcomes, authentication failures, rate limits,
and postage domain transitions.

Closes Stellar-Mail#1509
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.

Replace the no-op API counter with a production metrics adapter

2 participants