honeycombio/beeline-ruby

Way to completely disable in test environment?

Closed this issue · 2 comments

Hi, thanks for creating this gem, overall it was easy to set up!

This is kind of an edge case, but wanted to report it. In our app we're stubbing SecureRandom.hex to ensure some deterministic values for testing. It appears that the beeline-ruby gem also uses it since we are now getting a few test failures in those specs.

The easy fix (which I'll probably do for now) would be to stub those calls as well. I'm wondering though if there is way to disable generating spans / random ids completely if the write key is not specified or if there is a different configuration value set. Then the test setup would not need to know about a gem that it doesn't rely on.

Quick example of my test setup diff:

    before do
+     # otherwise honeycomb random generation will cause this test to break
+     allow(SecureRandom).to receive(:hex).with(16).and_call_original
+     allow(SecureRandom).to receive(:hex).with(8).and_call_original

      # since this is random, stub it with a known value for asserting
      allow(SecureRandom).to receive(:hex).with(5) { 'abcde12345' }
    end

I think I figured out a good approach. While there is no configuration to disable, if you don't configure the gem, it appears not to do anything. So I did something like the following in config/initializers/honeycomb.rb:

if Rails.env.production? && ENV['HONEYCOMB_WRITE_KEY'].present?
  Honeycomb.configure do |config|
    ...

Will close for now since the immediate concern is addressed. Thanks!