Airbrake Elixir

Build StatusHex Version

Capture exceptions and send them to the Airbrake or to your Errbit installation!

Installation

# 1. Add :airbrake to applications list in your projects mix.exs

# 2. Add it to your deps in your projects mix.exs
defp deps do
  [{:airbrake, "~> 0.6"}]
end

# 3. Open up your config/config.exs (or appropriate project config)
config :airbrake,
  api_key: System.get_env("AIRBRAKE_API_KEY"),
  project_id: System.get_env("AIRBRAKE_PROJECT_ID"),
  environment: Mix.env,
  host: "https://airbrake.io" # or your Errbit host

config :logger,
  backends: [{Airbrake.LoggerBackend, :error}, :console]

General usage

With Phoenix:

defmodule YourApp.Router do
  use Phoenix.Router
  use Airbrake.Plug # <- put this line to your router.ex

  # ...
end
  def channel do
    quote do
      use Phoenix.Channel
      use Airbrake.Channel # <- put this line to your web.ex
      # ...

Ignore some exceptions

To ignore some exceptions use :ignore key in config:

config :airbrake,
  ignore: MapSet.new(["Custom.Error"])

# or

config :airbrake,
  ignore: fn(type, message) ->
    type == "Custom.Error" && String.contains?(message, "silent error")
  end

# or

config :airbrake,
  ignore: :all # to disable reporting

Custom usage examples

# Report an exception.
try do
  String.upcase(nil)
rescue
  exception -> Airbrake.report(exception)
end

With GenServer:

defmodule MyServer do
  # use Airbrake.GenServer instead of GenServer
  use Airbrake.GenServer
  # ...
end

With any process:

  Airbrake.monitor(pid)
  # or
  Airbrake.monitor(Registered.Process.Name)
  # or with spawn
  spawn(fn -> 
    :timer.sleep(500)
    String.upcase(nil)
  end) |> Airbrake.monitor