Rack

Rack

Rack instrumentation is more explicit than Rails instrumentation, since Rack applications can take nearly any form. After installing our agent, instrumenting Rack is a three step process:

  1. Configuring the agent
  2. Starting the agent
  3. Wrapping endpoints in tracing

Configuration

Rack apps are configured using the same approach as a Rails app: either via a config/scout_apm.yml config file or environment variables.

Starting the Agent

Add the ScoutApm::Rack.install! startup call as close to the spot you run your Rack application as possible. install! should be called after you require other gems (ActiveRecord, Mongo, etc) to install instrumentation for those libraries.

# config.ru

require 'scout_apm'
ScoutApm::Rack.install!

run MyApp

Adding endpoints

Wrap each endpoint in a call to ScoutApm::Rack#transaction(name, env).

This may be fairly application specific in details.

Example:

app = Proc.new do |env|
  ScoutApm::Rack.transaction("API User Listing", env) do
    User.all.to_json
    ['200', {'Content-Type' => 'application/json'}, [users]]
  end
end

If you run into any issues, or want advice on naming or wrapping endpoints, contact us at support@scoutapm.com for additional help.