Skip to content

Commit

Permalink
Check redis-client gem version to prevent error
Browse files Browse the repository at this point in the history
Version 0.14.0 of the redis-client gem introduced the `@config` object
we rely on in our instrumentation. Add a check using the version number
to make sure we only include our instrumentation on versions that
include this. This will avoid errors from occurring in the
instrumentation itself.

Fixes #1048
  • Loading branch information
tombruijn committed Apr 11, 2024
1 parent f72df40 commit 3946f3f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changesets/check-redis-client-version.md
@@ -0,0 +1,6 @@
---
bump: "patch"
type: "fix"
---

Check the redis-client gem version before installing instrumentation. This prevents errors from being raised on redis-client gem versions older than 0.14.0.
1 change: 1 addition & 0 deletions lib/appsignal/hooks/redis_client.rb
Expand Up @@ -8,6 +8,7 @@ class RedisClientHook < Appsignal::Hooks::Hook

def dependencies_present?
defined?(::RedisClient) &&
Gem::Version.new(::RedisClient::VERSION) >= Gem::Version.new("0.14.0") &&
Appsignal.config &&
Appsignal.config[:instrument_redis]
end
Expand Down
22 changes: 19 additions & 3 deletions spec/lib/appsignal/hooks/redis_client_spec.rb
Expand Up @@ -4,12 +4,28 @@
end

if DependencyHelper.redis_client_present?
context "with redis_client" do
context "with redis-client" do
context "with instrumentation enabled" do
describe "#dependencies_present?" do
subject { described_class.new.dependencies_present? }

it { is_expected.to be_truthy }
context "with gem version new than 0.14.0" do
before { stub_const("RedisClient::VERSION", "1.2.3") }

it { is_expected.to be_truthy }
end

context "with gem version 0.14.0" do
before { stub_const("RedisClient::VERSION", "0.14.0") }

it { is_expected.to be_truthy }
end

context "with gem version older than 0.14.0" do
before { stub_const("RedisClient::VERSION", "0.13.9") }

it { is_expected.to be_falsy }
end
end

context "with rest-client gem" do
Expand Down Expand Up @@ -211,7 +227,7 @@ def write(_commands)
end
end
else
context "without redis" do
context "without redis-client" do
describe "#dependencies_present?" do
subject { described_class.new.dependencies_present? }

Expand Down

0 comments on commit 3946f3f

Please sign in to comment.