Product Updates   Instrumentation  

New features for Ruby and Rails applications with a new version of the Honeycomb Beeline for Ruby

By Martin Holman  |   Last modified on July 26, 2019

We are excited to announce a new version of the Honeycomb Beeline for Ruby!

This new version solidifies our Ruby support, providing out-of-the-box automatic instrumentation for additional frameworks and enhanced support for our currently supported frameworks. The goods:

  • Support for more rails versions 4.1-6
  • Presend/sample hooks
  • Rake integration
  • Active support integration
  • Warden/Devise integration
  • Trace fields
  • Rollup fields
  • More ergonomic API
  • Add fields to current span more easily
  • Support for non rack based applications
  • Trace aware deterministic sampling
  • Reduces/eliminates incompatibility issues with various gems

What you'll need

  • Ruby 2.2 or greater
  • A Honeycomb API key, found on your Honeycomb Team Settings page. (Sign up for free if you haven’t already!)

Set up the configuration

For Rails applications we now have a generator that creates  a configuration file for the Beeline.

bundle exec rails generate honeycomb YOUR_API_KEY --dataset rails

This generates a configuration file in config/initializers/honeycomb.rb with the Beeline pre-configured for your Rails application:

Honeycomb.configure do |config|
  config.write_key = "{YOUR_API_KEY}"
  config.dataset = "rails"
  config.notification_events = %w[

Instrument your app with relevant context

With the basic setup complete you will start seeing events and traces in your Honeycomb dashboard. From here,  you can start adding context to your events by adding custom fields to spans, and adding additional child spans to your traces:

def slow_operation
  Honeycomb.start_span(name: "slow_operation") do |span|
    # ... go on and do the slow opp, add more data along the way
    span.add_field("interesting_thing", "banana")

Any additional child spans you add this way will join the trace which is started by the web requests connecting  to your rails application.

Scrub data you don't want sent

Once you start instrumenting additional areas of your application, you might find there is information in your events that you wish to remove or scrub so that you don't send sensitive information to Honeycomb. For this purpose, we have added a presend_hook that allows you to manipulate any of the information that your application is generating before it is sent to Honeycomb:

Honeycomb.configure do |config|
  config.write_key = "{YOUR_API_KEY}"
  config.dataset = "rails"
  config.presend_hook do |fields|
    if fields.has_key? "app.credit_card_number"
      fields["app.credit_card_number"] = "[REDACTED]"

Sample your data to focus on what matters

Now that you have more events being sent to Honeycomb, you may want to explore the world of sampling. To help you with that, we have made the Ruby Beeline deterministic sampling "trace" aware so that the whole trace is now sampled (or not), allowing you to always see the complete trace in your Honeycomb dashboard.

To allow you to customize further, we added a sample_hook. In the following example we use this new hook to perform dynamic sampling using the app.response_code field on the events:

class CustomSampler
  extend Honeycomb::DeterministicSampler

  def self.sample(fields)
    case fields["app.response_code"]
    when 200
      rate = 100
      [should_sample(rate, fields["trace.trace_id"]), rate]
      [true, 1]

Honeycomb.configure do |config|
  config.write_key = "{YOUR_API_KEY}"
  config.dataset = "rails"
  config.sample_hook do |fields|

Want to go further?

If you want to customize your Beeline further, you can find the docs here.

Get started with automatic instrumentation for your language: check out our Beelines and sign up for a free trial!


Related Posts

Product Updates  

Feature Focus: April 2023

You know the old saying, I’m sure: “April deploys bring May joys.” Okay, maybe it doesn’t go exactly like that, but after reading what we’ve...

Product Updates  

Observability, Meet Natural Language Querying with Query Assistant 

Engineers know best. No machine or tool will ever match the context and capacity that engineers have to make judgment calls about what a system...

Product Updates  

Honeycomb’s Deployment Protection Rule for GitHub Actions

Honeycomb's Deployment Protection Rule for GitHub Actions quickly enables canary deployments by letting you use Honeycomb query results to prevent deploying to your next target...