Skip to content

Commit

Permalink
fix: resolve Dalli::Server deprecation in 3.0+ (#1015)
Browse files Browse the repository at this point in the history
Co-authored-by: Francis Bogsanyi <francis.bogsanyi@shopify.com>
  • Loading branch information
tierra and fbogsany committed Nov 16, 2021
1 parent c1c35d3 commit 9428b4e
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 6 deletions.
4 changes: 4 additions & 0 deletions instrumentation/dalli/Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
appraise 'dalli-2.7' do
gem 'dalli', '~> 2.7'
end

appraise 'dalli-3.0' do
gem 'dalli', '~> 3.0'
end
3 changes: 3 additions & 0 deletions instrumentation/dalli/gemfiles/dalli_2.7.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
source "https://rubygems.org"

gem "opentelemetry-api", path: "../../../api"
gem "opentelemetry-instrumentation-base", path: "../../base"
gem "dalli", "~> 2.7"

group :test do
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-sdk", path: "../../../sdk"
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
gem "pry"
end

Expand Down
16 changes: 16 additions & 0 deletions instrumentation/dalli/gemfiles/dalli_3.0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "opentelemetry-api", path: "../../../api"
gem "opentelemetry-instrumentation-base", path: "../../base"
gem "dalli", "~> 3.0"

group :test do
gem "opentelemetry-common", path: "../../../common"
gem "opentelemetry-sdk", path: "../../../sdk"
gem "opentelemetry-semantic_conventions", path: "../../../semantic_conventions"
gem "pry"
end

gemspec path: "../"
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ def require_dependencies
end

def add_patches
::Dalli::Server.prepend(Patches::Server)
if Gem::Version.new(::Dalli::VERSION) < Gem::Version.new('3.0.0')
::Dalli::Server.prepend(Patches::Server)
else
::Dalli::Protocol::Binary.prepend(Patches::Server)
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module OpenTelemetry
module Instrumentation
module Dalli
module Patches
# Module to prepend to Dalli::Server for instrumentation
# Module to prepend to Dalli::Server (or Dalli::Protocol::Binary in 3.0+) for instrumentation
module Server
def request(op, *args)
operation = Utils.opname(op, multi?)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Gem::Specification.new do |spec|

spec.add_development_dependency 'appraisal', '~> 2.2.0'
spec.add_development_dependency 'bundler', '>= 1.17'
spec.add_development_dependency 'dalli', '~> 2.7'
spec.add_development_dependency 'dalli', '>= 2.7'
spec.add_development_dependency 'minitest', '~> 5.0'
spec.add_development_dependency 'opentelemetry-sdk', '~> 1.0'
spec.add_development_dependency 'rubocop', '~> 0.73.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
dalli.set('foo', 'bar')
exporter.reset

dalli.instance_variable_get(:@ring).servers.first.stub(:write, ->(_bytes) { raise Dalli::NetworkError }) do
dalli.instance_variable_get(:@ring).servers.first.stub(:write, ->(_bytes) { raise Dalli::DalliError }) do
dalli.get_multi('foo', 'bar')
end

Expand All @@ -93,8 +93,8 @@

span_event = span.events.first
_(span_event.name).must_equal 'exception'
_(span_event.attributes['exception.type']).must_equal 'Dalli::NetworkError'
_(span_event.attributes['exception.message']).must_equal 'Dalli::NetworkError'
_(span_event.attributes['exception.type']).must_equal 'Dalli::DalliError'
_(span_event.attributes['exception.message']).must_equal 'Dalli::DalliError'
end

it 'omits db.statement' do
Expand Down

0 comments on commit 9428b4e

Please sign in to comment.