Skip to content

runtime: one trace per business event (ADR-0034 lot A) - #44

Merged
cpoder merged 3 commits into
masterfrom
feat/trace-propagation
Nov 26, 2026
Merged

cpoder merged 3 commits into
masterfrom
feat/trace-propagation

Conversation

@cpoder

@cpoder cpoder commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Every event the runtime lets in now gets one trace, from the source or webhook through each flow and invoke to the sink. ADR-0034 lot A asked for exactly this (points 1 to 6, plus point 12).

What changes for an operator

  • One trace per event. A W3C traceparent travels in a NATS header on every publish, so the spans of an event have parent links. The payload is untouched.

  • Traces cross the edges of the cell.

    • http-in and api flows continue a caller's trace, and http-in answers with the trace_id.
    • http-out and slack-out send traceparent downstream. An exec sink gets TRACEPARENT and TRACESTATE in its environment.
    • A dead letter keeps its trace, and a DLQ replay continues it. The dead-lettered event carries the trace id, and so does each entry of the event ring.
  • The exporter reads the standard OTEL_* variables:

    • traces endpoint, headers (never logged), timeout and resource attributes;
    • the six samplers, with errors and dead letters always exported;
    • batching through OTEL_BSP_*.

    It also retries 429, 502, 503 and 504 with Retry-After, flushes its queue on a graceful stop, and exposes two counters: vejas_spans_exported_total and vejas_spans_dropped_total{reason}.

  • Span shape changes. The kind now says what the hop was: SERVER, PRODUCER, CONSUMER, CLIENT or INTERNAL. The OpenTelemetry semantic-convention attributes are added, and so is vejas.flow.version. A successful span now has an unset status. All of this is in the CHANGELOG under Changed.

How it is proven

Transport test T6 (e2e/transport/run.sh) runs against a stub collector and checks:

  • http-in → flow → invoke → flow → http-out, with a caller's traceparent, as one trace whose parents chain all the way to the sink's HTTP call;
  • the same chain with no header from the caller;
  • an api flow called with a TraceParent header (mixed case);
  • a caller that sampled its trace out: no span is exported, and the flag reaches the sink;
  • no span dropped, and the trace id visible in the event ring;
  • a graceful stop flushing the last event's spans. Without the flush, this case fails: all five spans go missing.

Other checks:

  • Mutation check: emptying the propagation headers fails 4 cases.
  • Unit tests cover parsing, ids, the sampler, header lookup, the JSON writer (escaping) and the OTEL_* reading.
  • Real Jaeger 2.23.0 rebuilt the 5-span trace with the right references and kinds.
  • Every other e2e suite and connector admission pass locally against the release binary.

Cost

Measured with the new bench/trace-cost.sh on the isolated flow hop: 20 000 events, median of 5 runs, runtime CPU per event.

Configuration CPU per event
Before tracing 72.5 µs
Propagation only, no exporter about +3 µs (1.5 to 4.5 over four series)
Every span exported +10.5 µs
One trace in ten exported +4 µs

Throughput stays within 2.5 %. The 200 000 exported spans all arrived. Along the way, two fixes brought export from 63 µs of CPU per event down to about 9 µs:

  • batching as the OpenTelemetry SDKs do, and writing the JSON directly;
  • not waking the export thread for every span.

bench/README.md has the full table.

Departures from the ADR text

They are recorded in ADR-0034 under "What is built":

  • no span per emit, and no second CLIENT span inside a sink hop;
  • spans are named after their unit;
  • no code.line.number (the AST has no line numbers yet);
  • the context travels even without an exporter, which is why that case has a cost.

Not built:

  • the Collector config and Grafana dashboard (the guide gives a one-line Jaeger instead);
  • traceparent on the poll sources' GETs;
  • MQTT (no headers before v5);
  • exec-rpc.

Lot B (the panel view, the VEJAS_TRACES stream, the vejas_trace MCP tool) is next.

Fixed after a first CI run and an independent review

  • bus.rs had gained use crate::trace. That broke the AMQP connector, which compiles bus.rs as it is. The bus now takes a trace through a two-method trait, and parsing stays in trace.rs. Both connectors check again.
  • An exporter header that HTTP cannot carry made every export fail with an error that quoted the whole header line into the log. Such entries are now skipped at start, with a warning that only gives their position. Only network errors are retried.
  • The startup line no longer prints the endpoint's user info or query.
  • vx.dlq.events forwarded the caller's tracestate. It now keeps only the trace ids.
  • Trace headers count toward max_payload. A message they would push past the limit now goes untraced instead of failing, and the same rule applies to the death envelope's traceparent.

🤖 Generated with Claude Code

https://claude.ai/code/session_018wXgxSSYsPm88PCqu98HPT

cpoder and others added 3 commits November 26, 2026 02:11
The runtime carries a W3C traceparent in a NATS header on every message it
publishes, so the spans of one event form one trace with parent links: the
source or webhook, each flow and invoke, the sink. http-in and api flows
continue a caller's trace; http-out, slack-out and exec sinks pass it on; a
dead letter keeps it and a replay continues it; the event ring shows the
trace id.

The OTLP exporter reads the standard OTEL_* variables (traces endpoint,
headers, timeout, resource attributes, the six samplers, OTEL_BSP_*),
retries what the OTLP specification calls retryable, batches, flushes on a
graceful stop, and counts what it sends and drops on /metrics.

Transport test T6 checks the chain against a stub collector: three entry
cases, an unsampled caller, no span dropped, the event ring, and the flush
on stop. bench/trace-cost.sh measures the cost on the flow hop: about 3 µs
of CPU for propagation, 10.5 µs to export every span, 4 µs at one in ten.

The observability guide now claims end-to-end traces, with that cost, and
ADR-0034 records what was built and where the build departs from its text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018wXgxSSYsPm88PCqu98HPT
… it is

bus.rs had gained `use crate::trace`, which the connectors that compile
core/src/bus.rs through #[path] do not have: the AMQP build failed in CI.
The bus now takes a trace through a two-method trait (the traceparent and
tracestate values) and hands a consumed message's headers back with
Message::header; parsing stays in trace.rs (trace::of). Both connectors
check again, test targets included, and the module says why it must stay
self-contained.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018wXgxSSYsPm88PCqu98HPT
- An exporter header that HTTP cannot carry (a colon for `=`, a control byte)
  made ureq fail every export with an error quoting the whole header line,
  which reached the log once a minute. Such entries are now skipped at start
  with a warning that gives their position only; a transport error prints its
  detail only when it comes from the network, and only network errors are
  retried, so a bad header or URL no longer holds the queue for 3.5 s a batch.
- The startup line printed the endpoint with any user info or query in it;
  it now prints scheme, host and path.
- The vx.dlq.events announcement forwarded the caller's tracestate, text from
  outside, in an event meant to hold only what the runtime wrote. It keeps the
  trace ids only.
- Trace headers count toward max_payload. A message they would push past it
  is now published untraced instead of failing, and a death envelope whose
  traceparent would not fit goes without it: a trace is never the reason a
  message or a letter is lost.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018wXgxSSYsPm88PCqu98HPT
@cpoder
cpoder merged commit 11e45a5 into master Nov 26, 2026
4 checks passed
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.

1 participant