Replicant.Telemetry (Replicant v1.2.4)

Copy Markdown View Source

Value-free :telemetry.span/3 wrapper. Owns the metadata AND measurement contracts — the single enforcement point for "no row values in telemetry" (Critical Rule 1). Each permitted key carries a closed value-SHAPE contract, not just key-closure: an LSN is a non-negative integer, a count is a non-negative integer, a duration is a non-negative integer, a boolean is a boolean, a table/slot name is a string or a value-free nil absent marker, and an error class is an atom. A key that is off-list, or on-list with the WRONG shape (a row value smuggled in as a string where an LSN belongs), raises rather than shipping a value downstream. The shape-violation error renders only an allowed atom key and the value's TYPE — never the value itself. Off-list errors elide the rejected keys as well, because map keys can be attacker-controlled terms. The guard therefore cannot leak the bytes it exists to keep out. Mirrors arcadic's allowlist pattern.

Summary

Functions

The permitted event measurement keys.

The permitted span/event metadata keys.

Emit a value-free telemetry event. BOTH measurements and meta are validated against their closed key + value-shape contracts (validate!/1 and validate_measurements!/1 raise on an off-list key or a wrong-shape value), so no row/column value can reach a telemetry consumer.

Wrap fun in a [:replicant, op] span, validating BOTH the start metadata and the returned stop metadata against the value-free contract (validate!/1 raises on an off-list key or a wrong-shape value). fun must return {result, stop_meta}. The span's own measurements (monotonic_time/duration) are generated by :telemetry and are not user-supplied.

Functions

allowed_measurement_keys()

@spec allowed_measurement_keys() :: [atom()]

The permitted event measurement keys.

allowed_meta_keys()

@spec allowed_meta_keys() :: [atom()]

The permitted span/event metadata keys.

event(name, measurements, meta)

@spec event([atom(), ...], map(), map()) :: :ok

Emit a value-free telemetry event. BOTH measurements and meta are validated against their closed key + value-shape contracts (validate!/1 and validate_measurements!/1 raise on an off-list key or a wrong-shape value), so no row/column value can reach a telemetry consumer.

span(op, start_meta, fun)

@spec span(atom(), map(), (-> {term(), map()})) :: term()

Wrap fun in a [:replicant, op] span, validating BOTH the start metadata and the returned stop metadata against the value-free contract (validate!/1 raises on an off-list key or a wrong-shape value). fun must return {result, stop_meta}. The span's own measurements (monotonic_time/duration) are generated by :telemetry and are not user-supplied.