Since its release in early 2018, Elastic APM has had experimental support for Ruby. We're 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, it's 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 there's 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.
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:
The Ruby Agent expects an instance of APM Server to report to. If you haven't got one, it doesn't take much to set one up. When you're ready, point the agent at it by adding a config file to your app:
server_url: http://localhost:8200 # default secret_token: 'very secret' # if you APM Server is set up to use one
If your app isn't Rails, add the middleware where appropriate:
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 app's 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 Ruby's nature this is all done for you. For a list of supported libraries, see GitHub.
If you'd like even more information than what happens automatically (can't 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 'Slow block' do # ... it doesn't take more to instrument blocks of code end slow_method end private def slow_method # ... there's also a class level helper to wrap whole methods end span_method :slow_method end
Now, two additional spans will be added to each incoming request hitting ThingsController#index. Let's head over to Kibana's 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 we're just getting started. If you have any comments or feature requests to the project or APM in general, we'd 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. We've already had a few user submissions and it's never not exciting to get help or feedback from our amazing community!