bugsnag (bugsnag_erlang v3.0.0)

View Source

BugSnag Erlang client.

Configuration

It can be configured using application environment variables or by passing a map to the start_link/1 function.

If using application environment variables, the config looks like the following:

{bugsnag_erlang, [
    {enabled, true},
    {api_key, "BUGSNAG_API_KEY"},
    {release_stage, "production"},
    {handler_name, bugsnag_logger_handler},
    {pool_size, 10}
]}

If enabled is set to other than true, the rest of the configuration won't be read and no handler will be registered. For the rest of the keys, see config/0.

If a new handler wants to be added, the handler_name key can be set to a new atom.

Summary

Types

Configuration options for the Bugsnag client.

Event to notify to BugSnag.

Metadata about the event.

A printable string

Functions

Add a new logger handler.

Add a new logger handler.

Notify of a bugsnag event.

Remove a new logger handler.

Types

config()

-type config() ::
          #{api_key := binary(),
            release_stage := binary(),
            name := logger_handler:id(),
            pool_size := pos_integer(),
            endpoint => binary(),
            events_limit => pos_integer(),
            notifier_name => binary()}.

Configuration options for the Bugsnag client.

It takes the following configuration options:

  • api_key: the Bugsnag API key, mandatory to provide.
  • release_stage: the release stage of the application, defaults to production
  • name: defaults to bugsnag_logger_handler, but allows to create more logger handlers with different configurations.
  • pool_size: defaults to the number of schedulers, increases the number of workers in the pool in case of high load.
  • endpoint: allows you to configure a custom config, including testing endpoints.
  • events_limit: allows you to configure the maximum number of events to be sent to Bugsnag at once. If event queues fill too fast, older non-sent events will be dropped. The default is 1000, as an average big event including stacktraces is no bigger than 1KB, therefore 1000 events should keep the payload below 1MB.
  • notifier_name: a string, the notifier name as required by BugSnag. Defaults to "Bugsnag Erlang".

event()

-type event() ::
          #{what => text(),
            message => text(),
            class => exit | error | throw,
            kind => exit | error | throw,
            error =>
                #{kind => exit | error | throw,
                  message => term(),
                  stack => [{module(), atom(), non_neg_integer() | [term()], [{atom(), _}]}]},
            reason => term(),
            stacktrace => [{module(), atom(), non_neg_integer() | [term()], [{atom(), _}]}],
            atom() => text()}.

Event to notify to BugSnag.

  1. Events that contain #{class := _, reason := _, stacktrace := _}, following the naming convention as exemplified by erlang:raise/3, will be treated as exceptions to BugSnag; or #{kind := _, reason := _, stacktrace := _} as per telemetry's convention; or #{error := #{kind := _, message := _, stack := _} as per DataDog convention;
  2. Event structure will have all their printable key-value pairs as key-value pairs in metaData.
  3. breadcrumbs will always contain the timestamp of the event.

metadata()

-type metadata() ::
          #{mfa := {module(), atom(), non_neg_integer()},
            line := non_neg_integer(),
            level => logger:level(),
            time => integer(),
            atom() => term()}.

Metadata about the event.

The default severity level is warning. The default mfa is {undefined, undefined, 0} and line is also 0.

text()

-type text() :: atom() | string() | binary().

A printable string

Functions

add_handler(Config)

-spec add_handler(config()) -> supervisor:startchild_ret().

Add a new logger handler.

add_handler(Config, LoggerConfig)

Add a new logger handler.

notify(BugSnagConfig, Report, Meta)

-spec notify(config(), event(), metadata()) -> term().

Notify of a bugsnag event.

  1. Events that contain #{class := _, reason := _, stacktrace := _}, following the naming convention as exemplified by erlang:raise/3, will be treated as exceptions to BugSnag; or #{kind := _, reason := _, stacktrace := _} as per telemetry's convention; or #{error := #{kind := _, message := _, stack := _} as per DataDog convention;
  2. Event structure will have all their printable key-value pairs as key-value pairs in metaData

remove_handler/1

-spec remove_handler(logger_handler:id() | config()) -> ok | {error, term()}.

Remove a new logger handler.