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

wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New
handnot2
Samly can be used to enable SAML 2.0 Single Sign On in a Plug/Phoenix application. This library uses Erlang esaml to provide plug enabl...
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination 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
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
fuelen
Hi all! I want to present a small library which provides a mix task for generating an Entity-Relationship Diagram for Ecto schemas. You...
New
anuaralfetahe
Hello Published a new library - ProcessHub! ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
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
mudasobwa
I am seeing a lot of aplications of Argumentum ad Vericundiam in software discussions. They do link some piece of writing and point us to...
New
AstonJ
This showed up on my feed.. anyone heard of it? Just hype? Ox Alpha is a reasoning model designed for coding, sustained ag...
New
sergio
It’s not that it’s vocabulary is too advanced. It’s something worse. I get lost trying to follow even a paragraph written by Claude. It’...
New
sorenone
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New
akoutmos
@hugobarauna, Dr. Dimitrios Koutmos (my brother) and I (Alex Koutmos) have been hard at work on writing a book on how you can use Elixir ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews