AppSignal  Docs

Visit AppSignal.com
Jump to navigation

Grape

Grape support is integrated in AppSignal Ruby gem versions 1.1 and up.

For older versions of the AppSignal Ruby gem, check grape-appsignal gem created by Mark Madsen.

Installation

A Grape application requires a few manual steps to get working.

  1. Create a config/appsignal.yml configuration file or configure it with environment variables. For more information see the Ruby configuration page.
  2. Make sure AppSignal is required, require "appsignal".
  3. Require the Grape integration, require "appsignal/integrations/grape".
  4. Start AppSignal, Appsignal.start.

A Grape config.ru file looks something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
# config.ru
require File.expand_path("../config/environment", __FILE__)
require_relative "./api.rb"

Appsignal.config = Appsignal::Config.new(
  File.expand_path("../", __FILE__), # The root of your app
  ENV["RACK_ENV"] # The environment of your app (development/production)
)

Appsignal.start_logger
Appsignal.start

run Acme::App

An example of a Grape api.rb file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# api.rb
# require these two files
require "appsignal"
require "appsignal/integrations/grape"

module Acme
  class API < Grape::API
    insert_before Grape::Middleware::Error, Appsignal::Grape::Middleware # Include this middleware

    prefix "api"
    format :json
    get "/" do
      { :message => "Hello world!" }
    end
  end
end

insert_before was introduced in Grape 0.19. If you use an earlier version use this approach:

1
use Appsignal::Grape::Middleware

After these steps, start your Grape application and wait for data to arrive in AppSignal.

Example app

We have an example application in our examples repository on GitHub. The example shows how to set up AppSignal with Grape.

Want to help us improve this documentation page? Create a pull request