airbrake_client

Airbrake client to report errors and exceptions to Airbrake.io.

Latest version: 0.10.0 registry icon
Maintenance score
0
Safety score
0
Popularity score
71
Check your open source dependency risks. Get immediate insight about security, stability and licensing risks.
Security
  Vulnerabilities
Version Suggest Low Medium High
0.10.0 0 0 0 0
0.9.1 0 0 0 0
0.9.0 0 0 0 0
0.8.2 0 0 0 0
0.8.1 0 0 0 0
0.8.0 0 0 0 0

Stability
Latest release:

0.10.0 - this version is safe to use because it has no known security vulnerabilities at this time. Find out if your coding project uses this component and get notified of any reported security vulnerabilities with Meterian-X Open Source Security Platform

Licensing

Maintain your licence declarations and avoid unwanted licences to protect your IP the way you intended.

LGPL-3.0-only   -   GNU Lesser General Public License v3.0 only

Not a wildcard

Not proprietary

OSI Compliant



Airbrake Client

Capture exceptions and send them to Airbrake or to your Errbit installation.

This library was originally forked from the airbrake Hex package. Development and support for that library seems to have lapsed, but we (the devs at CityBase) had changes and updates we wanted to make. So we decided to publish our own fork of the library.

Installation

Add airbrake_client to your dependencies:

defp deps do
  [
    {:airbrake_client, "~> 0.10"}
  ]
end

Migrating from airbrake

If you are switching from the original airbrake library:

  1. Replace the :airbrake dependency with the :airbrake_client dependency above.
    • You may want to start with version ~> 0.8.0 for maximum backwards compatibility.
  2. Remove the airbrake dependency in your lockfile.
    • Command: mix deps.unlock --unused
    • If the dependency remains in the lockfile, check all of your apps and all of your dependencies.
  3. Update your config/*.exs files to configure :airbrake_client instead of :airbrake.
    • A search-and-replace-in-project on config :airbrake can work really well.
    • When you run your project(even running the tests), you should get a complaint if you're still configuring :airbrake.

Configuration

config :airbrake_client,
  api_key: System.get_env("AIRBRAKE_API_KEY"),
  project_id: System.get_env("AIRBRAKE_PROJECT_ID"),
  environment: Mix.env(),
  filter_parameters: ["password"],
  filter_headers: ["authorization"],
  host: "https://api.airbrake.io" # or your Errbit host

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

Required configuration arguments:

  • :api_key - (binary) the token needed to access the Airbrake API. You can find it in User Settings.
  • :project_id - (integer) the id of your project at Airbrake.

Optional configuration arguments:

  • :environment - (binary or function returning binary) the environment that will be attached to each reported exception.
  • :filter_parameters - (list of binaries) allows to filter out sensitive parameters such as passwords and tokens.
  • :filter_headers - (list of binaries) filters HTTP headers.
  • :host - (binary) the URL of the HTTP host; defaults to https://api.airbrake.io.
  • :ignore - (MapSet of binary or function returning boolean or :all) allows to ignore some or all exceptions. See examples below.
  • :options - (keyword list or function returning keyword list) values that are included in all reports to Airbrake.io. See examples below.

Ignoring some exceptions

To ignore some exceptions use the :ignore config key. The value can be a MapSet:

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

The value can also be a two-argument function:

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

Or the value can be the atom :all to ignore all errors (and effectively turning off all reporting):

config :airbrake_client,
  ignore: :all

Shared options for reporting data to Airbrake

If you have data that should always be reported, they can be included in the config with the :options key. Its value should be a keyword list with any of these keys: :context, :params, :session, and :env.

config :airbrake_client,
  options: [env: %{"SOME_ENVIRONMENT_VARIABLE" => "environment variable"}]

Alternatively, you can specify a function (as a tuple) which returns a keyword list (with the same keys):

config :airbrake_client,
  options: {Web, :airbrake_options, 1}

The function takes a keyword list as its only parameter; the function arity is always 1.

Usage

Phoenix app

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
      # ...

Report an exception

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

GenServer

Use Airbrake.GenServer instead of GenServer:

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

Any Elixir process

By pid:

Airbrake.monitor(pid)

By name:

Airbrake.monitor(Registered.Process.Name)

Integration Apps

The Elixir apps defined in integration_test_apps are used for testing different dependency scenarios. If you make changes to the way jason or poison is used this library, you should consider adding tests to those apps.