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 increasingattemptordinals; recordattempt = kcarries the k−1 prior failed tries inoutcome.retries, so the Task 7 invariantattempt == retries.len() + 1holds for every record. Non-final attempts carry a typedProviderFailedterminal describing that attempt’s own failure; the final record carries the request’s terminal outcome (Completed,Canceled, orProviderFailed). 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 itsWriterTraceSinkwhen telemetry is Basic/Full. The default sink is a no-op; tests installCollectingTraceSink.
No hidden global mutable state: all shared state (lazy key cell,
counters, sequence) lives inside the TraceContext handle the caller
owns and clones.
Structs§
- Attempt
Clock - Monotonic (
Instant-based) timing capture for one transport attempt. Every mark is set-once; unobserved stages stayNone(never zero). - Collecting
Trace Sink - In-memory collector for deterministic tests.
- Noop
Trace Sink - Disabled sink: accepts and discards.
enabled() == falselets transports skip all trace work. Production installs the Task 11 writer-backed sink (runtime::telemetry::WriterTraceSink) instead when the telemetry level warrants persistence. - Request
Correlation - Request
Structure - Structural, metadata-only description of one outgoing request, built by a
transport-specific helper (see
trace::anthropic) from trusted inputs — includingWireMetacomputed from the exact bytes handed to reqwest. - Request
Tracer - Builds and emits one record per actual transport attempt (see module docs for the record rule). Owned by a single request; not shared.
- Trace
Context - Cloneable handle carrying the sink, the lazily-loaded digest key, the session identity, and metadata-only degradation counters.
Traits§
- Trace
Sink - 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
WireMetaused by transports — there is no re-serialization path.