Chronicle.Phoenix (chronicle v0.1.1)

Copy Markdown

Builds audit context from a Plug.Conn.

The default actor mapper records only a type and id; it never serializes the entire user struct. Use :actor or :actor_mapper for application-specific identity.

Request provenance — method, path, remote IP, request id — is contextual data, so it lands under metadata["http"] rather than in a column nothing queries.

Summary

Functions

Runs one Phoenix request action as an audited group.

Runs a block with request audit context without leaking it to subsequent work in the same process.

Functions

context(conn, opts \\ [])

@spec context(
  Plug.Conn.t(),
  keyword()
) :: map()

put_context(conn, opts \\ [])

@spec put_context(
  Plug.Conn.t(),
  keyword()
) :: Plug.Conn.t()

run(conn, type, opts \\ [], fun \\ nil)

(macro)

Runs one Phoenix request action as an audited group.

Takes a do block or a zero-arity function. Option values for :actor, :subject, :data, and :metadata may be one-argument functions that receive the connection.

with_context(conn, opts \\ [], fun \\ nil)

(macro)

Runs a block with request audit context without leaking it to subsequent work in the same process.

Takes a do block or a zero-arity function, like Chronicle.transaction/3:

Chronicle.Phoenix.with_context conn do
  Accounts.disable(account)
end