AuditLog.Context (AuditLog v0.1.0)

Copy Markdown View Source

Explicit actor, correlation, causation, and shared metadata for audit events.

A context is ordinary immutable data with no process- or connection-local state. Pass it through functions and tasks. Across a serialization boundary, store its primitive fields and rebuild the context in the receiving process.

Summary

Functions

Creates a context for follow-up work.

Creates a context, generating a correlation UUID unless one is supplied.

Types

t()

@type t() :: %AuditLog.Context{
  actor: AuditLog.Actor.t(),
  causation_id: Ecto.UUID.t() | nil,
  correlation_id: Ecto.UUID.t(),
  metadata: map()
}

Functions

child(parent, actor, causing_event, opts \\ [])

@spec child(t(), AuditLog.Actor.t(), AuditLog.Event.t() | Ecto.UUID.t(), keyword()) ::
  t()

Creates a context for follow-up work.

The parent correlation is retained, the explicitly supplied actor performs the child action, and causing_event may be an event struct or UUID. Parent metadata is inherited unless :metadata is supplied.

This function does not mutate the parent context.

new(actor, opts \\ [])

@spec new(
  AuditLog.Actor.t(),
  keyword()
) :: t()

Creates a context, generating a correlation UUID unless one is supplied.

Options

  • :correlation_id - UUID for the request or business operation; generated when omitted
  • :causation_id - optional UUID of the event that caused later work
  • :metadata - JSON-object map inherited by events