Commit aaeaae9
authored
## Summary
Adds Prometheus `/metrics` scrape endpoint and OTLP log exporter,
closing the most significant telemetry gap (G1) for enterprise
control-plane positioning.
### Phase 1: Prometheus /metrics endpoint
- `GET /api/v1/metrics` -- unauthenticated Prometheus scrape target
- `PrometheusCollector` with dedicated `CollectorRegistry` (no global
pollution)
- **5 metric families**:
- `synthorg_agents_total{status, trust_level}` -- agent counts by status
and trust level
- `synthorg_tasks_total{status, agent}` -- task counts by lifecycle
status and assigned agent
- `synthorg_cost_total` -- total accumulated cost
- `synthorg_budget_used_percent` / `synthorg_budget_monthly_usd` --
budget utilization
- `synthorg_coordination_efficiency` /
`synthorg_coordination_overhead_percent` -- push-updated by coordination
collector
- `synthorg_security_evaluations_total{verdict}` -- security verdict
counter (bounded: allow/deny/escalate)
- `set_prometheus_collector()` on `AppState` for deferred initialization
- Returns 503 when collector not configured
### Phase 2: OTLP exporter
- `SinkType.OTLP` + `OtlpProtocol` enum (HTTP/protobuf only; gRPC
rejected at init with `NotImplementedError`)
- `OtlpHandler` -- background daemon thread with batched export
- Maps structlog events to OTLP log records via `self.format(record)`
(runs ProcessorFormatter + foreign_pre_chain) with correlation IDs
(request_id, task_id, agent_id) as trace context
- Configurable: endpoint, protocol, headers, export interval, batch
size, timeout
- `SinkType.PROMETHEUS` returns `NullHandler` (pull-based, no log
handler needed)
### Security hardening
- CRLF validation on OTLP headers (header injection prevention)
- SSRF: private/loopback IP rejection on OTLP endpoint
- TLS warning for unencrypted HTTP with auth headers
- `/metrics` always excluded from auth (even with custom
`auth.exclude_paths`)
- Security verdict label cardinality bounded to allow/deny/escalate
### Documentation
- `docs/architecture/acg-glossary.md` -- bidirectional ACG-to-SynthOrg
concept mapping
- `docs/design/operations.md` -- /metrics endpoint (all 9 metric
families with types/labels), OTLP sink, G1 status updated
- `CLAUDE.md` -- metrics event constants, otlp_handler.py logging
exception
## Test plan
- 15,616 tests pass (13 new tests added)
- Unit tests for: MetricsController (200/503 with body assertion),
PrometheusCollector (init, refresh, partial failure, all metric
families, gauge clearing, coordination push, security verdicts with
validation), OtlpHandler (emit, batch-ready, drain, format via
self.format(), gRPC rejection, export failure with mocked urllib,
close-always-drains), build_handler dispatch (PROMETHEUS NullHandler,
OTLP delegation), SinkConfig validation (Prometheus/OTLP fields,
cross-type rejection, batch_size/timeout fields, CRLF headers, SSRF)
## Review coverage
Pre-reviewed by 15 agents, 18 findings addressed. Post-PR reviewed by 14
local agents + 3 external reviewers (CodeRabbit, Copilot, Gemini), 21
additional findings addressed:
- 4 CRITICAL: gRPC rejection, formatter bypass, stale gauges, auth
exclusion
- 8 MAJOR: unused OTEL deps, verdict cardinality, test determinism,
CRLF/SSRF/TLS, setter logs, docs G1 status, budget metric text
- 5 MEDIUM: 503 body assertion, /metrics docs, OTLP constants,
task-by-agent gauge
- 2 MINOR: docstring push/pull model, lock semantics
- 1 INFRA: pre-push hook worker crashes (-n 4 for full-suite runs)
**Deferred to #1148:** daily budget %, per-agent budget, per-agent task
count infrastructure (requires CostTracker time-windowed and per-agent
queries).
Closes #1122
Closes #1124
1 parent a8c1194 commit aaeaae9
23 files changed
Lines changed: 1985 additions & 26 deletions
File tree
- docs
- architecture
- design
- src/synthorg
- api
- controllers
- observability
- events
- tests/unit
- api/controllers
- observability
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
| 91 | + | |
92 | 92 | | |
93 | | - | |
| 93 | + | |
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
0 commit comments