DarynOngera

DarynOngera

Hey guys, I’ve had this in local for a couple of days I thought I should share to the community.

What if ? A business transaction can never be reported as complete ({:ok, _}) unless its audit trail is also complete, written atomically with it.

FortAudit aims to solve this but not entirely confined by this business rule, it is an audit logging library that dual-routes every audit event to PostgreSQL (via Ecto.Multi) and structured JSON (via Elixir’s :logger). Business transactions and their audit records are always committed atomically.

Two paths

  • Transactional transact/4: DB audit row is atomic with business steps. Logger emission is secondary, after commit.

  • Standalone log/1: Single insert outside a transaction. Useful for pre-Multi validation failures or non-transactional code.

When you need AduitFort

  • You need both audit trail AND ops visibility: the DB row is your source of truth for compliance; the Logger line is how your on-call finds the event in Datadog/Loki without running a SQL query.

  • Your audit is part of a business transaction: the order was created, the payment was captured, and the audit row must commit atomically with both. A separate Repo.insert after Repo.transaction returns leaves a window where the business data exists but the audit doesn’t.

  • You can’t afford silent audit loss: a crash between the DB commit and the Logger emission leaves a row with emitted_at: nil. FortAudit’s reconciliation finds those rows and re-emits them on restart.

  • You ship logs to a metrics-oriented backend: Loki, Datadog, and Elasticsearch all charge by label cardinality. FortAudit’s configurable label/body split keeps unbounded fields out of your indexed metadata by default.

Key features

  • Atomic by construction: bare Ecto.Multi passed to transact/4 raises; you must wrap with Fort.Audit.wrap/1 first. Zero-step transactions also raise. The type system prevents silent omissions.

  • At-least-once Logger emission: the DB write commits first. If the process crashes before the Logger line is emitted and emitted_at stamped, the row is recovered on restart via mix fort.reconcile.

  • Label-safe metadata: Logger metadata is split into two tiers via :logger_label_fields config. Low-cardinality fields are top-level keys; unbounded fields nest under a single :details key, preventing accidental label explosions in Loki/Datadog/Elasticsearch.

  • No vendor lock-in: FortAudit’s responsibility ends at emitting a well-structured Logger line.

  • Pure Ecto: Zero dependencies on Phoenix, Plug, or any web framework.

Quick start

# mix.exs
{:fort_audit, "~> 0.1"}
# config/config.exs
config :fort_audit, :repo, MyApp.Repo
mix fort.install
mix ecto.migrate
Multi.new()
|> Multi.insert(:user, user_changeset)
|> Fort.Audit.wrap()
|> Fort.Audit.append_to_multi(:audit, %{
  actor_id: actor.id,
  actor_type: "admin_user",
  action: "user.created"
})
|> Fort.Audit.transact("user.created", actor.id)

Recover unemitted rows:

mix fort.reconcile

GitHub:

Hex:

Where Next? Top

Trending in Announcing Top

type1fool
WebAuthnLiveComponent WebAuthnComponents See this post about renaming the package. Passwordless authentication for Phoenix LiveView app...
New
GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
ahamez
Hi everyone, I’ve been working on this protobuf library for 3 years. We use it in the company I work for, EasyMile, to communicate with ...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
kip
I’ll shortly be launching Text, a nascent text analysis library. Current functionality In this early version (not ready for prime time) ...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews