diff --git a/honeycomb-beeline.gemspec b/honeycomb-beeline.gemspec index 3ba0944..930a8c0 100644 --- a/honeycomb-beeline.gemspec +++ b/honeycomb-beeline.gemspec @@ -37,7 +37,7 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] - spec.add_dependency "libhoney", ">= 1.14.2" + spec.add_dependency "libhoney", ">= 2.3.0" spec.add_development_dependency "appraisal" spec.add_development_dependency "bump" diff --git a/lib/honeycomb/client.rb b/lib/honeycomb/client.rb index c87de4c..98b4e6a 100644 --- a/lib/honeycomb/client.rb +++ b/lib/honeycomb/client.rb @@ -33,7 +33,7 @@ def initialize(configuration:) @libhoney.add_field "service.name", configuration.service_name @context = Context.new - @context.classic = classic_write_key?(configuration.write_key) + @context.classic = configuration.classic? @additional_trace_options = { presend_hook: configuration.presend_hook, @@ -128,9 +128,5 @@ def add_exception_data(span, exception) span.add_field("error_backtrace_limit", error_backtrace_limit) span.add_field("error_backtrace_total_length", exception.backtrace.length) end - - def classic_write_key?(write_key) - write_key.nil? || write_key.length == 32 - end end end diff --git a/lib/honeycomb/configuration.rb b/lib/honeycomb/configuration.rb index 06ce174..973d446 100644 --- a/lib/honeycomb/configuration.rb +++ b/lib/honeycomb/configuration.rb @@ -24,7 +24,7 @@ def initialize end def classic? - @write_key.nil? || @write_key.length == 32 + Libhoney.classic_api_key?(@write_key) end def service_name diff --git a/spec/honeycomb/configuration_spec.rb b/spec/honeycomb/configuration_spec.rb index 8a792a3..2b4f833 100644 --- a/spec/honeycomb/configuration_spec.rb +++ b/spec/honeycomb/configuration_spec.rb @@ -43,8 +43,41 @@ expect(configuration.write_key).to eq write_key end + describe "#classic?" do + it "is true when no key is set" do + configuration.write_key = nil + expect(configuration.classic?).to be true + end + + it "is true with a classic key" do + configuration.write_key = "c1a551c000d68f9ed1e96432ac1a3380" + expect(configuration.classic?).to be true + end + + it "is true with a classic v3 ingest key" do + configuration.write_key = "hcaic_1234567890123456789012345678901234567890123456789012345678" + expect(configuration.classic?).to be true + end + + it "is false with an E&S key" do + configuration.write_key = "1234567890123456789012" + expect(configuration.classic?).to be false + end + + it "is false with an E&S v3 ingest key" do + configuration.write_key = "hcaik_1234567890123456789012345678901234567890123456789012345678" + expect(configuration.classic?).to be false + end + + it "is false with a v3 key id only" do + configuration.write_key = "hcxik_12345678901234567890123456" + expect(configuration.classic?).to be false + end + end + describe "#service_name" do it "returns the default unknown-service: when not set" do + expect(configuration.instance_variable_get(:@service_name)).to be_nil # rspec is the expected process name because *this test suite* is rspec expect(configuration.service_name).to eq "unknown_service:rspec" end @@ -61,10 +94,12 @@ context "with a classic write key" do before do - configuration.write_key = "c1a551c000d68f9ed1e96432ac1a3380" + allow(configuration).to receive(:classic?).and_return(true) end it "returns the value of dataset when service_name isn't set" do + expect(configuration.instance_variable_get(:@service_name)).to be_nil + configuration.dataset = "a_dataset" expect(configuration.service_name).to eq "a_dataset" end @@ -105,11 +140,12 @@ context "with a classic write key" do before do - configuration.write_key = "c1a551c000d68f9ed1e96432ac1a3380" + allow(configuration).to receive(:classic?).and_return(true) end it "returns whatever dataset has been set" do expect(configuration.dataset).to be_nil + configuration.dataset = "a_dataset" expect(configuration.dataset).to eq "a_dataset" end