Ruby Frameworks

Ruby Frameworks

How do I use Scout with Sinatra?

Sinatra instrumentation is similar to Rack. After installing the gem and configuring:

  1. Add the startup call in your config.ru:
require'./main'require'scout_apm'ScoutApm::Rack.install!run Sinatra::Application
  1. 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:

  1. Configure: Create config/scout_apm.yml or use environment variables
  2. Start the agent in config.ru:
require'scout_apm'ScoutApm::Rack.install!run MyApp
  1. 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:

  1. Download the Sneakers integration code from Scout’s documentation
  2. Place it in your /lib folder
  3. In config/boot.rb , add: require File.expand_path('lib/scout_sneakers.rb', __FILE__)
  4. In your Worker class, after the work method, add:
classBaseWorkerincludeSneakers::Workerdef work(attributes)# Do workendincludeScoutApm::BackgroundJobIntegrations::Sneakers::Instrumentsend