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_jsonlbuilds aSpanTreefrom a possibly truncated, hostile or huge JSON lines file;render_terminalandrender_htmlshow 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 intoValue. - 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 disabledSpan.
Structs§
- Callback
Sink - 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 withenterorin_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_scopeandCtx::in_scope. - Jsonl
Options - Settings for
JsonlSink. Defaults: refuse an existing file, stop at 256 MiB with onetruncatedrecord inside the limit, flush every 64 records. Input:with_*setters. Output: passed toJsonlSink::with_options. - Jsonl
Sink - 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.
- Memory
Sink - 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 anddropped(). - Span
- A span guard: writes a
startrecord when opened and anendrecord when dropped. A span opened outside any scope, or for a category that is off, is disabled and every method on it does nothing. - Trace
Set - A set of trace categories stored as one bit per category.
Input: categories through
withorFromIterator. Output:contains.bitsandfrom_bitsround-trip it for storage without serde. - Trace
Spec - 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 insideenterorin_scope. - Tracer
Builder - 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, nametrace.
Enums§
- Trace
- One trace category; every trace point belongs to exactly one.
as_strgives the snake-case name used in JSON lines and TOML, andFromStrparses it back. Later releases may add categories. - Trace
Error - 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.
Contentholds user text (prompts, replies, queries) and is written only when the scope keeps content; otherwise only its byte count.
Traits§
- Trace
Sink - 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
textas user content, withheld unless the scope keeps content. Input: the text. Output: aValue::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_DIRor./traces, file<name>-<trace id>.jsonl. Bytes ofnameoutside[a-z0-9_-]become_; the name is cut to 64 bytes, empty istrace. - enabled
- Returns whether a point of category
trecords anything here. One relaxed atomic load and a bit test when no live tracer hast; 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
urlwith 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.