Sha256: 9f2930c8b5e3bf9e43e19a70b02d6a4d6027851e25cbe4d2b5881f67fa7eb83a

Contents?: true

Size: 1.24 KB

Versions: 7

Compression:

Stored size: 1.24 KB

Contents

ifdef::env-github[]
NOTE: For the best reading experience,
please view this documentation at
https://www.elastic.co/guide/en/apm/agent/ruby/current/introduction.html[elastic.co]
endif::[]

[[getting-started-rack]]
== Getting started with Rack

Add the gem to your `Gemfile`:

[source,ruby]
----
gem 'elastic-apm'
----

Create a file `config/elastic_apm.yml`:

[source,yaml]
----
server_url: http://localhost:8100
secret_token: ''
----

Include the middleware, start (and stop) Elastic APM when booting your app:

[source,ruby]
----
# 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 }
----

[float]
[[getting-started-sinatra]]
==== Sinatra example

[source,ruby]
----
# 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 }
----

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
elastic-apm-2.6.1 docs/getting-started-rack.asciidoc
elastic-apm-2.6.0 docs/getting-started-rack.asciidoc
elastic-apm-2.5.0 docs/getting-started-rack.asciidoc
elastic-apm-2.4.0 docs/getting-started-rack.asciidoc
elastic-apm-2.3.1 docs/getting-started-rack.asciidoc
elastic-apm-2.3.0 docs/getting-started-rack.asciidoc
elastic-apm-2.2.0 docs/getting-started-rack.asciidoc