Airbax v0.0.4 Airbax

This module provides functions to report any kind of exception to Airbrake or Errbit.

Configuration

The :airbax application needs to be configured properly in order to work. This configuration can be done, for example, in config/config.exs:

config :airbax,
  project_key: "9309123491",
  project_id: true,
  environment: "production"

Summary

Functions

report(kind, value, stacktrace, params \\ %{}, session \\ %{})

Specs

report(:error | :exit | :throw, any, [any], map, map) :: :ok

Reports the given error/exit/throw.

kind specifies the kind of exception being reported while value specifies the value of that exception. kind can be:

  • :error - reports an exception defined with defexception; value must be an exception, or this function will raise an ArgumentError exception
  • :exit - reports an exit; value can be any term
  • :throw - reports a thrown term; value can be any term

kind itself is not sent to the Airbrake/Errbit, it’s only used to properly parse value.

The params and session arguments can be used to customize metadata sent to Airbrake.

This function is fire-and-forget: it will always return :ok right away and perform the reporting of the given exception in the background.

Examples

Exceptions can be reported directly:

Airbax.report(:error, ArgumentError.exception("oops"), System.stacktrace())
#=> :ok

Often, you’ll want to report something you either rescued or caught. For rescued exceptions:

try do
  raise ArgumentError, "oops"
rescue
  exception ->
    Airbax.report(:error, exception, System.stacktrace())
    # You can also reraise the exception here with reraise/2
end

For caught exceptions:

try do
  throw(:oops)
  # or exit(:oops)
catch
  kind, value ->
    Airbax.report(kind, value, System.stacktrace())
end

Using custom data:

Airbax.report(:exit, :oops, System.stacktrace(), %{"weather" => "rainy"})