Honeykiq

Sidekiq → Honeycomb 🐝

Send Sidekiq related events to Honeycomb.

Installation

Add this line to your application's Gemfile:

gem 'honeykiq'

Usage

The library provides two use cases:

Honeykiq::ServerMiddleware

Add it to Sidekiq server middleware chain and pass a Libhoney::Client as shown below. It will send an event to Honeycomb once a job finishes or fails. Have a look at server_middleware.rb to see what kind of information we send.

Sidekiq.configure_server do |config|
  config.server_middleware do |chain|
    chain.add Honeykiq::ServerMiddleware,
      honey_client: Libhoney::Client.new(
        writekey: ENV.fetch('HONEYCOMB_WRITE_KEY'),
        dataset: ENV.fetch('HONEYCOMB_DATASET')
      )
  end
end

Note on long running jobs: If you have long running jobs an event is only sent to Honeycomb when it finishes so it may appear as no jobs are running. Also if the process gets a SIGKILL then no event is sent about that job and the job may keep retrying and not appear in Honeycomb. The PeriodicReporter should help with this but we are thinking of a nicer approach.

Honeykiq::PeriodicReporter

The periodic reporter should be scheduled to report every few seconds depending on your use case (e.g. 30 seconds). Every time the #report method is called it will send a total of 1 + P + Q events to Honeycomb where P and Q are the number of processes and queues respectively.

It sends three types of events: instance, process, and queue. Have a look at periodic_reporter.rb to see what kind of information we send for each type.

A simple setup using clockwork would look like this:

require 'clockwork'
require 'libhoney'
require 'honeykiq'

module Clockwork
  every(30, 'Honeykiq', thread: true) { SidekiqHealth.report }
end

module SidekiqHealth
  def self.report
    reporter.report
  end

  def self.reporter
    @reporter ||= Honeykiq::PeriodicReporter.new(honey_client: honey_client)
  end

  def self.honey_client
    Libhoney::Client.new(
      writekey: ENV.fetch('HONEYCOMB_WRITE_KEY'),
      dataset: ENV.fetch('HONEYCOMB_DATASET')
    )
  end
end

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/carwow/honeykiq.

License

The gem is available as open source under the terms of the MIT License.