Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve Dalli::Server deprecation in 3.0+ #1015

Merged
merged 2 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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