Imison (Imison v0.1.0)

Copy Markdown View Source

Error tracker that runs inside the host's Phoenix app.

Add Imison to the host's supervision tree, after its repo:

children = [
  MyApp.Repo,
  {Imison, Application.fetch_env!(:my_app, Imison)}
]

with its options in the host's config:

config :my_app, Imison,
  repo: MyApp.Repo,
  username: System.fetch_env!("IMISON_USER"),
  password: System.fetch_env!("IMISON_PASSWORD")

repo, username and password are required. Every other option has a default, see Imison.Config. Imison refuses to start with an ArgumentError when an option is missing, unknown, duplicate or of the wrong type, so a bad config fails the host's boot.

Summary

Functions

Returns the config of a running Imison instance.

Reports an exception the app rescued itself, so handled errors are tracked too.

Starts an Imison supervision tree, raising ArgumentError when the options are invalid.

Types

name()

@type name() :: term()

Functions

config(name \\ __MODULE__)

@spec config(name()) :: Imison.Config.t()

Returns the config of a running Imison instance.

Example

The default instance:

%Imison.Config{} = Imison.config()

An instance started with a custom name:

%Imison.Config{} = Imison.config(MyApp.Imison)

report(exception, stacktrace, metadata \\ %{})

@spec report(Exception.t() | term(), Exception.stacktrace(), map() | keyword()) :: :ok

Reports an exception the app rescued itself, so handled errors are tracked too.

metadata (a map or a keyword list) is stored under metadata in the occurrence's context, with keys from the filter option replaced by [FILTERED]. A value that isn't an exception, such as an Erlang error term, is normalized to its exception first.

The report goes to the default instance, named Imison. It is recorded in the background, like a captured crash: report/3 always returns :ok, never raises and never blocks, and does nothing when no instance runs or the exception is listed in ignore.

Example

try do
  MyApp.Orders.charge(order)
rescue
  exception ->
    Imison.report(exception, __STACKTRACE__, %{order_id: order.id})
    {:error, :charge_failed}
end

start_link(opts)

@spec start_link(keyword()) :: Supervisor.on_start()

Starts an Imison supervision tree, raising ArgumentError when the options are invalid.