Bandera.Audit (bandera v0.4.0)

Copy Markdown View Source

Opt-in audit hook. Turns Bandera's existing write telemetry ([:bandera, :enable|:disable|:clear] span :stop events) into structured Bandera.Audit.Event records and forwards them to a callback you provide.

Bandera.Audit.attach(:my_audit, fn event ->
  MyApp.AuditLog.insert!(event)
end)

An exception raised by your callback is caught and logged rather than propagated, so a transient failure can't make :telemetry silently detach the handler and drop all later audit events.

Summary

Functions

Attach a handler that invokes callback with a Bandera.Audit.Event for every enable/disable/clear. handler_id is any term unique to this handler.

Detach a handler attached with attach/2.

Functions

attach(handler_id, callback)

@spec attach(term(), (Bandera.Audit.Event.t() -> any())) ::
  :ok | {:error, :already_exists}

Attach a handler that invokes callback with a Bandera.Audit.Event for every enable/disable/clear. handler_id is any term unique to this handler.

detach(handler_id)

@spec detach(term()) :: :ok | {:error, :not_found}

Detach a handler attached with attach/2.