kenpratt / erlbrake

Erlang Airbrake notification client
http://github.com/kenpratt/erlbrake
MIT License
32 stars 21 forks source link

h1. erlbrake

An Erlang client for the "Airbrake":http://airbrake.io/ exception notification service (formerly known as Hoptoad).

h2. Requirements

h2. Usage

  1. Sign up for "Airbrake":http://airbrake.io/
  2. Create a Airbrake project, and copy the API key
  3. Proceed with "Running the Erlbrake application" or "Embedding Erlbrake in an existing application"

h3. Running the Erlbrake application

  1. Compile erlbrake: @cd path/to/erlbrake/ && make@ or @rebar compile@
  2. Start the erlbrake application, replacing the API key with your own and the paths to ibrowse and erlbrake to where they are installed on your machine:
ERL_LIBS="$HOME/erlang/ibrowse:$HOME/erlang/erlbrake:$ERL_LIBS" erl -erlbrake apikey '"76fdb93ab2cf276ec080671a8b3d3866"' -erlbrake error_logger true -erlbrake environment '"development"' -s erlbrake start
  1. Try generating a couple of error reports:
1> airbrake:notify(error, fake, "Testing erlbrake with a manual error report", no_module, 0).
ok
2> error_logger:error_msg("A sample error caught by the erlbrake error logger.").
...
  1. Configure erlbrake: three configuration options are supported: @apikey@, @environment@, and @error_logger@

These configuration options can be set in @ebin/erlbrake.app@, or configured on the command line as in the above example.

h3. Embedding Erlbrake in an existing application

  1. Add airbrake to your application supervision tree:
{airbrake,
    {airbrake, start_link, ["production", "76fdb93ab2cf276ec080671a8b3d3866"]},
    permanent, 5000, worker, dynamic}.
  1. Add airbrake hooks:
case calculate_something() of
    {ok, Value} ->
        Value;
    Error = {error, Reason} ->
        airbrake:notify(error, Reason, "Frobber calculation failed", ?MODULE, ?LINE)
end.

and/or:

try do_stuff() of
    Value ->
        Value
catch
    Type:Reason ->
        airbrake:notify(Type, Reason, "Ahhh! Stuff is not good!", ?MODULE, ?LINE, erlang:get_stacktrace())
end.
  1. Compile erlbrake: @cd path/to/erlbrake/ && make@
  2. Add the erlbrake ebin directory to your Erlang path: @-pa path/to/erlbrake/ebin@
  3. Start ibrowse during your application startup: @application:start(ibrowse)@
  4. Test it out!
  5. (Optional) Add the erlbrake error logger to your application startup:
error_logger:add_report_handler(erlbrake_error_logger)

h2. Macro

A macro similar to this is likely useful to avoid duplication:

-define(NOTIFY_AIRBRAKE(Type, Reason, Message),
        airbrake:notify(Type, Reason, Message, ?MODULE, ?LINE, erlang:get_stacktrace())).

If you already have a macro to log errors, just add it to that :)