caelum0x 13abc31645 feat(ration): observability, infra-as-code, security hardening, and test depth
Phase 2 sections 2-6 and 8 of docs/SCALE-EXPANSION.md:

- pkg/telemetry + pkg/metrics: OpenTelemetry trace propagation and
  Prometheus metrics across every service hop (CLI -> agent -> gateway ->
  card-issuance/tenant-registry/auth -> ledger-core), tracing added to
  ledger-core itself via services/ledger-core/src/telemetry.rs.
- infra/: otel-collector + Prometheus + Grafana docker-compose stack, a
  Terraform ECS Fargate module + dev/staging/prod envs (plan-only, no
  apply — real AWS spend is an owner action), and a dev-only mTLS CA
  (infra/dev-ca) wired through pkg/mtls + services/ledger-core/src/mtls.rs.
- services/audit-log (from the prior commit) gets its async mirror writer
  in services/ledger-core/src/audit_mirror.rs, and services/gateway gets
  a per-tenant token-bucket rate limiter (internal/ratelimit).
- Test depth: a Rust proptest suite proving concurrent ApplyEntry never
  breaches the reserve floor (tests/apply_entry_proptest.rs, passing), a Go
  fuzz seed corpus for the policy envelope (rules_fuzz_test.go), a libFuzzer
  harness for the C WAL frame parser (services/wal/fuzz, deliberately not
  wired into `make test` per its own Makefile comment - needs a
  libFuzzer-bundled clang), and a real chaos test
  (scripts/chaos/kill-ledger-mid-write.sh) that SIGKILLs ledger-core
  mid-write under concurrent load and verifies via ListEntries that
  nothing was lost or double-applied.
- docs/formal/ledger.tla: a TLA+ spec of the ledger state machine (balance
  >= reserve_floor safety, HOLD-eventually-resolves liveness) plus a TLC
  model config - not run through TLC in this pass, that's a precise
  documented TODO, not faked.
- docs/adr/0001-0004, docs/RUNBOOK.md, docs/SLO.md, docs/THREAT-MODEL.md.

Verified: `make build && make test` clean (C WAL, Rust incl. the new
proptest suite, all 10 Go modules) from a cold target.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-19 12:25:58 +03:00

35 lines
1.5 KiB
Go

package telemetry
import (
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"google.golang.org/grpc"
)
// ServerOption returns the grpc.ServerOption that wires OpenTelemetry
// trace propagation into every unary and streaming RPC a server
// receives: it extracts an incoming W3C traceparent from gRPC metadata
// (if the caller is itself instrumented, e.g. another Ration service)
// and starts a server span as its child, or starts a fresh root span if
// this is the entry point of a trace (e.g. the first hop from the CLI).
//
// Pass this to grpc.NewServer alongside UnaryServerInterceptor /
// StreamServerInterceptor (below) for structured request logging —
// stats handlers (tracing) and interceptors (logging/correlation IDs)
// compose cleanly and both run on every RPC.
func ServerOption() grpc.ServerOption {
return grpc.StatsHandler(otelgrpc.NewServerHandler())
}
// DialOption returns the grpc.DialOption that wires OpenTelemetry trace
// propagation into every RPC a client issues: it starts a client span
// and injects its W3C traceparent into outgoing gRPC metadata so the
// receiving service's ServerOption picks it up as the same trace.
//
// Every grpc.NewClient call in this project (gateway's ledger-core
// client, agent's ledger-core/gateway clients, cli's and tui's clients)
// should pass this so a single CLI command's trace spans every hop it
// causes.
func DialOption() grpc.DialOption {
return grpc.WithStatsHandler(otelgrpc.NewClientHandler())
}