Elixir plug health check, allow to define different health checks and expose them in a path
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-08-21 08:36:40 -06:00
.github/workflows ci: upgrade checkout action to v7 2026-08-21 08:36:40 -06:00
lib fix(plugins): hide internal errors from health responses 2026-08-21 08:26:16 -06:00
test fix(plugins): hide internal errors from health responses 2026-08-21 08:26:16 -06:00
.formatter.exs Initial commit 🚀 2024-03-04 22:01:14 -06:00
.gitignore Initial commit 🚀 2024-03-04 22:01:14 -06:00
LICENSE Add LICENSE 2024-03-05 08:56:51 -06:00
mix.exs chore: bump version to 0.2.0 2026-08-21 08:29:39 -06:00
mix.lock chore(deps): fix vulnerabilities and bump version to 0.1.1 2026-08-21 00:55:13 -06:00
README.md chore: bump version to 0.2.0 2026-08-21 08:29:39 -06:00

Sanito

A Plug health-check endpoint with isolated, time-limited plugin checks.

Installation

def deps do
  [
    {:sanito, "~> 0.2.0"}
  ]
end

The Ecto plugin also requires {:ecto_sql, "~> 3.13"}.

Usage

Add Sanito before your router:

defmodule MyAppWeb.Endpoint do
  use Phoenix.Endpoint, otp_app: :my_app

  plug Sanito.Plug,
    path: "/health",
    timeout: 5_000,
    plugins: [
      {Sanito.Plugins.EctoPlugin, repo: MyApp.Repo},
      MyApp.Health.CachePlugin
    ]

  plug MyAppWeb.Router
end
Option Default Description
:path "/health" Health-check path.
:plugins [] Modules or {module, keyword_options} entries.
:timeout 5_000 Timeout for each plugin, in milliseconds.

Sanito returns 200 when every check succeeds and 503 when any check fails.

Custom plugins

Plugins implement Sanito.PluginBehaviour and return {:ok, message} or {:error, message} with a string message.

defmodule MyApp.Health.CachePlugin do
  @behaviour Sanito.PluginBehaviour

  @impl true
  def check(_conn, opts) do
    name = Keyword.get(opts, :name, "cache")
    {:ok, "#{name} is available"}
  end
end

Plugin error messages are public. Exceptions, exits, malformed results, and Ecto errors return generic messages while details are written to application logs.

The Ecto plugin runs SELECT 1 against its configured repo:

plugins: [{Sanito.Plugins.EctoPlugin, repo: MyApp.Repo}]

Development

MIX_ENV=test mix ci

Sanito is available under the MIT License.