Exceptions

Turn logged exceptions into structured exception events

The Timber Exception integration requires installation of the base timber Hex package first.

Timber integrates directly with Elixir to turn your exceptions into rich structured events. This reduces noise in your logs and makes them easier to search and use.

Installation

  1. Ensure that you have both :timber (version 3.1.0 or later) and :timber_exceptions listed as dependencies in mix.exs:

    mix.exs
    def deps do
    [
    {:timber, "~> 3.1"},
    {:timber_exceptions, "~> 2.0"}
    ]
    end
  2. Run mix deps.get to install the dependencies.

  3. Add the translator in your application's start/2 function:

    lib/my_app/application.ex
    defmodule MyApp
    use Applictation
    def start(_type, _args) do
    # ADD THE FOLLOWING LINE:
    :ok = Logger.add_translator({Timber.Exceptions.Translator, :translate})
    ‚Äč
    opts = [strategy: :one_for_one, name: MyApp.Supervisor]
    Supervisor.start_link(children, opts)
    end
    end

Events

error

The error event is emitted any time your application raises an exception

{
"error": {
"name": "RuntimeError",
"message": "function MyModule.bad/0 is undefined (module MyModule is not available)",
"backtrace": [
{
"function": "my_func",
"file": "lib/my_file.ex",
"line": 22
}
]
}
}

Name

Type

Description

error.name

string

The module name of the exception.

error.message

string

The message of the exception.

error.backtrace.[n].function

string

The backtrace item's function name.

error.backtrace.[n].file

string

The backtrace item's file name.

error.backtrace.[n].line

int

The backtrace item's line number