Skip to content

Commit 1d47bbf

Browse files
fix: skip instrumenting dalli 4.2.0 (#1982)
* fix: skip instrumenting dalli 4.2.0 * rubocop * use compatible? block * Restrict gem install and update README * rubocop: alphabetize dependencies * Revert dependency changes, use compatiable block --------- Co-authored-by: Ariel Valentin <arielvalentin@users.noreply.github.com>
1 parent 1040b36 commit 1d47bbf

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

instrumentation/dalli/Appraisals

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# frozen_string_literal: true
22

3-
%w[2.7.0 3.2.0].each do |version|
3+
%w[2.7.0 3.2.0 4.1.0].each do |version|
44
appraise "dalli-#{version}" do
55
gem 'dalli', "~> #{version}"
66
end
77
end
88

9-
appraise 'dalli-latest' do
10-
gem 'dalli'
11-
end
9+
# Dalli 4.2.0+ has native OpenTelemetry support, so we no longer need
10+
# to test our instrumentation against it.
11+
# appraise 'dalli-latest' do
12+
# gem 'dalli'
13+
# end

instrumentation/dalli/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
The OpenTelemetry Dalli gem is a community maintained instrumentation for the [Dalli][dalli-home] Memcache client.
44

5+
## Dalli 4.2.0+ Native Integration
6+
7+
Dalli 4.2.0+ includes native OpenTelemetry instrumentation. For the best experience and continued support, we recommend:
8+
9+
- **Dalli < 4.2.0**: Use `opentelemetry-instrumentation-dalli` gem
10+
- **Dalli ≥ 4.2.0**: Use Dalli's built-in OpenTelemetry support (remove `opentelemetry-instrumentation-dalli` gem)
11+
12+
Community instrumentation is compatible with Dalli versions up to 4.1.x. Development of this gem is frozen for newer Dalli versions in favor of the native integration.
13+
514
## How do I get started?
615

716
Install the gem using:

instrumentation/dalli/lib/opentelemetry/instrumentation/dalli/instrumentation.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ module Dalli
1010
# The Instrumentation class contains logic to detect and install the Dalli
1111
# instrumentation
1212
class Instrumentation < OpenTelemetry::Instrumentation::Base
13+
MAX_VERSION = Gem::Version.new('4.1.0') # Dalli 4.2.0+ has native OpenTelemetry instrumentation
14+
1315
install do |_config|
1416
require_dependencies
1517
add_patches
@@ -19,18 +21,31 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base
1921
defined?(::Dalli)
2022
end
2123

24+
compatible do
25+
if gem_version > MAX_VERSION
26+
OpenTelemetry.logger.info("Dalli #{gem_version} has native OpenTelemetry support. Skipping community instrumentation.")
27+
return false
28+
end
29+
30+
true
31+
end
32+
2233
option :peer_service, default: nil, validate: :string
2334
option :db_statement, default: :obfuscate, validate: %I[omit obfuscate include]
2435

2536
private
2637

38+
def gem_version
39+
Gem::Version.new(::Dalli::VERSION)
40+
end
41+
2742
def require_dependencies
2843
require_relative 'utils'
2944
require_relative 'patches/server'
3045
end
3146

3247
def add_patches
33-
if Gem::Version.new(::Dalli::VERSION) < Gem::Version.new('3.0.0')
48+
if gem_version < Gem::Version.new('3.0.0')
3449
::Dalli::Server.prepend(Patches::Server)
3550
else
3651
::Dalli::Protocol::Binary.prepend(Patches::Server) if defined?(::Dalli::Protocol::Binary)

0 commit comments

Comments
 (0)