Hanami

AppSignal for RubyThis feature requires version 3.3.0 or higher.
HanamiThis feature requires version 2 or higher.

Hanami are officially supported. Instrumenting Hanami applications requires some manual setup. Follow the installation steps in AppSignal, starting by clicking 'Add app' on the accounts screen.

Is your application using a combination of Grape, Hanami, Padrino or Sinatra? Follow our guide for instrumenting multiple Rack applications.

This page describes the integration for the Hanami framework, installed via the "hanami" gem. The Hanami::API framework (from the "hanami-api" gem) is not supported.

Installation

After installing the AppSignal gem, add the AppSignal integration after requiring hanami/boot in the config.ru file.

ruby
# config.ru require "appsignal" # Add this require require "hanami/boot" # Load the Hanami integration Appsignal.load(:hanami) # Start AppSignal Appsignal.start run Hanami.app # For Ruby gem 3.11 and older require "appsignal/integrations/hanami" # Add this line

Exception handling

Hanami doesn't have any exception handling by default. The web server (like Puma or Unicorn) will show a basic "internal server error" page if an error occurs in the app. These unhandled exceptions will be reported to AppSignal automatically.

The Hanami exception handling guide explains how to add custom exception handling to Hanami applications to render custom error pages. Handled exceptions will not be reported to AppSignal automatically.

We recommend adding the following code to the application's base Action class found in app/action.rb to add exception handling for StandardError. This way, adding exception handling to every action class is unnecessary.

In the handle_standard_error method, configured by handle_exception, call the Appsignal.set_error helper to report the exception to AppSignal and not miss any errors reported by your app.

ruby
# app/action.rb # auto_register: false # frozen_string_literal: true require "hanami/action" module MyHanamiApp class Action < Hanami::Action handle_exception StandardError => :handle_standard_error private def handle_standard_error(request, response, exception) # Report the error to AppSignal Appsignal.set_error(exception) # Render custom error page response.status = 500 response.body = "Sorry, something went wrong handling your request" end end end

After you add the Appsignal.set_error method to the Hanami exceptions you want to report, AppSignal will report these errors whenever they occur.