Elastic APM Ruby Agent 1.0 is Generally Available | Elastic Blog

Elastic APM Ruby Agent 1.0 is Generally Available

Since its release in early 2018, Elastic APM has had experimental support for Ruby. Were thrilled to announce that the Ruby agent is now ready for GA its big 1.0.

If you are not already familiar with Elastic APM, its our open source Application Performance Monitoring solution for the Elastic Stack.

The Ruby Agent has been in beta since January and is already in use by some teams. We are now ready to commit to the API. That means theres no longer any reason to hold back if you are looking for a way to track what your application spends its time on and get a more accurate perception of how it reacts to your users and their (sometimes) mysterious ways.

Elastic APM also supports apps written in Node.js, Python, JavaScript/RUM (beta), Go (beta) and Java (alpha).

How to Instrument your Ruby App

Whether your app is based on Ruby on Rails or any other Rack-compatible server, Elastic APM will give you insights into your application right out of the box.

Start by adding the Rubygem to your Gemfile:

gem 'elastic-apm'

The Ruby Agent expects an instance of APM Server to report to. If you havent got one, it doesnt take much to set one up. When youre ready, point the agent at it by adding a config file to your app:

In config/elastic_apm.yml:

server_url: http://localhost:8200 # default
secret_token: 'very secret' # if you APM Server is set up to use one

If your app isnt Rails, add the middleware where appropriate:

use ElasticAPM::Middleware

Thats it!

By default the agent does nothing in development. To take it for a test run, add this setting to your config file:

server_url: http://localhost:8200 # default
secret_token: 'very secret' # if you APM Server is set up to use one
enabled_environments: ['production', 'development'] # default is ['production']

What it does

Out of the box, Elastic APM for Ruby instruments your apps incoming requests. To see how this looks, check out this intro to Elastic APM. It instruments database queries for the most popular libraries, outgoing web requests, background jobs and more. Due to Rubys nature this is all done for you. For a list of supported libraries, see GitHub.

If youd like even more information than what happens automatically (cant have enough!) Elastic APM for Ruby allows you to add custom instrumentation to any method or block of code:

class ThingsController < ApplicationController
  include ElasticAPM::SpanHelpers # optional, adds span_method helper

  def index
    ElasticAPM.span &apos;Slow block&apos; do
      # ... it doesn&apos;t take more to instrument blocks of code



  def slow_method
    # ... there&apos;s also a class level helper to wrap whole methods
  span_method :slow_method

Now, two additional spans will be added to each incoming request hitting ThingsController#index. Lets head over to Kibanas APM UI and see how glorious it looks already:


The future of Elastic APM for Ruby

Getting to 1.0 is obviously exciting, but we feel like were just getting started. If you have any comments or feature requests to the project or APM in general, wed love to hear from your in an issue on the GitHub repo or on our forums.

And as with most of the Elastic stack, all of this is Open Source. Weve already had a few user submissions and its never not exciting to get help or feedback from our amazing community!