IMPORTANT: No additional bug fixes or documentation updates
will be released for this version. For the latest information, see the
current release documentation.
Getting started with Rack
edit
IMPORTANT: This documentation is no longer updated. Refer to Elastic's version policy and the latest documentation.
Getting started with Rack
editAdd the gem to your Gemfile:
gem 'elastic-apm'
Create a file config/elastic_apm.yml:
server_url: http://localhost:8100 secret_token: ''
Include the middleware, start (and stop) Elastic APM when booting your app:
# config.ru
app = lambda do |env|
[200, {'Content-Type' => 'text/plain'}, ['ok']]
end
# Wraps all requests in transactions and reports exceptions
use ElasticAPM::Middleware
# Start an instance of the Agent
ElasticAPM.start(service_name: 'NothingButRack')
run app
# Gracefully stop the agent when process exits.
# Makes sure any pending transactions are sent.
at_exit { ElasticAPM.stop }
Sinatra example
edit# Example config.ru
require 'sinatra/base'
class MySinatraApp < Sinatra::Base
use ElasticAPM::Middleware
# ...
end
# Takes optional ElasticAPM::Config values
ElasticAPM.start(app: MySinatraApp, ...)
run MySinatraApp
at_exit { ElasticAPM.stop }