TraceGuard.TraceBuilder (trace_guard v0.1.0)

Copy Markdown View Source

Internal module. Not part of TraceGuard's public API: it may change in any release. Use the functions in TraceGuard instead.

Turns a finished TraceGuard.Context into a diagnostic report.

The pipeline is fixed and runs entirely in the request process when the request completes:

  1. Order events by time (see "Timestamps" in TraceGuard.EventCollector), then by sequence number.
  2. Convert monotonic timestamps into microsecond offsets from the start of the request.
  3. Sanitize every value into a JSON-safe term: strings are truncated, structs, PIDs, references, functions and tuples are replaced by descriptive placeholders, and atom keys become strings.
  4. Redact sensitive keys recursively and scrub the exception message.

Only the result of step 4 ever leaves this module, so nothing unredacted is stored or exported. The report structure is documented in docs/architecture.md and TraceGuard.report().

Summary

Functions

Builds the redacted, JSON-safe report for a completed request.

Builds a failure description from a caught kind/reason/stacktrace.

Functions

build(ctx, status, config)

@spec build(TraceGuard.Context.t(), integer() | nil, TraceGuard.Config.t()) :: map()

Builds the redacted, JSON-safe report for a completed request.

status is the final HTTP status (or nil when unknown).

failure(kind, wrapper, stacktrace, source, config)

@spec failure(
  atom(),
  term(),
  Exception.stacktrace(),
  String.t(),
  TraceGuard.Config.t()
) :: map()

Builds a failure description from a caught kind/reason/stacktrace.

The raw exception is reduced immediately to plain data: module name, message, HTTP status mapping and a stacktrace without function arguments. Message scrubbing and truncation happen later, in build/3.