Skip to main content

Crate troupekit_trace

Crate troupekit_trace 

Source
Expand description

Trace spans for every Troupekit crate, with no dependencies. A disabled trace point costs one atomic load and a branch. Records go to sinks as JSON lines; the view module reads them back.

Re-exports§

pub use tracer::current;
pub use tracer::Ctx;
pub use tracer::Instrumented;
pub use tracer::Tracer;
pub use tracer::TracerBuilder;

Modules§

view
Reads trace files back and renders them for people. read_jsonl builds a SpanTree from a possibly truncated, hostile or huge JSON lines file; render_terminal and render_html show it.

Macros§

trace
Writes one point event: trace!(Trace::Laws, "law.check", held = true). Field expressions run only when the category is on in the current scope. Keys are identifiers; values are anything that converts into Value.
trace_span
Opens a span: let span = trace_span!(Trace::Models, "model.call", model = id);. Field expressions run only when the category is on in the current scope; otherwise the macro returns a disabled Span.

Structs§

CallbackSink
Hands every record line to a callback. A panic in the callback is caught, counted and disables the sink, so it never fails the run. Input: lines. Output: calls to the callback.
Ctx
A captured trace scope: a tracer plus the current span id. Get one with current() and re-enter it in a spawned task or a blocking closure with enter or in_scope, so parents stay right.
Instrumented
A future that installs a trace scope on every poll and restores the previous one after, so the scope follows the task across threads. Made by Tracer::in_scope and Ctx::in_scope.
JsonlOptions
Settings for JsonlSink. Defaults: refuse an existing file, stop at 256 MiB with one truncated record inside the limit, flush every 64 records. Input: with_* setters. Output: passed to JsonlSink::with_options.
JsonlSink
Writes record lines to a private JSON lines file. The file is created with mode 0600 and missing folders with 0700 on Unix. I/O errors are counted, never returned to the traced run; a failed record write stops the sink, since its bytes on disk are unknown.
MemorySink
Keeps the newest record lines in memory, dropping the oldest past its capacity (default 100 000 lines) or its byte limit (default 64 MiB), and counting what it dropped. Input: lines. Output: lines() copies and dropped().
Span
A span guard: writes a start record when opened and an end record when dropped. A span opened outside any scope, or for a category that is off, is disabled and every method on it does nothing.
TraceSet
A set of trace categories stored as one bit per category. Input: categories through with or FromIterator. Output: contains. bits and from_bits round-trip it for storage without serde.
TraceSpec
Plain trace settings as written in a persona or workflow file. Input: categories, content flag and an optional file path. Output: getters; the default is every category, no content, no file.
Tracer
A live trace: categories, content flag, scrubbed secrets and one sink. Built with Tracer::builder(). While any clone is alive its categories are switched on, but points record only inside enter or in_scope.
TracerBuilder
Settings for a new Tracer. The trace id is chosen when the builder is made, so a caller can name a file after it before picking the sink. Defaults: every category, content withheld, name trace.

Enums§

Trace
One trace category; every trace point belongs to exactly one. as_str gives the snake-case name used in JSON lines and TOML, and FromStr parses it back. Later releases may add categories.
TraceError
Errors from parsing trace settings or building a tracer. Input: caller settings. Output: one variant naming what was wrong. Later releases may add variants.
Value
One field value of a trace record. Content holds user text (prompts, replies, queries) and is written only when the scope keeps content; otherwise only its byte count.

Traits§

TraceSink
A destination for finished trace record lines. Input: one JSON line per call, without a trailing newline. A sink never returns an error and never panics through the caller.

Functions§

content
Marks text as user content, withheld unless the scope keeps content. Input: the text. Output: a Value::Content.
current
Returns the trace scope current on this thread, if any. Input: none. Output: a clone of the scope, to pass into a spawned task or a blocking closure and re-enter there.
default_trace_path
Returns the default trace file path: $TROUPEKIT_TRACE_DIR or ./traces, file <name>-<trace id>.jsonl. Bytes of name outside [a-z0-9_-] become _; the name is cut to 64 bytes, empty is trace.
enabled
Returns whether a point of category t records anything here. One relaxed atomic load and a bit test when no live tracer has t; otherwise also a check of the current scope on this thread.
live_categories
Returns the union of the categories of every live tracer. Input: none. Output: the set; empty when no tracer is alive.
url_for_trace
Returns url with only scheme, host, port and path: user info, query and fragment are dropped. The text is first cleaned as URL parsers do (C0 controls and spaces trimmed at both ends, tab, LF and CR removed), then reduced until a further pass changes nothing, so no reading of the result holds userinfo. A malformed authority, such as a password cut by /, ? or # before its @, becomes [redacted] with the path dropped. Use it for every URL written to a trace.