Crystal Exception & Error Tracking

Typical installation time: ~2 minutes

Hi there! You’ve found Honeybadger’s guide to Crystal exception and error tracking. Once installed, Honeybadger will automatically report errors in your Crystal application.

Getting Started

Source Code

Update your shard.yml to include honeybadger:

+  honeybadger:
+    github: honeybadger-io/honeybadger-crystal

Configure your API key (available under Project Settings in Honeybadger):

Honeybadger.configure do |config|
  config.api_key = ENV["HONEYBADGER_API_KEY"]? || "API Key"
  config.environment = ENV["HONEYBADGER_ENVIRONMENT"]? || "production"

Reporting Errors

If you’re using a web framework, add the Honeybadger::Handler to the HTTP::Server stack:[]) do |context|
  # ...

Details for adding the handler to:

For non-web contexts, or to manually report exceptions to Honeybadger, use Honeybadger.notify:

  # run application code
  raise "OH NO!"
rescue exception


To set configuration options, use the Honeybadger.configure method:

Honeybadger.configure do |config|
  config.api_key = "API Key"
  config.environment = "production"

The following configuration options are available:

Name Type Default Example Environment Var
api_key String "" "badgers" HONEYBADGER_API_KEY
endpoint Path|String "" "" HONEYBADGER_ENDPOINT
hostname String The hostname of the current server. "badger" HONEYBADGER_HOSTNAME
project_root String The current working directory "/path/to/project" HONEYBADGER_PROJECT_ROOT
report_data bool true false HONEYBADGER_REPORT_DATA
development_environments Array(String) [“development”,”test”]   HONEYBADGER_DEVELOPMENT_ENVIRONMENTS
environment String? nil "production" HONEYBADGER_ENVIRONMENT

Environment based config

Honeybadger can also be configured from environment variables. Each variable has a correlated environment variable and is prefixed with HONEYBADGER_. For example:

env HONEYBADGER_API_KEY=2468 ./server

All environment variables are documented in the configuration table above.

Version Requirements

Crystal > 0.36.1