Skip to main content

Module emit

Module emit 

Source
Expand description

Trace emission seam (Task 8, spec §6.2/§6.4).

Transports hand fully-built, schema-valid RequestTrace records to a TraceSink. The seam is deliberately tiny:

  • Record rule (documented invariant): one record is emitted per actual transport attempt (one HTTP send). A request that is retried N times therefore yields N+1 records sharing the same request_id, with strictly increasing attempt ordinals; record attempt = k carries the k−1 prior failed tries in outcome.retries, so the Task 7 invariant attempt == retries.len() + 1 holds for every record. Non-final attempts carry a typed ProviderFailed terminal describing that attempt’s own failure; the final record carries the request’s terminal outcome (Completed, Canceled, or ProviderFailed). A cancellation observed between attempts (during backoff sleep, when no send is in flight) emits no extra record — the preceding failed attempt was already recorded.
  • Correctness firewall: nothing in this module can fail a request. Key I/O failure degrades the record (digest-bearing sections omitted) and bumps a metadata-only counter + one warning; it never propagates.
  • No persistence here: persistence lives in the Task 11 bounded background writer (runtime::telemetry::writer); production installs its WriterTraceSink when telemetry is Basic/Full. The default sink is a no-op; tests install CollectingTraceSink.

No hidden global mutable state: all shared state (lazy key cell, counters, sequence) lives inside the TraceContext handle the caller owns and clones.

Structs§

AttemptClock
Monotonic (Instant-based) timing capture for one transport attempt. Every mark is set-once; unobserved stages stay None (never zero).
CollectingTraceSink
In-memory collector for deterministic tests.
NoopTraceSink
Disabled sink: accepts and discards. enabled() == false lets transports skip all trace work. Production installs the Task 11 writer-backed sink (runtime::telemetry::WriterTraceSink) instead when the telemetry level warrants persistence.
RequestCorrelation
RequestStructure
Structural, metadata-only description of one outgoing request, built by a transport-specific helper (see trace::anthropic) from trusted inputs — including WireMeta computed from the exact bytes handed to reqwest.
RequestTracer
Builds and emits one record per actual transport attempt (see module docs for the record rule). Owned by a single request; not shared.
TraceContext
Cloneable handle carrying the sink, the lazily-loaded digest key, the session identity, and metadata-only degradation counters.

Traits§

TraceSink
Receives finished trace records. Implementations must be cheap and non-blocking: they run inline on the request path.

Functions§

wire_meta_from_sent_bytes
Compute exact-wire metadata from the very byte buffer handed to the transport. This is the ONLY constructor for WireMeta used by transports — there is no re-serialization path.