Code Monkey home page Code Monkey logo

raven-erlang's Introduction

raven-erlang

raven-erlang is an Erlang client for Sentry that integrates with the standard error_logger module. It also serves as a Lager backend.

Build Status Hex.pm

Basic Usage

Add as dependency

Add raven as a dependency to your project, and include the raven-erlang application in your release.

In rebar.config:

{deps, [
    {raven_erlang, "0.4.3"}
]}.

To start raven_erlang with your application, add in your myapp.app.src:

% ...
{applications, [
    % ...
    raven_erlang
]},
% ...

Configure

raven_erlang is configured using the application environment. This is generally done in app.config or sys.config:

{raven_erlang, [
    % One can point `raven_erlang` to a project like this:
    {uri, "https://app.getsentry.com"},
    {project, "1"},
    {public_key, "PUBLIC_KEY"},
    {private_key, "PRIVATE_KEY"},  % This is now optional

    % ...or just use the DSN:
    {dsn, "https://[email protected]/1"},
    % {dsn, "https://PUBLIC_KEY:[email protected]/1"},  % If using the private key

    % Set to inet6 to use IPv6.
    % See `ipfamily` in `httpc:set_options/1` for more information.
    % Default value is `inet`.
    {ipfamily, inet},

    % Set to true in order to install the standard error logger.
    % Now all events logged using `error_logger` will be sent to Sentry.
    {error_logger, true},

    % Customize error logger:
    % Default value is `[]`.
    {error_logger_config, [
        % `warning` or `error`.
        % If set to `error`, error logger will ignore warning messages and reports.
        % Default value is `warning`.
        {level, warning},

        % Not all messages that error_logger generates are useful.
        % For example, supervisors will always generate an error_report when
        % restarting a child, even if it exits with `reason = normal`.
        % You can provide a module that implements `raven_error_logger_filter` behavior
        % to avoid spamming sentry with issues that are not errors.
        % See http://erlang.org/doc/apps/sasl/error_logging.html for more information.
        % Default value is `undefined`.
        {filter, callback_module}
    ]}
]}.

Lager Backend

At the moment, the raven lager backend shares its configuration with the raven application, and does not allow per-backend configuration.

Simple Configuration

This adds the raven backend to lager. By default, it configures the raven lager backend to send most metadata that the lager parse transform creates (see Advanced Configuration).

{lager, [
    {handlers, [
        {raven_lager_backend, info}]}]}

Advanced Configuration

This configuration uses a list [Level :: atom(), MetadataKeys :: [atom()]].

MetadataKeys is a list of atoms that correspond to the metadata to be sent by Raven, should it be included in the lager log message.

The configuration shown here is equivalent to the Simple Configuration.

{lager, [
    {handlers, [
        {raven_lager_backend,
            [info, [pid, file, line, module, function, stacktrace]]}]}]}

To exclude all metadata except pid:

{lager, [
    {handlers, [
        {raven_lager_backend, [info, [pid]]}]}]}

Advanced Usage

You can log directly events to sentry using the raven:capture/2 function, for example:

try erlang:error(badarg)
catch Class:Reason:Stacktrace ->
    raven:capture("Test Event", [
        {exception, {Class, Reason}},
        {stacktrace, Stacktrace},
        {extra, [
            {pid, self()},
            {process_dictionary, erlang:get()}
        ]}
    ])
end.

raven-erlang's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

raven-erlang's Issues

supervisor reports not appear in sentry

I use filter option in raven_erlang section:

{raven_erlang, [
                        {dsn, "http://url"},
                        {error_logger, true},
                        {error_logger_config, [
                                         {level, warning},
                                         {filter, raven_filter}
                                         ]
                        }
                   ]
    }

I have module raven_filter.erl:

-module(raven_filter).

-behaviour(raven_error_logger_filter).

-export([should_send_supervisor_report/3]).

-include_lib("include/log.hrl").

should_send_supervisor_report(_Supervisor, _Reason, _Context) ->
    %% start_error | child_terminated | shutdown_error
    true.

Then I turn on dbg and generate error:

(<8099.531.0>) call raven_filter:should_send_supervisor_report(...)
(<8099.531.0>) call raven:capture(<<"Supervisor app_sup had child exit with reason bad argument...">>, ....)
(<8099.531.0>) call httpc:request(post,{"http://url/api/store/",} ...

But in sentry I have not see supervisors report.

Does it changes in API or what?

add report handler in doc

Documentation says:

To start raven_erlang with your application, add in your myapp.app.src:

% ...
{applications, [
    % ...
    raven_erlang
]},
% ...

So, in applications section we have list of all applications that must be started before main application is started. And we have -- raven_erlang in that list.

Ok, lets look at this:

case application:get_env(?APP, error_logger) of
            {ok, true} ->
                error_logger:add_report_handler(raven_error_logger);
            _ ->
                ok
        end

Here we get env error_logger from here:

    , {env,
            [ {error_logger, false}
            , {ipfamily, inet}
            ]}

So, raven-erlang starts without adding report handler raven_error_logger, but I have in sys.config:

    {raven_erlang, [
                        {dsn, "http://lol"},
                        {error_logger, true},
                        {error_logger_config, [
                                         {level, warning},
                                         {filter, raven_filter}]
                        }
                   ]
    }

We need to do it manually:

error_logger:add_report_handler(raven_error_logger),

Is it a bug in doc or a feature?

Thanks!

Wrong RESTAPI endpoint

According to the docs, the endpoint should be

{BASE_URI}/api/{PROJECT_ID}/store/

but the endpoint used in the code is

{BASE_URI}/api/store/

Not sure if this is a bug, or some configuration mishap somewhere, but I wanted to raise it as a possible issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.