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:
- Configuring the agent
- Starting the agent
- 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.
- configuration file: create a
config/scout_apm.yml
file under your application root directory. The file structure is outlined here. - environment variables: see our docs on configuring the agent via 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)
.
name
- an unchanging string argument for what the endpoint is. Example:"API User Listing"
env
- the rack environment hash
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.