From 857ee1d79a3b69149928abc6ef7b63e65a60c9d5 Mon Sep 17 00:00:00 2001 From: Robb Kidd Date: Wed, 6 Mar 2024 15:41:33 -0500 Subject: [PATCH 1/4] remove duplicated classic key detect logic --- lib/honeycomb/client.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/honeycomb/client.rb b/lib/honeycomb/client.rb index c87de4c2..98b4e6a0 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 From 0cd4d188940ef9c37361ddc52756f6d811d71d38 Mon Sep 17 00:00:00 2001 From: Robb Kidd Date: Wed, 6 Mar 2024 16:13:59 -0500 Subject: [PATCH 2/4] spec classic? method behavior directly; use stub for classic/not-classic in other tests --- spec/honeycomb/configuration_spec.rb | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/spec/honeycomb/configuration_spec.rb b/spec/honeycomb/configuration_spec.rb index 8a792a3b..a0f8db5c 100644 --- a/spec/honeycomb/configuration_spec.rb +++ b/spec/honeycomb/configuration_spec.rb @@ -43,8 +43,26 @@ 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 false with an E&S key" do + configuration.write_key = "1234567890123456789012" + 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 +79,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 +125,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 From 0021baca1abf73b9f4ad448b12219086829f60e0 Mon Sep 17 00:00:00 2001 From: Robb Kidd Date: Wed, 6 Mar 2024 16:22:05 -0500 Subject: [PATCH 3/4] spec the v3 key behavior --- spec/honeycomb/configuration_spec.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/spec/honeycomb/configuration_spec.rb b/spec/honeycomb/configuration_spec.rb index a0f8db5c..2b4f833f 100644 --- a/spec/honeycomb/configuration_spec.rb +++ b/spec/honeycomb/configuration_spec.rb @@ -54,10 +54,25 @@ 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 From 451b36d7778488a0a0ca9475699e618d4ac972a9 Mon Sep 17 00:00:00 2001 From: Robb Kidd Date: Thu, 7 Mar 2024 12:56:03 -0500 Subject: [PATCH 4/4] use Libhoney to check classic keys (min libhoney now 2.3.0) --- honeycomb-beeline.gemspec | 2 +- lib/honeycomb/configuration.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/honeycomb-beeline.gemspec b/honeycomb-beeline.gemspec index 3ba09443..930a8c0c 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/configuration.rb b/lib/honeycomb/configuration.rb index 06ce174f..973d446d 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