Skip to content

CityBaseInc/airbrake_client

Repository files navigation

Airbrake Client

Capture exceptions and post notices for them to Airbrake or to your Errbit installation.

This library was originally forked from the airbrake Hex package. Development and support for that library seems to have lapsed, but we (the devs at Euna Payments (formerly CityBase)) had changes and updates we wanted to make. So we decided to publish our own fork of the library.

Documentation is available on hexdocs.pm.

There are sections below for configuration and usage of this library. Some other documentation that might be interesting:

Installation

Add airbrake_client to your dependencies:

defp deps do
  [
    {:airbrake_client, "~> 2.3"}
  ]
end

Configuration

See the "Create notice v3" section in the Airbrake API docs to understand the config options.

Configure :airbrake_client in your config/*.exs files.

Only the :api_key and :project_id options are required.

Airbrake project configuration

These options configure :airbrake_client to connect to the right project on Airbrake.io (or another host).

config :airbrake_client,
  api_key: System.get_env("AIRBRAKE_API_KEY"),
  project_id: System.get_env("AIRBRAKE_PROJECT_ID"),
  host: "https://api.airbrake.io"
  • :api_key - (required, binary) the token needed to access the Airbrake API. You can find it in User Settings.
  • :project_id - (required, integer or string) the id of your project at Airbrake.
  • :host - (string) the URL of the HTTP host; defaults to https://api.airbrake.io.

Data for an Airbrake notice

You can add some static data to every posted notice:

config :airbrake_client,
  # ...
  context_environment: System.get_env("KUBERNETES_CLUSTER"),
  production_aliases: ["prod"],
  options: [env: %{"namespace" => System.get_env("KUBERNETES_NAMESPACE")}],
  session: :include_logger_metadata
  • :context_environment - (binary or function returning binary) the deployment environment; used to set notice.context.environment. See "Setting the Environment in the Context" for more details.
    • This was formerly :environment which is now deprecated and will be removed in the next major release.
  • :production_aliases - (list of strings) a list of "production" aliases for the environment.
  • :options - (keyword list or function returning keyword list) values that are included in all notices posted to Airbrake.io. See "Shared Options" for more information.
  • :session - can be set to :include_logger_metadata to include Logger metadata in the session field of the report; omit this option if you do not want Logger metadata. See The Session for more details.

Processing the payload when posting a notice

Use these options to change how the payload is processed when posting a notice to Airbrake:

config :airbrake_client,
  # ...
  filter_parameters: ["password"],
  filter_headers: ["authorization"],
  payload_processor: Airbrake.JasonPayloadProcessor

See Airbrake.Utils.filter/2 for details about filtering.

  • :filter_parameters - (list of strings) names of keys (strings or atoms) for sensitive data such as passwords and tokens.
  • :filter_headers - (list of strings) names of HTTP headers (strings or atoms) to filter.
  • :payload_processor - (module, defaults to Airbrake.PoisonPayloadProcessor)
    • See the Payload Processor guide for more details.
    • Replaces :json_encoder which is now deprecated,

:json_encoder is ignored if :payload_processor is set. If only :json_encoder is set, the :payload_processor will be set to the appropriate module. If neither :json_encoder nor :payload_processor is set, the library will use Airbrake.PoisonPayloadProcessor.

Ignoring exceptions

config :airbrake_client,
  # ...
  ignore: :all
  • :ignore has several possibilities:
    • nil (default) - skips nothing
    • :all to ignore all errors (useful in test)
    • MapSet of error modules to ignore
    • A function (type, message -> boolean)

See "Ignoring Errors". Also see Airbrake.Test which might affect your choice for :ignore in test.

Usage

See the specific modules for more details.

  • Airbrake.report/1 to post a notice to Airbrake.
  • Airbrake.LoggerBackend to post Logger error messages as notices to Airbrake.
  • Airbrake.Plug to post a notice for an error in a plug pipeline.
  • Airbrake.Channel to post a notice for an error on a web channel.
  • Airbrake.monitor/1 to post a notice for errors from a process.
  • Airbrake.GenServer or Airbrake.GenServer.handle_terminate/2 to post a notice when a GenServer terminates abnormally.

About

Airbrake client to report errors and exceptions to Airbrake.io.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors