Tlm

Reports your Elixir app's errors to Hullop Telemetry (Tlm), which groups them into issues and shows you what broke and why.

Installation

Add the dependency to mix.exs:

def deps do
  [
    {:tlm, ">= 0.1.0"}
  ]
end

Give it your project's DSN (from its setup page in Tlm) in the TLM_DSN environment variable of the deployed app. Or, to take it from somewhere else, in config/runtime.exs:

config :tlm, dsn: System.get_env("MY_TLM_DSN")

That's it. From now on, crashes are reported on their own: controllers, LiveViews, GenServers, Tasks, any process. Oban job failures too, when Oban is around (not the jobs that return {:cancel, _} or {:discard, _}). Exceptions that Plug turns into a 4xx, like Ecto.NoResultsError, aren't bugs and aren't reported.

It also sends a heartbeat when the app starts and every hour after, so Tlm knows the app is up even when nothing breaks, and shows its release, environment and SDK version.

Without a DSN nothing is sent, so dev and test stay quiet: don't export TLM_DSN there.

Checking the setup

Send a test event and see Tlm's answer:

MIX_ENV=prod mix tlm.test

It prints the event's id when Tlm accepted it, or what went wrong (no DSN, a refused key, Tlm unreachable), and exits with 1 then. In a release, where mix tasks aren't available:

bin/my_app rpc 'IO.inspect(Tlm.test_event())'

Request details and users

Add the plug to your endpoint to see the request each error happened in (credentials such as cookies are never sent):

# lib/my_app_web/endpoint.ex
plug Tlm.Plug

And say who hit the error, by id:

Tlm.set_user(current_user.id)

Source lines in releases

Tlm shows the lines around each frame of your code. Releases don't ship source files, so package them right before building the release:

MIX_ENV=prod mix tlm.package_source
MIX_ENV=prod mix release

In a Dockerfile, that's one line before mix release.

Oban job args

A failed Oban job's issue shows the job's args, id and attempt (as "3 of 3"), so the input that broke it is at hand. Values under keys that look secret (password, token, secret, api_key, key, auth, cookie, session, …, at any depth) are sent as "[FILTERED]", and args past 2 KB are cut. For apps whose job args are sensitive by nature:

config :tlm, oban: [args: false]

Reporting by hand

try do
  charge!(order)
rescue
  e ->
    Tlm.capture_exception(e, stacktrace: __STACKTRACE__)
    {:error, :payment_failed}
end

Tlm.capture_message("Payment gateway slow", level: :warning)

Options

Option Default
:dsn TLM_DSN https://tlm_…@tlm.hullop.com: where Tlm runs plus the project's key. Nothing is sent without it
:key, :endpoint TLM_KEY, https://tlm.hullop.com The DSN's two halves, set apart. A DSN wins over both
:environment The Mix env the app was built in prod, staging, …
:release RELEASE_VSN Version or git sha
:in_app Your app's own applications Which applications count as "your code"
:oban [args: true] [args: false] leaves job args out of Oban failures
:repos none Ecto repo telemetry prefixes, e.g. [[:my_app, :repo]], to record queries as breadcrumbs

How it behaves

Events are sent in the background, one at a time, from a bounded queue (the oldest is dropped past 1000), so a slow or unreachable Tlm never slows your app down. Failed sends are retried with the same id, so nothing is counted twice; when Tlm asks to slow down, it does. When it refuses the key, nothing more is sent until the app restarts. Heartbeats share that queue, at most one waiting at a time. They have their own rate limit, so being slowed down on heartbeats never pauses errors, and they never log anything.

The protocol is documented in Tlm's docs/protocol.md, if you'd like to report from another language.

License

MIT. See LICENSE.