sentry v6.4.2 Sentry.Logger

This is based on the Erlang error_logger.

To set this up, add :ok = :error_logger.add_report_handler(Sentry.Logger) to your application’s start function. Example:

def start(_type, _opts) do
  children = [
    supervisor(Task.Supervisor, [[name: Sentry.TaskSupervisor]]),
    :hackney_pool.child_spec(Sentry.Client.hackney_pool_name(),  [timeout: Config.hackney_timeout(), max_connections: Config.max_hackney_connections()])
  ]
  opts = [strategy: :one_for_one, name: Sentry.Supervisor]

  :ok = :error_logger.add_report_handler(Sentry.Logger)

  Supervisor.start_link(children, opts)
end

Your application will then be running a Sentry.Logger event handler that receives error report messages and send them to Sentry.

It is important to note that the same report handler can be added multiple times. If you run an umbrella app, and add the report handler in multiple individual applications, the same error will be reported multiple times (one for each handler). There are two solutions to fix it.

The first is to ensure that the handler is only added at the primary application entry-point. This will work, but can be brittle, and will not work for applications running the multiple release style.

The other solution is to check for existing handlers before trying to add another. Example:

# :error_logger.start() # this may be necessary on Elixir 1.6/OTP 21
if !(Sentry.Logger in :gen_event.which_handlers(:error_logger)) do
  :ok = :error_logger.add_report_handler(Sentry.Logger)
end

With this solution, if a Sentry.Logger handler is already running, it will not add another. One can add the code to each application, and there will only ever be one handler created. This solution is safer, but slightly more complex to manage.

If you are running on Elixir 1.6 and Erlang/OTP 21, it may be necessary to call :error_logger.start/1 prior to calling :gen_event.which_handlers/1

Link to this section Summary

Functions

Callback implementation for c::gen_event.code_change/3

Callback implementation for c::gen_event.handle_call/2

Callback implementation for c::gen_event.handle_event/2

Callback implementation for c::gen_event.handle_info/2

Callback implementation for c::gen_event.init/1

Callback implementation for c::gen_event.terminate/2

Link to this section Functions

Link to this function code_change(old, state, extra)

Callback implementation for c::gen_event.code_change/3.

Link to this function handle_call(arg, state)

Callback implementation for c::gen_event.handle_call/2.

Link to this function handle_event(arg1, state)

Callback implementation for c::gen_event.handle_event/2.

Link to this function handle_info(msg, state)

Callback implementation for c::gen_event.handle_info/2.

Callback implementation for c::gen_event.init/1.

Link to this function terminate(reason, state)

Callback implementation for c::gen_event.terminate/2.