Skip to content

kenpratt/erlbrake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

erlbrake

An Erlang client for the Airbrake exception notification service (formerly known as Hoptoad).

Requirements

Usage

1. Sign up for Airbrake
2. Create a Airbrake project, and copy the API key
3. Proceed with “Running the Erlbrake application” or “Embedding Erlbrake in an existing application”

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

3. 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.").
...

4. Configure erlbrake: three configuration options are supported: apikey, environment, and error_logger

  • apikey – Set this to the API key of your Airbrake project (String).
  • environment – The Airbrake environment that errors will be reported under (String).
  • error_logger – Set to true to enable the erlbrake error_logger (Boolean). The erlbrake error logger will intergrate with the existing Erlang/OTP error logging, notifying airbrake of any runtime errors in your application. The upside is that it can catch things that manual airbrake notification can’t.

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

Embedding Erlbrake in an existing application

1. Add airbrake to your application supervision tree:

{airbrake,
    {airbrake, start_link, ["production", "76fdb93ab2cf276ec080671a8b3d3866"]},
    permanent, 5000, worker, dynamic}.

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

3. Compile erlbrake: cd path/to/erlbrake/ && make
4. Add the erlbrake ebin directory to your Erlang path: -pa path/to/erlbrake/ebin
5. Start ibrowse during your application startup: application:start(ibrowse)
6. Test it out!
7. (Optional) Add the erlbrake error logger to your application startup:

error_logger:add_report_handler(erlbrake_error_logger)

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 :)

About

Erlang Airbrake notification client

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages