Mimir.RouteLog (Mimir v0.1.0)

Copy Markdown View Source

The typed record of one routing decision — who asked (caller), which workflow step (correlation), how it ended (outcome), and the decision record. to_meta/2 translates it into request-log meta vocabulary; how (and whether) that meta is persisted belongs to the embedder.

Outcomes: :placed and :no_candidate are both successful routing verdicts (status: "success") — a no-candidate answer is an outcome, not an error. {:grant_failed, reason} means a placement was decided but not grantable (status: "error", class "grant_failed"); the decision record survives the failure it explains.

Summary

Types

Who asked — any map or struct carrying the caller key's id and tenant.

The workflow coordinates of the routed step.

How the route call ended. Everything else about the row derives from this.

t()

Functions

Correlation id for a route call that arrived without one.

Translate the record into request-log meta. Pure given ts (nanosecond event timestamp); defaults to the monotonic clock. Only route-meaningful keys are emitted. Notably, the emitted virtual_key_id carries caller.id — the field name is kept as-is for embedder request-log vocabulary compatibility, not because the caller is necessarily a virtual key.

Types

caller()

@type caller() :: %{
  :id => String.t(),
  optional(:tenant_id) => String.t() | nil,
  optional(atom()) => any()
}

Who asked — any map or struct carrying the caller key's id and tenant.

correlation()

@type correlation() :: %{
  workflow_id: String.t(),
  step_id: String.t(),
  parent_step_id: String.t() | nil
}

The workflow coordinates of the routed step.

outcome()

@type outcome() :: :placed | :no_candidate | {:grant_failed, reason :: atom()}

How the route call ended. Everything else about the row derives from this.

t()

@type t() :: %Mimir.RouteLog{
  caller: caller(),
  correlation: correlation(),
  decision_record: map(),
  outcome: outcome(),
  request_id: String.t()
}

Functions

gen_request_id()

@spec gen_request_id() :: String.t()

Correlation id for a route call that arrived without one.

to_meta(log, ts \\ System.monotonic_time(:nanosecond))

@spec to_meta(t(), integer()) :: map()

Translate the record into request-log meta. Pure given ts (nanosecond event timestamp); defaults to the monotonic clock. Only route-meaningful keys are emitted. Notably, the emitted virtual_key_id carries caller.id — the field name is kept as-is for embedder request-log vocabulary compatibility, not because the caller is necessarily a virtual key.