Skip to content

feat(ledger): wire prometheus metrics, otlp tracing and structured json logs - #141

Merged
tiana-code merged 4 commits into
mainfrom
feat/E-01-observability
Jun 16, 2026
Merged

feat(ledger): wire prometheus metrics, otlp tracing and structured json logs#141
tiana-code merged 4 commits into
mainfrom
feat/E-01-observability

Conversation

@tiana-code

Copy link
Copy Markdown
Owner

What

Wires generic OSS observability into the ledger service (Epic E-01).

  • Metrics: two bounded ledger counters via LedgerMetrics - ledger.transactions.posted (tag type=post|reversal) and ledger.balance.reads, incremented on the success path only (after the write + audit commit; failures throw earlier). Enables the http.server.requests percentile histogram. Exposed at /actuator/prometheus as ledger_transactions_posted_total / ledger_balance_reads_total (Micrometer appends _total, so the counter names deliberately omit it).
  • Tracing: Micrometer Tracing bridged to OpenTelemetry with an OTLP exporter; endpoint and sampling are env-overridable per profile (dev 1.0, prod ${TRACING_SAMPLING_PROBABILITY:0.1}, test disabled). traceId/spanId flow into the logging MDC via the bridge.
  • Structured logs: logging.structured.format.console=logstash on default/test/prod (one JSON line per event carrying correlation_id and trace ids from MDC); dev keeps the human-readable pattern with %X{correlation_id:-}.
  • Security: /actuator/prometheus added to PUBLIC_PATHS (mirrors /actuator/health); exposure stays health,info,prometheus.

Tagging / cardinality

Only the bounded type tag is used. No account id, transaction id, amount, actor, or correlation id is ever a metric tag or label. No money value is emitted as a metric.

Tests

  • Unit: LedgerMetricsTest (counter names/tags), poster + balance tests assert increment-on-success and no-increment-on-duplicate.
  • Integration (ObservabilityIT, CI only): prometheus reachable without a token and contains the posted counter with value >= 1 after a post; a logged line parses as logstash JSON with @timestamp/level/logger_name/message/correlation_id; the Tracer bean and tracing properties are bound.
  • MetricsTestConfig supplies a MeterRegistry to the 5 @DataJpaTest slices that import the poster/balance beans (no actuator autoconfig there).

Gate chain: analyst, architect, critic (GO-WITH-CHANGES, folded in), code-reviewer (caught the _total naming bug, fixed), security-auditor PASS, OSS-boundary PASS. Local gates green; integration tests run on CI.

Closes #51

@tanya_r added 4 commits June 16, 2026 00:46
…on logs

Add two bounded ledger counters (ledger.transactions.posted with a
post/reversal type tag, ledger.balance.reads) incremented on the success
path only, enable the http.server.requests percentile histogram, bridge
micrometer tracing to opentelemetry with a configurable otlp endpoint and
sampling, and switch console logging to logstash structured json on the
default, test and prod profiles while keeping the human-readable pattern
in dev. Expose /actuator/prometheus without a token, mirroring health.

Closes #51
…structured logs

Drop the explicit micrometer 1.13.7 and opentelemetry 1.41.0 pins so the
boot bom manages every micrometer and opentelemetry artifact uniformly.
The pins left micrometer-registry-prometheus at 1.13.7 while the tracing
bridge dragged micrometer-core to 1.15.1, and opentelemetry-api at 1.41.0
against a 1.49.0 sdk, which made the prometheus scrape return 500. Move
the structured-log assertion off the flaky OutputCapture path onto Boot
StructuredLogEncoder in a unit test.
Spring boot disables metrics export registries in @SpringBootTest by
default, so the prometheus registry was absent and /actuator/prometheus
returned 500. Add @AutoConfigureObservability so the test context wires
the prometheus registry, and drop the diagnostic scrape probe.
@tiana-code
tiana-code merged commit c3313ed into main Jun 16, 2026
6 checks passed
@tiana-code
tiana-code deleted the feat/E-01-observability branch June 16, 2026 04:30
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.

Configure observability (Micrometer, OTel, structured logs)

1 participant