Skip to content

Latest commit

 

History

History
181 lines (139 loc) · 8.72 KB

observability-technical.md

File metadata and controls

181 lines (139 loc) · 8.72 KB

Observability — Technical Depth

Technical depth

Concept: Observability.

This companion carries the exact emission inventory, the trace session's configuration domain and ceilings, the redaction rules by name, the module that enforces each.

The Emission Inventory

Concept: Observability.

Accepted ADR 0030 fixes this set exactly. Every name emits start, stop and exception. Adding a name, removing one, or emitting a second span from one boundary is an ADR amendment, not an implementation choice.

Five port callbacks:

Port Event names
Model [:loopex, :model, :complete]
Store [:loopex, :store, :transact], :transaction_status, :runtime_command, :ownership_head, :load_records, :load_events
Artifact store [:loopex, :artifact, :put], :fetch, :stat, :describe, :open_transfer, :read_transfer, :close_transfer
Executor [:loopex, :executor, :execute], :cancel, :retained_receipt
Policy [:loopex, :policy, :decide]

Six coordinator transaction cuts:

[:loopex, :command, :admit], [:loopex, :commit], [:loopex, :effect, :intent], [:loopex, :events, :publish], [:loopex, :interaction], [:loopex, :artifact, :transfer].

Loopex.Instrumentation Is the Only Place a Span Opens

Concept: Why core emits and the edge handles.

Every emission goes through Loopex.Instrumentation. There is no second path, and that is enforced by review rather than by a compiler, so a change that emits :telemetry.execute/3 directly is a defect however correct its metadata looks.

Two shapes exist:

  • span/4 wraps work whose lifetime is one call. It classifies the result through a per-boundary classifier rather than a generic one, because a generic classifier flattens every domain result to :other and the outcome is the point of the span.
  • open_span/2 and close_span/4 cover a lifetime that spans several calls — the interaction and transfer cuts, where the work begins in one message and ends in another.

The library's own :telemetry.span/3 is not used. Its exception path attaches kind, reason and stacktrace to the event metadata, which carries exactly the content ADR 0030 excludes. The exception path here emits directly and attaches an error class only:

defp error_class(:error, %{__struct__: module}), do: inspect(module)
defp error_class(:error, reason) when is_atom(reason), do: inspect(reason)
defp error_class(kind, _reason), do: Atom.to_string(kind)

The original is re-raised with its own stacktrace, so instrumentation is invisible to error handling.

The Edge Handler

Concept: Why core emits and the edge handles.

Loopex.Telemetry in loopex_telemetry is the only Loopex-attached handler.

  • attach/1 reads the runtime's diagnostics admission handle once and attaches with :telemetry.attach_many/4. The handler identity carries the runtime reference, so attaching twice for one runtime is idempotent and two runtimes in one VM never collide.
  • The handle is plain data, read at attach time rather than per event, so a runtime whose dispatcher restarts gets a fresh attachment rather than a handler holding a dead table.
  • The handler performs no I/O, never calls the synchronous host-facing diagnostic entry, and never blocks on a sink. Anything it cannot express as bounded plain data it drops.

Trace Session Domain

Concept: Neither is truth, and neither is authority.

Concept: Everything is bounded, and says so when it bounds.

Loopex.Trace.Config.validate/1 is the whole domain. A supplied value is accepted when it is positive and no larger than the ceiling, and refused by name otherwise.

Field Domain Default
modules Exact module names, or wildcards over :loopex and :loopex_protocol only both namespaces
level :calls, :returns, :arguments :calls
limits.entry_bytes 1 … 4,096 4,096
limits.entries_per_second 1 … 2,000 2,000
limits.queued 1 … 8,192 8,192
sink :diagnostics, :logger :diagnostics

Wildcards exist only over the two Loopex namespaces. A wildcard over anything else would let a session observe code the runtime does not own; an adapter is traced by naming its module exactly.

Loopex.Trace is an OTP 27 trace session, so it coexists with other tracers and is destroyed as a unit. Processes are flagged from the runtime's supervisor with set_on_spawn, so a coordinator started later is covered and a process the runtime does not own never is. The tracer is the only consumer of raw trace messages, applies ceilings before anything reaches a sink, never calls into a traced process and never replies to one.

Match specs by level: :calls sends the caller; :returns and :arguments add the return trace; :arguments drops the :arity flag so argument terms arrive.

Call patterns are installed with trace:function/4 when the session starts, and OTP installs them only for loaded modules, so the session first calls Code.ensure_loaded/1 on every module it names, the namespace wildcards included. That loads installed code from the code path, as the Store and executor boundaries already do when they probe an adapter; it never creates a code generation, which stays the VM generation manager's alone. A name that no installed module answers to traces nothing. A module installed on the code path but not yet loaded is therefore traced once a session names it.

Exclusion. Loopex.Trace.exclude_self/2 takes a host-bound capability (Loopex.Trace.Capability.Handle, bound once per runtime) and the exact {module, function, arity} list that can carry sensitive data. Control records the caller in a monitored excluded-process set and adds the functions to a ref-counted union with no fixed ceiling; the active session clears the caller's flags and those match specs, and the call returns only after an OTP trace-delivery barrier. A session started later applies the retained set. When the excluded process exits, its whole contribution is removed. Two ReqLLM callers use it: the durable profile's credential sender excludes itself before it receives any credential context, and the ephemeral profile's sensitive in-VM provider caller excludes itself before its provider call; each refuses the call if exclusion is unavailable. Trace keeps the full OTP session handle in private ETS so neither crash output nor status formatting carries it, and a replacement tracer recreates an active session from Control's retained metadata.

Trace sessions cover only runtime-owned processes. A host's own processes — the daemon's listener, connections and lease owners — are not flagged and are not claimed as trace-session witnesses.

Redaction Rules

Concept: Redaction is a contract, not a filter.

Loopex.Trace.Entry.redact/1 walks the term before rendering.

Trigger Result
Key matches credential|secret|token|api[_-]?key|password|authorization (case-insensitive) credential placeholder
Key in messages canonical_request_bytes text tool_calls arguments argument result results content contents data bytes payload body chunk content placeholder
Binary longer than 64 bytes bytes placeholder
Nesting deeper than 6 depth placeholder
List longer than 32 elements the first 32 elements, then one list placeholder for the rest
Map or tuple with more than 32 members map or tuple placeholder
Pid, port, reference or function opaque placeholder

A placeholder carries the byte size and the lowercase SHA-256 digest of the deterministic external-term encoding of what it replaced. The rendered form is then truncated to entry_bytes with a ... marker, so an entry is bounded however deep or wide the term was.

The tests that prove each claim on this page are listed in the verification guide.

Related

Back to the developer index.