Skip to content

Instantly share code, notes, and snippets.

@samstokes
Created June 7, 2018 01:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samstokes/c6bfa6f6bf6102a5d0c5daee89e95fb1 to your computer and use it in GitHub Desktop.
Save samstokes/c6bfa6f6bf6102a5d0c5daee89e95fb1 to your computer and use it in GitHub Desktop.

Instrument Your Ruby App In Minutes with the Honeycomb Beeline for Ruby

You’ve always been able to get observability for your Ruby apps by instrumenting them with our SDK, affectionately known as libhoney. Unfortunately, instrumenting code you’ve already written is nobody’s favourite job. If only there were some way to automate the repetitive parts, so you could get instant insight into what your app is doing in production, and then focus your effort on augmenting that insight with the information that’s unique to your app!

Meet the Honeycomb Beeline for Ruby. Like our Beelines for Go and Node, it understands the common packages you're using and automatically instruments them to send useful events to Honeycomb. Then once you've got a chance to explore your app's behavior, you can add custom fields specific to your app with just one line of code.

What you'll need

  • A Ruby web app of your choice
  • Ruby 2.2+
  • A Honeycomb API key, found on your Honeycomb Account page. (Sign up for free if you haven't already!)

Setup

First add the Beeline to your Gemfile:

gem 'honeycomb-beeline'

Then call Honeycomb.init in your app's startup script (e.g. config.ru):

require 'honeycomb-beeline'
Honeycomb.init(writekey: 'abcabc123123defdef456456', dataset: 'myapp')

That's all you need for most web apps! The Beeline will automatically instrument your incoming HTTP requests, outbound requests, and database queries, and send events to Honeycomb. Check out the docs for more information on what's supported, and some example queries to try.

Explore!

Now that your app is instrumented, let's take a look at your data.

Log into Honeycomb. You should see a new myapp dataset waiting on your team homepage - let's open it and find out which endpoints were hit most often.

In the sidebar on the right, you'll see the schema from events that the Ruby Beeline has automatically sent into Honeycomb. Let's take a look at the data that was generated from your HTTP requests.

Screenshot of schema in sidebar

These look promising. Let's break down by request.method and request.path to get an overview of our app endpoints, and calculate the COUNT to find out how many times each endpoint was used.

Screenshot of query builder

That's all you need to start visualizing and investigating your app behavior in Honeycomb! Learn more here about exploring your data and constructing queries in Honeycomb.

Screenshot of query result

Customize

The real power of observability comes when you augment your instrumentation with context that's unique to your app. For example, let's say you'd like to deprecate an endpoint, and you want to know which users are using it. In your handler for that endpoint, you can add a custom field onto the event associated with the request:

Rack::Honeycomb.add_field(env, :user_id, current_user.id)

Enjoy!

Check out the Beeline documentation for more information on what else is supported.

Haven't tried Honeycomb before? Sign up for free!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment