From 7fa32ae4be82bbec20ea0bb0fcdd53300f1244cc Mon Sep 17 00:00:00 2001 From: Vlado Cingel Date: Tue, 28 Jul 2026 17:32:58 +0200 Subject: [PATCH 1/2] Fallback to kicks gem for version check in SneakersSpy --- lib/elastic_apm/spies/sneakers.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/elastic_apm/spies/sneakers.rb b/lib/elastic_apm/spies/sneakers.rb index 76444f649..6c23f40ff 100644 --- a/lib/elastic_apm/spies/sneakers.rb +++ b/lib/elastic_apm/spies/sneakers.rb @@ -25,7 +25,8 @@ class SneakersSpy include Logging def self.supported_version? - Gem.loaded_specs['sneakers'].version >= Gem::Version.create('2.12.0') + spec = Gem.loaded_specs['sneakers'] || Gem.loaded_specs['kicks'] + spec.present? && spec.version >= Gem::Version.create('2.12.0') end def install From 38f3f8b692588ada3c151583753970f95e285466 Mon Sep 17 00:00:00 2001 From: Vlado Cingel Date: Wed, 29 Jul 2026 13:38:31 +0200 Subject: [PATCH 2/2] Add specs for sneaker spy changes --- Gemfile | 8 ++++++- lib/elastic_apm/spies/sneakers.rb | 4 +++- spec/elastic_apm/spies/sneakers_spec.rb | 30 ++++++++++++++++++++++--- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index 0d58288f1..3e392baca 100644 --- a/Gemfile +++ b/Gemfile @@ -168,7 +168,13 @@ end # sneakers main only supports >=2.5.0 if Gem::Version.create(RUBY_VERSION) >= Gem::Version.create('2.5.0') && !defined?(JRUBY_VERSION) - gem 'sneakers', github: 'jondot/sneakers', ref: 'd761dfe1493', require: nil + # The sneakers gem was renamed to kicks, which SneakersSpy also instruments. + # Set SNEAKERS_GEM=kicks to run the suite against it instead. + if ENV['SNEAKERS_GEM'] == 'kicks' + gem 'kicks', '>= 2.12.0', require: nil + else + gem 'sneakers', github: 'jondot/sneakers', ref: 'd761dfe1493', require: nil + end end if Gem::Version.create(RUBY_VERSION) <= Gem::Version.create('2.5.0') diff --git a/lib/elastic_apm/spies/sneakers.rb b/lib/elastic_apm/spies/sneakers.rb index 6c23f40ff..f5fbaf700 100644 --- a/lib/elastic_apm/spies/sneakers.rb +++ b/lib/elastic_apm/spies/sneakers.rb @@ -24,9 +24,11 @@ module Spies class SneakersSpy include Logging + # The sneakers gem was renamed to kicks, which still ships + # `lib/sneakers.rb` but registers under a different gem name. def self.supported_version? spec = Gem.loaded_specs['sneakers'] || Gem.loaded_specs['kicks'] - spec.present? && spec.version >= Gem::Version.create('2.12.0') + spec && spec.version >= Gem::Version.create('2.12.0') end def install diff --git a/spec/elastic_apm/spies/sneakers_spec.rb b/spec/elastic_apm/spies/sneakers_spec.rb index bf329dab4..4bb60ba91 100644 --- a/spec/elastic_apm/spies/sneakers_spec.rb +++ b/spec/elastic_apm/spies/sneakers_spec.rb @@ -18,9 +18,18 @@ # frozen_string_literal: true require 'spec_helper' -unless Gem::Specification.find_all_by_name('sneakers', '>=2.12.0').empty? || defined?(JRUBY_VERSION) +require 'elastic_apm/spies/sneakers' + +# The sneakers gem was renamed to kicks. Both ship `lib/sneakers.rb` and define +# the `Sneakers` constant, but register under different gem names, so either one +# satisfies the spy. +queue_gem_bundled = + !defined?(JRUBY_VERSION) && + !(Gem::Specification.find_all_by_name('sneakers', '>=2.12.0') + + Gem::Specification.find_all_by_name('kicks', '>=2.12.0')).empty? + +if queue_gem_bundled require 'sneakers' - require 'elastic_apm/spies/sneakers' module ElasticAPM RSpec.describe 'Spy: Sneakers', :intercept do @@ -70,6 +79,10 @@ def work(_message) Sneakers.logger = Logger.new(nil) # silence end + it 'supports the version of the gem in the bundle' do + expect(Spies::SneakersSpy.supported_version?).to be_truthy + end + it 'instruments job transaction' do with_agent do worker = TestWorker.new @@ -108,4 +121,15 @@ def work(_message) end end end -end \ No newline at end of file +elsif Gem.loaded_specs['sneakers'].nil? && Gem.loaded_specs['kicks'].nil? + # Neither gem is in the bundle (eg. JRuby, or Ruby below 2.5), so the spy has + # no gem spec to read a version from. It has to report the version as + # unsupported rather than raise. + module ElasticAPM + RSpec.describe 'Spy: Sneakers' do + it 'is unsupported when neither sneakers nor kicks is bundled' do + expect(Spies::SneakersSpy.supported_version?).to be_falsey + end + end + end +end