From dd79b4f9fdc633e4409898ce28745e6c8160942e Mon Sep 17 00:00:00 2001 From: Cyril Poder Date: Thu, 26 Nov 2026 00:13:40 +0100 Subject: [PATCH] docs: ADR-0034, observability as the trust surface; the guide stops claiming end-to-end traces The observability guide said "an end-to-end request shows up as a trace across the pipeline". It does not: every span gets a fresh trace id and no parent, so a request that crosses three flows is three unrelated traces in the collector. The guide now says so, and says the cost of the OTLP exporter and of the event ring has not been measured separately. ADR-0034 (Proposed) decides how the claim becomes true: a W3C traceparent in NATS headers on every publish and consume, parent spans per hop, a hardened hand-rolled exporter, a transport test T6 against a stub collector, then a bounded VEJAS_TRACES stream and a panel view that links each hop to its flow version, promote record, proposal and replay diff. Written on 2026-10-24 and left uncommitted since; the measured state was re-read on v0.6.0 before this commit (the bus moved to async-nats behind core/src/bus.rs, nothing else in the table changed). Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 8 + docs/ROADMAP.md | 5 +- ...0034-observability-as-the-trust-surface.md | 260 ++++++++++++++++++ docs/adr/README.md | 1 + docs/book/src/guides/observability.md | 18 +- 5 files changed, 285 insertions(+), 7 deletions(-) create mode 100644 docs/adr/0034-observability-as-the-trust-surface.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b3038a..7603eb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,14 @@ is `0`, minor versions may carry breaking changes — they are called out here. ## [Unreleased] +### Corrected +- The observability guide said an end-to-end request shows up as a trace across the + pipeline. It does not: every span carries a fresh trace id and no parent, so a + request that crosses three flows is three unrelated traces in the collector. The + guide now says so, and says the cost of the OTLP exporter and of the event ring has + not been measured separately. ADR-0034 (Proposed) decides how one trace per event + gets built; the guide will claim it once its CI test passes. + ### Security - **url 2.5.8 → 2.5.9** in the runtime and in the `mq` and `amqp` connectors, for RUSTSEC-2026-0592 (stack overflow in `Url::origin()` on nested `blob:` URLs). diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index db1a935..76ed5e6 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -76,7 +76,10 @@ What turns "nice project" into "I can run this in production": re-injected explicitly after the fix. The sister loop of ADR-0005. 2. **Real observability** · built (ADR-0016): OTLP/HTTP-JSON traces + a Prometheus `/metrics` endpoint, hand-rolled to keep the footprint. The - manifesto claims it again now that it ships. + manifesto claims it again now that it ships. Every span is still its own + trace: one trace per event across hops, and an end-to-end view in the + panel that links each hop to its version, approval and replay evidence, + is ADR-0034 (proposed, not built). 3. **Full shadow-replay** · built (ADR-0018): JetStream-hydrated history, promote audit trail (git + `VEJAS_AUDIT`), forward-only rollback. 4. **Published, reproducible benchmarks**: throughput, memory, image size, diff --git a/docs/adr/0034-observability-as-the-trust-surface.md b/docs/adr/0034-observability-as-the-trust-surface.md new file mode 100644 index 0000000..8032e29 --- /dev/null +++ b/docs/adr/0034-observability-as-the-trust-surface.md @@ -0,0 +1,260 @@ +# 0034 — Observability as the trust surface + +- Status: Proposed (founder-directed, 2026-10-24; nothing built yet. The guide + correction in point 12 ships with this ADR) +- Date: 2026-10-24; measured state re-read on v0.6.0 on 2026-11-26 + +## Context + +Flows are written by agents and promoted under governance (ADR-0001, ADR-0024). +The person who operates a cell did not write the flow and often will not read +it. Their distrust is specific. For one event they want two answers on one +screen: what did the flow do with it, and who changed that flow, in which +version, with what evidence before the change went live. The runtime already +holds the data for both answers. It shows neither as one picture. + +A per-execution view is the entry ticket of the category: n8n shows every +node's input and output for a run, Temporal keeps an event history per +workflow, Kestra draws a timeline per execution. Exporting traces to an +OpenTelemetry collector is expected of any runtime that calls itself operable. +This ADR treats both as table stakes. What no tool in the category shows is the +link between what a run did and who changed the code that ran, because none of +them holds versioning, approval and replay evidence in the same place. Vejas +holds all three (ADR-0018, ADR-0021, ADR-0024). The decision below makes that +link visible on a real event. + +### The measured state (re-read 2026-11-26 on v0.6.0, master at `ef48a1f`; first measured on v0.3.6) + +| Element | State | Where | +|---|---|---| +| OTLP spans | one span per processed event, `SPAN_KIND_CONSUMER`, a fresh random `traceId` and `spanId` on every span, no `parentSpanId` | `core/src/metrics.rs`, `otlp_payload` | +| W3C trace context | `traceparent` / `tracestate`: 0 occurrences in `core/src` and `connectors/` | `grep -rn traceparent core/src connectors` | +| NATS headers on emit | none; since v0.5.0 every publish goes through `Bus::publish` or a confirmed `Batch`, in the one module that talks to async-nats (ADR-0035); neither takes headers, although async-nats offers `publish_with_headers` and `Message.headers` | `core/src/bus.rs` | +| Span attributes | `service.name`, `vejas.unit`, `messaging.destination.name`, `vejas.emits`, `error.message` | `metrics.rs`, `otlp_payload` | +| Flow version in traces | absent; `flow_version` is computed per unit and only tags dead letters | `main.rs`, the consumer loop: `flow_version` goes to `connectors::to_dlq` only | +| Statement-level detail | none; `exec_block` has no observer hook | `core/src/vjs.rs`, `exec_block` | +| Event ring | last 50 per unit, in memory, lost on restart; fields `seq, ts, flow, subject, ok, error, emits, preview, response, event` | `main.rs`, the per-flow ring | +| Exporter loss | `try_send` drops spans when the queue of 4 096 is full; no counter says how many | `metrics.rs`, the exporter thread: `sync_channel(4096)`, `try_send` | +| OTLP wire | HTTP JSON only; no auth headers, no retry, no sampling | `metrics.rs`, the exporter thread | +| OTLP metrics and logs | none; metrics are Prometheus pull only | ADR-0016 | +| Panel | no trace view; a Recent events card refreshed every 4 s | `core/src/panel.html` | +| CI | no test runs a collector; the transport suite boots nats and the runtime only | `e2e/transport/run.sh` | +| Docs | the guide said "an end-to-end request shows up as a trace across the pipeline" | `docs/book/src/guides/observability.md:35`, corrected with this ADR | + +ADR-0016 named the seam honestly: "a richer trace context (parent spans across +a multi-hop flow)" is the extension point of the `metrics` module. The guide +went further than the code. That broke the cross-cutting rule of the ROADMAP +(no promise the code cannot keep) and guardrail R7 of ADR-0029 (trust is +pre-earned). The sentence is corrected in the same change as this ADR. The +capability is decided below and will be claimed in the docs only once its CI +test is green. + +### What the view can link, as it exists today + +- `VEJAS_AUDIT` (ADR-0018) records a promote as `{ts, actor, unit, file, name, + key, before, after}` and a proposal decision as `{ts, actor, kind, proposal, + applied}`. +- `VEJAS_VERSIONS` (ADR-0021) holds the content snapshot and its FNV-1a hash + per flow, with the git baseline it forked from. +- `VEJAS_PROPOSALS` (ADR-0024) holds `{id, kind, payload, author, baseline, + evidence, status, decided_by, decided_at}`. +- Shadow replay (ADR-0018) produces a before/after diff on persisted events. +- Git holds the deployed versions. + +Today these are four endpoints and three panel cards. None of them starts from +an event. + +## Decision + +Two lots, twelve points. Each point names its test; a point is "built" when +that test is green. The constraints of ADR-0002 (NATS is the only +infrastructure), ADR-0016 (hand-rolled, no `opentelemetry` crate tree) and the +MANIFESTO (the monitoring screen draws nothing) hold throughout. + +### Lot A: one trace per business event + +1. **Trace context travels in NATS headers.** A message entering at a source + gets a trace id; every hop that follows carries it. The context is a W3C + `traceparent` header (`tracestate` is passed through unchanged) set on every + publish the runtime makes (flow emits, tick emits, confirmed batches) and + read on every consumed message. Since ADR-0035 all of them go through + `core/src/bus.rs`, so the header is written and read in that one module. + An `api` flow reads `traceparent` from the HTTP request; the HTTP + connectors inject it on outgoing requests. A message + that arrives without the header starts a new trace, so foreign producers + keep working unchanged, and a foreign consumer sees a header it can ignore. + The payload is untouched, so the at-least-once contract of ADR-0002 is not + affected. NATS headers need server 2.2 or later, which JetStream already + requires. + +2. **Spans have parents.** Per hop: one span for the flow run (kind + `CONSUMER`, parent = the producer's span id from the header), one child + span per `invoke` (kind `INTERNAL`), per emit (kind `PRODUCER`) and per + connector call (kind `CLIENT`), and one span for the sink hop. Assignments + do not get spans: they are sub-microsecond and would multiply the volume for + nothing. Their detail belongs to the local hop record of point 8. + +3. **Attributes follow the OpenTelemetry semantic conventions** where one + exists, at the version current when built: `messaging.system = nats`, + `messaging.destination.name`, `messaging.operation.type`, + `messaging.message.id` (the JetStream sequence), `code.file.path` and + `code.line.number` on invoke and emit spans, `error.type`, `error.message`. + Vejas-specific attributes: `vejas.unit`, `vejas.flow.version` (the content + hash of ADR-0021), `vejas.flow.baseline` (the git baseline when the version + is an overlay), `vejas.delivery.attempt`, `vejas.dlq = true` on a + dead-lettered run. The version hash is the join key to provenance; the + exporter does not look provenance up, the view does (point 10). + +4. **The exporter is hardened, still hand-rolled.** `OTEL_EXPORTER_OTLP_HEADERS` + for the hosted backends that need a token; `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` + with the precedence the specification gives it; HTTPS through the `ureq` + TLS already linked; bounded retry with backoff on connection errors, 429 and + 5xx; sampling via `OTEL_TRACES_SAMPLER=parentbased_traceidratio` and + `OTEL_TRACES_SAMPLER_ARG`, the decision taken at the entry hop and carried in + the `sampled` flag so every hop agrees; errors and dead letters are always + exported whatever the ratio. A counter `vejas_spans_dropped_total{reason}` + (`queue_full`, `export_failed`) on `/metrics` makes loss visible. The wire + stays OTLP/HTTP JSON; the Collector accepts it and protobuf adds nothing + here. + +5. **The proof is a transport-level test.** `e2e/transport/run.sh` gains + scenario T6: a three-hop chain (source flow, middle flow, sink) under a stub + collector that is part of the test (a small HTTP listener writing what it + receives to a file). It asserts that every span produced for one input event + carries the same trace id, that parent ids chain across the three hops, that + an incoming `traceparent` on an `api` request is honoured, and that + `vejas_spans_dropped_total` is 0 at the end. It runs in CI with T1–T5. A + Collector configuration and a Grafana dashboard (traces waterfall plus the + `/metrics` series) ship in the repo so an operator sees something within + minutes of pointing a collector at a cell. + +6. **The cost is measured, not claimed.** `bench/flow-only.sh` runs before and + after, with the exporter unset (must stay at zero cost, as ADR-0016 + promises) and set against a local collector. The numbers go to the + benchmarks page. The hot path keeps the ADR-0016 property: it never blocks + on the collector. + +### Lot B: the end-to-end view in the default panel + +7. **Traces persist in NATS, nothing else.** A dedicated JetStream stream, + `VEJAS_TRACES`, bounded by age, message count and bytes like the DLQ and + audit streams, holds one message per hop. The subject carries the trace id + as a token, so one filtered consumer returns every hop of a trace without + any index outside NATS. The memory cost of that subject index on the server + is measured in the bench before the default limits are set; if it measures + too high, the fallback is a KV bucket mapping trace id to stream sequences. + Under load the same sampling decision as the exporter applies, errors and + dead letters always kept. The in-memory ring and `GET /events` stay as the + zero-dependency fallback and keep their shape. + +8. **The hop record is richer than the span.** Per hop it records the unit, + the flow version and its baseline, the delivery attempt, the statements + executed with a snapshot of the pipeline (the flow's variables) at each + `invoke`, `emit` and `respond` boundary, the emits, the downstream answer + for a sink, and the DLQ verdict when there is one. The snapshot passes + through the credential mask that already guards the panel + (`secrets::SECRET_KEY_PATTERN`, one definition shared with the admission + lint), and a value resolved from the vault is never written to a record. + That second rule gets its own test. The boundary snapshot is one JSON walk + per boundary; its cost is part of the measurement of point 6. + +9. **The screen is the monitoring screen the MANIFESTO allows.** Entry by + trace id, by subject, or from a row of Recent events; then the path hop by + hop; for each hop the unit, the flow version, the statements executed with + the pipeline at each boundary, the emits, the downstream answer, the DLQ + verdict and the attempt count; and the existing replay actions (DLQ replay, + shadow replay), nothing new to write. The statement-level rendering is the + read-only projection doctrine of ADR-0019 applied to the whole flow body, + fed by the hop record; that projection gets its own ADR. The screen edits + nothing. The same data is an MCP tool, `vejas_trace`, so an agent asked + "what happened to order 4711" answers with the record rather than with a + guess (ADR-0006). + +10. **Provenance sits on the same screen.** For each hop, the flow version + links to the `VEJAS_VERSIONS` snapshot or the git baseline that produced + it; to the `VEJAS_AUDIT` promote record (actor, before, after); to the + proposal (author, evidence, decided by, decided at) when the change went + through the queue; and to the shadow-replay diff recorded with the + promotion. The join key is the version hash. Today the promote record and + the proposal decision do not carry the resulting content hash; this point + adds it to both records. The operator reads, on one event: this version, + written by this author, approved by this person, replayed on these events + with this diff before promotion. + +11. **Open-core placement.** Everything above is in the free runtime: the + headers, the spans, the exporter, the stream, the screen and the MCP tool. + ADR-0028 puts the line at fleet, identity and export, and this is + monitoring of one cell. The enterprise seams of ADR-0030 attach where they + already do: the SIEM export reads `VEJAS_TRACES` next to `VEJAS_AUDIT`, the + fleet console shows traces across cells. + +12. **Documentation discipline.** The guide sentence is corrected with this + ADR: today every span is its own trace. The guide claims end-to-end traces + only when T6 is green, and the ROADMAP points here from Phase 5. + +## Consequences + +- The guide is honest today. The "future extension" of ADR-0016 has a design + and a test instead of a sentence. +- The operator's two questions get one answer on one screen, and an agent gets + the same answer over MCP. This is the first place where the governance + machinery of ADR-0018, ADR-0021 and ADR-0024 is visible on a real event, + which is the argument the MANIFESTO makes to a buyer who distrusts + agent-written code. +- A new bounded stream per cell, and a subject index whose server-side memory + is a function of retention. Defaults are set from the measurement of point 7, + not guessed; a cell on a small box keeps them small. +- Hop records carry business payloads. They inherit the retention concerns of + the DLQ and the audit stream; the key-pattern mask is a filter on names, not + a classifier of values, so a secret stored under an unremarkable name would + pass it. The never-record rule for vault values closes the known hole; the + mask's limits stay documented. +- A sampled-out trace that fails late is kept locally in full (errors are + always kept) but its ancestors are missing in the collector. Head sampling + has this limit; it is stated rather than hidden. +- The interpreter gains a per-statement branch for the boundary snapshot. If + the measurement of point 6 shows a cost above noise with the exporter unset, + the snapshot becomes opt-in per flow rather than silently accepted. +- Rolling upgrades are safe: a runtime from before this ADR ignores the header + and keeps processing; a runtime after it starts new traces for messages + without one. +- Volume at the exporter grows from one span per hop to one plus the number of + invokes, emits and connector calls. The queue and batch sizes of ADR-0016 + are re-checked under the bench load; the drop counter makes the limit a + number rather than a silence. +- Not decided here: OTLP logs (stderr stays the log), OTLP metrics (Prometheus + pull stays; a Collector scrapes it), a protobuf wire, and any editing of a + flow from the trace screen. + +Rough sizing, in working sessions, to be corrected by reality: + +| Lot | Points | Sessions | +|---|---|---| +| A: context propagation, parent spans, T6 | 1, 2, 3, 5 | 2 | +| A: exporter hardening and the cost measurement | 4, 6 | 1 | +| B: stream, hop record, screen, MCP tool | 7, 8, 9 | 3 to 4 | +| B: provenance links and the hash on audit records | 10 | 1 | + +## Alternatives considered + +- **The `opentelemetry` crate stack.** Rejected for the reasons of ADR-0016, + which have not changed: the OTLP exporter in that stack drags an async + runtime and tens of megabytes behind it, and what is missing here is a W3C + header, a parent id and a handful of environment variables. +- **Trace context inside the payload** (an envelope field). Rejected: it would + change the event every flow sees and every foreign consumer receives. A NATS + header is invisible to anyone who does not ask for it. +- **The collector's own UI as the only view** (Jaeger, Tempo, a hosted + backend). Rejected as the only option, kept as the complement: the view must + work with NATS alone (ADR-0002), and no collector can show provenance since + it does not hold the audit stream, the proposals or the replay diffs. The + collector remains the right place for long retention and cross-service + search. +- **Per-assignment spans.** Rejected on volume. Statement detail lives in the + hop record at boundaries. +- **Growing the in-memory ring** instead of a stream. Rejected: ADR-0018 + already moved replay hydration to JetStream because the ring is small, + recency-clipped and lost on restart. The same reasons apply to traces. +- **A separate observability product or sidecar.** Rejected: one binary, one + bus, one screen is the point of the platform (MANIFESTO), and a sidecar + would reopen the footprint question ADR-0016 closed. diff --git a/docs/adr/README.md b/docs/adr/README.md index b0ed8af..61057ff 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -42,6 +42,7 @@ the old one. | [0029](0029-failure-mode-guardrails.md) | The failure-mode guardrails | Accepted | | [0030](0030-enterprise-repo-architecture.md) | How the enterprise tier attaches: seams, not plugins | Proposed | | [0031](0031-pattern-detection-unit-varpulis-engine.md) | Pattern detection as a unit type: the Varpulis engine embedded | Proposed | +| [0034](0034-observability-as-the-trust-surface.md) | Observability as the trust surface: one trace per event, an end-to-end view with provenance | Proposed | | [0035](0035-async-nats-bus-island.md) | The NATS client moves to async-nats, behind one synchronous module | Accepted | | [0036](0036-integration-agent-separate-binary.md) | The integration agent is a separate binary, a client of `/mcp` | Accepted, not built | diff --git a/docs/book/src/guides/observability.md b/docs/book/src/guides/observability.md index 9f1799f..4ff18fe 100644 --- a/docs/book/src/guides/observability.md +++ b/docs/book/src/guides/observability.md @@ -31,8 +31,13 @@ OTEL_SERVICE_NAME=vejas # optional label ``` Unset, it is a genuine no-op — no exporter thread, no overhead. Each flow -execution becomes a span (subject, ok/error, emit count, timing), so an -end-to-end request shows up as a trace across the pipeline. +execution becomes one span (subject, ok/error, emit count, timing). + +Today every span is its own trace. The runtime does not yet propagate a +trace context across hops, so a request that crosses three flows shows up in +the collector as three unrelated traces, correlated by time and subject only. +One trace per business event, with parent spans across hops, is decided in +ADR-0034 and will be claimed here once its CI test is green. ## The event ring — what just happened @@ -53,7 +58,8 @@ landed. - Anything that *failed* past its retries is not lost — it is parked with a verdict in the [DLQ](dlq-replay.md), which is its own inspectable surface. -Everything here is a read; none of it changes what runs. The performance -cost of all three, measured, is in the [benchmarks](../reference/benchmarks.md) -— the hot path stays a few-MB, few-thousand-per-second runtime with the -windows open. +Everything here is a read; none of it changes what runs. The +[benchmarks](../reference/benchmarks.md) are taken with metrics on, since the +counters cannot be switched off, so their numbers include that cost. The cost +of the OTLP exporter and of the event ring has not been measured separately +yet; ADR-0034 adds that measurement.