Ruby Frameworks
Ruby Frameworks
How do I use Scout with Sinatra?
Sinatra instrumentation is similar to Rack. After installing the gem and configuring:
- Add the startup call in your config.ru:
require'./main'require'scout_apm'ScoutApm::Rack.install!run Sinatra::Application
- Wrap each endpoint with transaction tracking:
get '/'doScoutApm::Rack.transaction("get /", request.env) do"Hello!"endend
Call install! after requiring other gems (ActiveRecord, Mongo, etc.) to instrument those libraries.
How do I use Scout with a generic Rack application?
Rack instrumentation involves three steps:
- Configure: Create
config/scout_apm.ymlor use environment variables - Start the agent in config.ru:
require'scout_apm'ScoutApm::Rack.install!run MyApp
- Wrap endpoints :
app =Proc.newdo|env|ScoutApm::Rack.transaction("API User Listing", env) do['200', {'Content-Type'=>'application/json'}, [users.to_json]]endend
The transaction method takes a name (unchanging string describing the endpoint) and the rack environment hash.
Does Scout automatically instrument ActionController::Metal?
Yes, as of agent version 2.1.26, ActionController::Metal and ActionController::Api controllers are automatically instrumented. No additional configuration is needed.
How do I instrument Sneakers (RabbitMQ)?
Scout doesn’t automatically instrument Sneakers. To add instrumentation:
- Download the Sneakers integration code from Scout’s documentation
- Place it in your
/libfolder - In
config/boot.rb, add:require File.expand_path('lib/scout_sneakers.rb', __FILE__) - In your Worker class, after the
workmethod, add:
classBaseWorkerincludeSneakers::Workerdef work(attributes)# Do workendincludeScoutApm::BackgroundJobIntegrations::Sneakers::Instrumentsend