Skip to content

signdict/bugsnex

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bugsnex Hex Version Build Status

API client and logger for Bugsnag

Installation

If available in Hex, the package can be installed as:

  1. Add bugsnex to your list of dependencies in mix.exs:

    def deps do
      [{:bugsnex, "~> 0.4.1"}]
    end
  2. If you use Elixir < 1.4 ensure bugsnex is started before your application:

    def application do
      [applications: [:bugsnex]]
    end
  3. Check out how to send notifications to bugsnag via Bugsnag.notify or the plug in the "Usage" section

Configuration

config :bugsnex, :otp_app, :your_app_name
config :bugsnex, :api_key, "your_api_key"
config :bugsnex, :release_stage, "staging"
config :bugsnex, :use_logger, true
config :bugsnex, :filter_params, ~w(password password_confirmation api_key)

The :filter_params config is used by the Bugsnex.Plug module to filter out parameters that should not be sent to Bugsnag.

Usage

Sending bug reports

Once configured, use Bugsnex.notice(exception) or Bugsnex.notice(exception,stacktrace) to send errors to Bugsnag.

If use_logger is set to true, an error logger event handler is added and SASL compliant errors are sent to Bugsnag.

You can also manually wrap code in a Bugsnex.handle_error block. Errors in this block will then be sent to Bugsnag and reraised. Example:

Bugsnex.handle_errors %{some: "metadata"} do
  somthing_that_could_raise_and_error()
end

Automatic reports via Bugsnex.Plug

Bugsnex also provides a Plug called Bugsnex.Plug that you could add to your router to send errors automatically. Example:

defmodule YourApp.Router do
  use YourApp.Web, :router
  use Bugsnex.Plug

  # ...
end

Tracking deployments

Use Bugsnex.track_deploy(additional_params) to send a deployment notification to bugsnag. additional_params is an optional map with keys:

  • :apiKey: your bugsnag api key (default is Application.get_env(:bugsnex, :api_key))
  • :repository: url of your source code repository (default is Application.get_env(:bugsnex, :repository_url))
  • :releaseStage: the release stage (e.g. staging, production) (default is Application.get_env(:bugsnex, :release_stage))
  • :branch: scm branch this release was deployed from
  • :revision: scm revision this release was deployed from
  • :appVersion: SemVer version of your app

Metadata

You can associate metadata by calling Bugsnex.put_metadata(%{some: "metadata"}). Note that metadata is stored inside the process dictionary. This means that you shouldn't put a lot of data in there and also that it's only associated with the calling process. Errors in different processes won't be associated with that metadata.

There are some special keys for metadata that Bugsnag understands (explanations paraphrased from the Bugsnag API documentation):

  • %{user: %{id: 123, email: "user@example.com", name: "Some name"}: Information about the user affected by the crash
  • %{context: "auth/session#create"}: A string representing what was happening in the application at the time of the error
  • %{device: %{osVersion: "2.1.1", hostname: "web1.internal"}}: Information about the computer/device running the app

About

API client and logger for Bugsnag

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Elixir 100.0%