We're working on something new! Hook Relay gives you Stripe-quality webhooks in minutes. Sign up for free today!

Introducing Honeybadger for Crystal

Good news, Crystal developers! We just shipped an official Crystal shard for Honeybadger. Track errors and keep your users happy.

We are excited that you can now easily plug your Crystal applications into Honeybadger. Installation and configuration are easy, and the shard provides everything you need to set up your application.

In this article, we'll cover installing Honeybadger, capturing errors in HTTP servers, manually capturing errors, and collecting context data from the Crystal Log::Context.


Update your shard.yml with the following snippet and shards install

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

Provide your Honeybadger API key at runtime

Visit your Project Settings page on Honeybadger and find your API key. Add the following code to your application startup, and configure your API key in the environment:

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

Capturing exceptions — HTTP::Server

For HTTP frameworks based on Crystal’s excellent HTTP::Server library, add the Honeybadger::Handler middleware to the server stack:

require "http/server"
require "honeybadger"

server = HTTP::Server.new([
  Honeybadger::Handler.new, # added at the top of the stack

server.bind_tcp "", 8080

Adding Honeybadger::Handler to the top of the server stack allows it to capture and report as many errors as possible. Any exception raised within the server stack will be captured and reported to the Honeybadger API.

Capturing exceptions — General utility

For applications which don't leverage HTTP::Server, an application-wide capture is still helpful and might look something like this:

require "honeybadger"

def run_application
rescue exception : Exception
    Honeybadger.notify exception


Log context

Crystal’s unique and powerful Log::Context system allows easily decorating log entries with helpful information like this:

user = Users.first
Log.context.set user_id: user.id
Log.info { "Sent email to User##{user.id}" }

Out of the box, Honeybadger includes the current Log::Context with exceptions reported via Honeybadger.notify — it's dead simple!

Honeybadger has your back when it counts.

We're the only error tracker that combines exception monitoring, uptime monitoring, and cron monitoring into a single, simple to use platform. Our mission: to tame production and make you a better, more productive developer.

Learn more
author photo

Robert Carpenter

My name is Robert Carpenter. I build web applications, automate clouds, compile and analyze data, and spend way too much time thinking about software.

“We've looked at a lot of error management systems. Honeybadger is head and shoulders above the rest and somehow gets better with every new release.” 
Michael Smith
Try Error Monitoring Free for 15 Days