Chronicle.Context (chronicle v0.1.2)

Copy Markdown

Carries audit identity and correlation data through the current process.

A context can be captured in one process and attached in another. This is deliberately explicit: Elixir process dictionary state is not inherited by Tasks.

context = Chronicle.Context.capture()

Task.async(fn ->
  Chronicle.Context.with(context, fn ->
    Chronicle.record("email.delivered", %{message_id: id})
  end)
end)

If the context was captured inside an Chronicle.group/3, events from the task join that group. The group owner must await those tasks before returning.

Summary

Types

t()

@type t() :: %Chronicle.Context{group: pid() | nil, values: map()}

Functions

allowed_keys()

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

Returns the context keys that audit options may carry.

capture()

@spec capture() :: t()

current_group()

@spec current_group() :: pid() | nil

delete(key)

@spec delete(atom() | String.t()) :: :ok

get()

@spec get() :: map()

merge(values)

@spec merge(map() | keyword()) :: :ok

put(values)

@spec put(map() | keyword()) :: :ok

with(context, fun)

@spec with(t() | map() | keyword(), (-> result)) :: result when result: term()