From 7b0293eead56bb21eae64897b35b115a96f29ca1 Mon Sep 17 00:00:00 2001 From: Kayla Reopelle Date: Fri, 14 Jun 2024 17:02:42 -0700 Subject: [PATCH 01/13] WIP: add support for redis clustering --- lib/new_relic/agent/instrumentation/redis.rb | 4 +-- .../instrumentation/redis/instrumentation.rb | 26 ++++++++++++------- .../agent/instrumentation/redis/middleware.rb | 8 ++++++ test/multiverse/suites/redis/Envfile | 7 ++++- 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/lib/new_relic/agent/instrumentation/redis.rb b/lib/new_relic/agent/instrumentation/redis.rb index ef609676ab..a57574cb8a 100644 --- a/lib/new_relic/agent/instrumentation/redis.rb +++ b/lib/new_relic/agent/instrumentation/redis.rb @@ -33,9 +33,7 @@ NewRelic::Agent.logger.info('Installing Redis Instrumentation') if NewRelic::Agent::Instrumentation::Redis::Constants::HAS_REDIS_CLIENT RedisClient.register(NewRelic::Agent::Instrumentation::RedisClient::Middleware) - end - - if use_prepend? + elsif use_prepend? prepend_instrument Redis::Client, NewRelic::Agent::Instrumentation::Redis::Prepend else chain_instrument NewRelic::Agent::Instrumentation::Redis::Chain diff --git a/lib/new_relic/agent/instrumentation/redis/instrumentation.rb b/lib/new_relic/agent/instrumentation/redis/instrumentation.rb index f8c02982cc..7d43f94caa 100644 --- a/lib/new_relic/agent/instrumentation/redis/instrumentation.rb +++ b/lib/new_relic/agent/instrumentation/redis/instrumentation.rb @@ -9,14 +9,14 @@ module Redis INSTRUMENTATION_NAME = NewRelic::Agent.base_name(name) def connect_with_tracing - with_tracing(Constants::CONNECT, database: db) { yield } + with_tracing(Constants::CONNECT, database: _nr_db) { yield } end def call_with_tracing(command, &block) operation = command[0] statement = ::NewRelic::Agent::Datastores::Redis.format_command(command) - with_tracing(operation, statement: statement, database: db) { yield } + with_tracing(operation, statement: statement, database: _nr_db) { yield } end # Used for Redis 4.x and 3.x @@ -24,22 +24,16 @@ def call_pipeline_with_tracing(pipeline) operation = pipeline.is_a?(::Redis::Pipeline::Multi) ? Constants::MULTI_OPERATION : Constants::PIPELINE_OPERATION statement = ::NewRelic::Agent::Datastores::Redis.format_pipeline_commands(pipeline.commands) - with_tracing(operation, statement: statement, database: db) { yield } + with_tracing(operation, statement: statement, database: _nr_db) { yield } end # Used for Redis 5.x+ def call_pipelined_with_tracing(pipeline) - db = begin - _nr_redis_client_config.db - rescue StandardError => e - NewRelic::Agent.logger.error("Failed to determine configured Redis db value: #{e.class} - #{e.message}") - nil - end operation = pipeline.flatten.include?('MULTI') ? Constants::MULTI_OPERATION : Constants::PIPELINE_OPERATION statement = ::NewRelic::Agent::Datastores::Redis.format_pipeline_commands(pipeline) - with_tracing(operation, statement: statement, database: db) { yield } + with_tracing(operation, statement: statement, database: _nr_db) { yield } end private @@ -94,5 +88,17 @@ def _nr_redis_client_config config end end + + def _nr_db + # db is a method on the Redis client in versions < 5.x + return db if respond_to?(:db) + + db = begin + _nr_redis_client_config.db + rescue StandardError => e + NewRelic::Agent.logger.error("Failed to determine configured Redis db value: #{e.class} - #{e.message}") + nil + end + end end end diff --git a/lib/new_relic/agent/instrumentation/redis/middleware.rb b/lib/new_relic/agent/instrumentation/redis/middleware.rb index ef55bb8010..6e7154dae7 100644 --- a/lib/new_relic/agent/instrumentation/redis/middleware.rb +++ b/lib/new_relic/agent/instrumentation/redis/middleware.rb @@ -8,9 +8,17 @@ module Middleware # This module is used to instrument Redis 5.x+ include NewRelic::Agent::Instrumentation::Redis + def call(*args, &block) + call_with_tracing(args[0]) { super } + end + def call_pipelined(*args, &block) call_pipelined_with_tracing(args[0]) { super } end + + def connect(*args, &block) + connect_with_tracing { super } + end end end end diff --git a/test/multiverse/suites/redis/Envfile b/test/multiverse/suites/redis/Envfile index 8969c4e42f..748e1c690d 100644 --- a/test/multiverse/suites/redis/Envfile +++ b/test/multiverse/suites/redis/Envfile @@ -4,6 +4,11 @@ instrumentation_methods :chain, :prepend +gemfile <<~RB + gem 'rack' + gem 'redis-clustering' +RB + REDIS_VERSIONS = [ [nil, 2.5], ['4.8.0', 2.4], @@ -14,7 +19,7 @@ def gem_list(redis_version = nil) <<~RB gem 'rack' gem 'redis'#{redis_version} - + RB end From 2b4c2ffa47cf4292866df6e76fd24d9f8b991e93 Mon Sep 17 00:00:00 2001 From: Kayla Reopelle Date: Thu, 20 Jun 2024 22:09:51 -0700 Subject: [PATCH 02/13] Install cluster middleware --- lib/new_relic/agent/instrumentation/redis.rb | 5 +++++ .../redis/cluster_middleware.rb | 20 +++++++++++++++++++ .../agent/instrumentation/redis/middleware.rb | 11 +++------- 3 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 lib/new_relic/agent/instrumentation/redis/cluster_middleware.rb diff --git a/lib/new_relic/agent/instrumentation/redis.rb b/lib/new_relic/agent/instrumentation/redis.rb index a57574cb8a..fb485a527a 100644 --- a/lib/new_relic/agent/instrumentation/redis.rb +++ b/lib/new_relic/agent/instrumentation/redis.rb @@ -10,6 +10,7 @@ require_relative 'redis/constants' require_relative 'redis/prepend' require_relative 'redis/middleware' +require_relative 'redis/cluster_middleware' DependencyDetection.defer do # Why not :redis? newrelic-redis used that name, so avoid conflicting @@ -33,6 +34,10 @@ NewRelic::Agent.logger.info('Installing Redis Instrumentation') if NewRelic::Agent::Instrumentation::Redis::Constants::HAS_REDIS_CLIENT RedisClient.register(NewRelic::Agent::Instrumentation::RedisClient::Middleware) + + if defined?(Redis::Cluster) + RedisClient.register(NewRelic::Agent::Instrumentation::RedisClient::ClusterMiddleware) + end elsif use_prepend? prepend_instrument Redis::Client, NewRelic::Agent::Instrumentation::Redis::Prepend else diff --git a/lib/new_relic/agent/instrumentation/redis/cluster_middleware.rb b/lib/new_relic/agent/instrumentation/redis/cluster_middleware.rb new file mode 100644 index 0000000000..9fe36ec9d5 --- /dev/null +++ b/lib/new_relic/agent/instrumentation/redis/cluster_middleware.rb @@ -0,0 +1,20 @@ +# This file is distributed under New Relic's license terms. +# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details. +# frozen_string_literal: true + +module NewRelic::Agent::Instrumentation + module RedisClient + module ClusterMiddleware + include NewRelic::Agent::Instrumentation::Redis + + # Can't access these in redis-clustering by prepending onto the same methods + def call(*args, &block) + call_with_tracing(args[0]) { super } + end + + def connect(*args, &block) + connect_with_tracing { super } + end + end + end +end diff --git a/lib/new_relic/agent/instrumentation/redis/middleware.rb b/lib/new_relic/agent/instrumentation/redis/middleware.rb index 6e7154dae7..d601fff9fb 100644 --- a/lib/new_relic/agent/instrumentation/redis/middleware.rb +++ b/lib/new_relic/agent/instrumentation/redis/middleware.rb @@ -6,19 +6,14 @@ module NewRelic::Agent::Instrumentation module RedisClient module Middleware # This module is used to instrument Redis 5.x+ + # + # It only instruments call_pipelined because connect and call are accessed + # too late in the stack to capture all errors include NewRelic::Agent::Instrumentation::Redis - def call(*args, &block) - call_with_tracing(args[0]) { super } - end - def call_pipelined(*args, &block) call_pipelined_with_tracing(args[0]) { super } end - - def connect(*args, &block) - connect_with_tracing { super } - end end end end From ac86f4b4d2867c378b1833df523b5437197f3633 Mon Sep 17 00:00:00 2001 From: Kayla Reopelle Date: Fri, 21 Jun 2024 15:18:39 -0700 Subject: [PATCH 03/13] Rubocop --- lib/new_relic/agent/instrumentation/redis/instrumentation.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/new_relic/agent/instrumentation/redis/instrumentation.rb b/lib/new_relic/agent/instrumentation/redis/instrumentation.rb index 7d43f94caa..8337eac124 100644 --- a/lib/new_relic/agent/instrumentation/redis/instrumentation.rb +++ b/lib/new_relic/agent/instrumentation/redis/instrumentation.rb @@ -29,7 +29,6 @@ def call_pipeline_with_tracing(pipeline) # Used for Redis 5.x+ def call_pipelined_with_tracing(pipeline) - operation = pipeline.flatten.include?('MULTI') ? Constants::MULTI_OPERATION : Constants::PIPELINE_OPERATION statement = ::NewRelic::Agent::Datastores::Redis.format_pipeline_commands(pipeline) From bcf6c903000d8092c29b1c3ef7862c3156d149c4 Mon Sep 17 00:00:00 2001 From: Kayla Reopelle Date: Fri, 21 Jun 2024 15:26:14 -0700 Subject: [PATCH 04/13] Remove unused variable --- lib/new_relic/agent/instrumentation/redis/instrumentation.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/new_relic/agent/instrumentation/redis/instrumentation.rb b/lib/new_relic/agent/instrumentation/redis/instrumentation.rb index 8337eac124..efa31df989 100644 --- a/lib/new_relic/agent/instrumentation/redis/instrumentation.rb +++ b/lib/new_relic/agent/instrumentation/redis/instrumentation.rb @@ -92,7 +92,7 @@ def _nr_db # db is a method on the Redis client in versions < 5.x return db if respond_to?(:db) - db = begin + begin _nr_redis_client_config.db rescue StandardError => e NewRelic::Agent.logger.error("Failed to determine configured Redis db value: #{e.class} - #{e.message}") From 1ad495e9855ba23eb72ae1bf9ffb8c7abd83c112 Mon Sep 17 00:00:00 2001 From: Kayla Reopelle Date: Wed, 26 Jun 2024 16:56:42 -0700 Subject: [PATCH 05/13] Add some config logging --- lib/new_relic/agent/instrumentation/redis.rb | 1 + lib/new_relic/agent/instrumentation/redis/instrumentation.rb | 2 ++ 2 files changed, 3 insertions(+) diff --git a/lib/new_relic/agent/instrumentation/redis.rb b/lib/new_relic/agent/instrumentation/redis.rb index fb485a527a..246e7a410a 100644 --- a/lib/new_relic/agent/instrumentation/redis.rb +++ b/lib/new_relic/agent/instrumentation/redis.rb @@ -36,6 +36,7 @@ RedisClient.register(NewRelic::Agent::Instrumentation::RedisClient::Middleware) if defined?(Redis::Cluster) + puts "REDIS CLUSTER DEFINED!" RedisClient.register(NewRelic::Agent::Instrumentation::RedisClient::ClusterMiddleware) end elsif use_prepend? diff --git a/lib/new_relic/agent/instrumentation/redis/instrumentation.rb b/lib/new_relic/agent/instrumentation/redis/instrumentation.rb index efa31df989..afc39ec0fd 100644 --- a/lib/new_relic/agent/instrumentation/redis/instrumentation.rb +++ b/lib/new_relic/agent/instrumentation/redis/instrumentation.rb @@ -38,6 +38,8 @@ def call_pipelined_with_tracing(pipeline) private def with_tracing(operation, statement: nil, database: nil) + puts "WALUIGI - OPERATION: #{operation}" + puts "WALUIGI - CLIENT CONFIG: #{client.config.inspect}" NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME) segment = NewRelic::Agent::Tracer.start_datastore_segment( From 75e08b9e4458398c5a7ae09b64adc97bc31ac0c5 Mon Sep 17 00:00:00 2001 From: Kayla Reopelle Date: Fri, 28 Jun 2024 17:10:47 -0700 Subject: [PATCH 06/13] Remove logging --- lib/new_relic/agent/instrumentation/redis/instrumentation.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/new_relic/agent/instrumentation/redis/instrumentation.rb b/lib/new_relic/agent/instrumentation/redis/instrumentation.rb index afc39ec0fd..efa31df989 100644 --- a/lib/new_relic/agent/instrumentation/redis/instrumentation.rb +++ b/lib/new_relic/agent/instrumentation/redis/instrumentation.rb @@ -38,8 +38,6 @@ def call_pipelined_with_tracing(pipeline) private def with_tracing(operation, statement: nil, database: nil) - puts "WALUIGI - OPERATION: #{operation}" - puts "WALUIGI - CLIENT CONFIG: #{client.config.inspect}" NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME) segment = NewRelic::Agent::Tracer.start_datastore_segment( From b317fa43315e45894ba07c1a38fab0771244528a Mon Sep 17 00:00:00 2001 From: Kayla Reopelle Date: Mon, 1 Jul 2024 16:52:31 -0700 Subject: [PATCH 07/13] Skip tests that fail on redis-clustering --- lib/new_relic/agent/instrumentation/redis.rb | 3 +-- .../instrumentation/redis/cluster_middleware.rb | 1 - .../suites/redis/redis_instrumentation_test.rb | 16 ++++++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/new_relic/agent/instrumentation/redis.rb b/lib/new_relic/agent/instrumentation/redis.rb index 246e7a410a..6c397ab59b 100644 --- a/lib/new_relic/agent/instrumentation/redis.rb +++ b/lib/new_relic/agent/instrumentation/redis.rb @@ -35,8 +35,7 @@ if NewRelic::Agent::Instrumentation::Redis::Constants::HAS_REDIS_CLIENT RedisClient.register(NewRelic::Agent::Instrumentation::RedisClient::Middleware) - if defined?(Redis::Cluster) - puts "REDIS CLUSTER DEFINED!" + if defined?(Redis::Cluster::Client) RedisClient.register(NewRelic::Agent::Instrumentation::RedisClient::ClusterMiddleware) end elsif use_prepend? diff --git a/lib/new_relic/agent/instrumentation/redis/cluster_middleware.rb b/lib/new_relic/agent/instrumentation/redis/cluster_middleware.rb index 9fe36ec9d5..849bb0e12a 100644 --- a/lib/new_relic/agent/instrumentation/redis/cluster_middleware.rb +++ b/lib/new_relic/agent/instrumentation/redis/cluster_middleware.rb @@ -7,7 +7,6 @@ module RedisClient module ClusterMiddleware include NewRelic::Agent::Instrumentation::Redis - # Can't access these in redis-clustering by prepending onto the same methods def call(*args, &block) call_with_tracing(args[0]) { super } end diff --git a/test/multiverse/suites/redis/redis_instrumentation_test.rb b/test/multiverse/suites/redis/redis_instrumentation_test.rb index bc88722d41..0d5a6a7420 100644 --- a/test/multiverse/suites/redis/redis_instrumentation_test.rb +++ b/test/multiverse/suites/redis/redis_instrumentation_test.rb @@ -59,6 +59,8 @@ def test_records_metrics_for_connect end def test_records_connect_tt_node_within_call_that_triggered_it + skip_for_redis_clustering_gem + in_transaction do redis = Redis.new redis.get('foo') @@ -277,6 +279,8 @@ def test_records_instance_parameters_on_tt_node_for_get end def test_records_hostname_on_tt_node_for_get_with_unix_domain_socket + skip_for_redis_clustering_gem + redis = Redis.new redis.send(client).stubs(:path).returns('/tmp/redis.sock') @@ -309,6 +313,8 @@ def test_records_instance_parameters_on_tt_node_for_multi end def test_records_hostname_on_tt_node_for_multi_with_unix_domain_socket + skip_for_redis_clustering_gem + redis = Redis.new redis.send(client).stubs(:path).returns('/tmp/redis.sock') @@ -327,6 +333,8 @@ def test_records_hostname_on_tt_node_for_multi_with_unix_domain_socket end def test_records_unknown_unknown_metric_when_error_gathering_instance_data + skip_for_redis_clustering_gem + redis = Redis.new redis.send(client).stubs(:path).raises(StandardError.new) in_transaction do @@ -347,6 +355,8 @@ def simulate_read_error end def test_noticed_error_at_segment_and_txn_on_error + skip_for_redis_clustering_gem + txn = nil begin in_transaction do |redis_txn| @@ -362,6 +372,8 @@ def test_noticed_error_at_segment_and_txn_on_error end def test_noticed_error_only_at_segment_on_error + skip_for_redis_clustering_gem + txn = nil in_transaction do |redis_txn| begin @@ -472,4 +484,8 @@ def either_hostname [NewRelic::Agent::Hostname.get, 'redis'] end end + + def skip_for_redis_clustering_gem + skip 'Incompatible with redis-clustering' if defined?(Redis::Cluster::Client) + end end From aea52de929cbdd3648b9d73e9aa73775cb51f566 Mon Sep 17 00:00:00 2001 From: Kayla Reopelle Date: Mon, 1 Jul 2024 16:58:59 -0700 Subject: [PATCH 08/13] Update --- lib/new_relic/agent/instrumentation/redis.rb | 6 ++++-- test/multiverse/suites/redis/Envfile | 14 +++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/new_relic/agent/instrumentation/redis.rb b/lib/new_relic/agent/instrumentation/redis.rb index 6c397ab59b..691c8e87c3 100644 --- a/lib/new_relic/agent/instrumentation/redis.rb +++ b/lib/new_relic/agent/instrumentation/redis.rb @@ -36,9 +36,11 @@ RedisClient.register(NewRelic::Agent::Instrumentation::RedisClient::Middleware) if defined?(Redis::Cluster::Client) - RedisClient.register(NewRelic::Agent::Instrumentation::RedisClient::ClusterMiddleware) + return RedisClient.register(NewRelic::Agent::Instrumentation::RedisClient::ClusterMiddleware) end - elsif use_prepend? + end + + if use_prepend? prepend_instrument Redis::Client, NewRelic::Agent::Instrumentation::Redis::Prepend else chain_instrument NewRelic::Agent::Instrumentation::Redis::Chain diff --git a/test/multiverse/suites/redis/Envfile b/test/multiverse/suites/redis/Envfile index 748e1c690d..9f9a56829c 100644 --- a/test/multiverse/suites/redis/Envfile +++ b/test/multiverse/suites/redis/Envfile @@ -4,11 +4,6 @@ instrumentation_methods :chain, :prepend -gemfile <<~RB - gem 'rack' - gem 'redis-clustering' -RB - REDIS_VERSIONS = [ [nil, 2.5], ['4.8.0', 2.4], @@ -24,3 +19,12 @@ def gem_list(redis_version = nil) end create_gemfiles(REDIS_VERSIONS) + +# We do not spin up a full Redis cluster in the testing environment, which +# limits our ability to run unit tests on the redis-clustering behavior. +# Since the testing capability is limited, only test the latest version of the +# redis-clustering gem. +gemfile <<~RB + gem 'rack' + gem 'redis-clustering' +RB From ee711e00c48c6a7f0a7df63d2769d8ac3d5ccf6c Mon Sep 17 00:00:00 2001 From: Kayla Reopelle Date: Tue, 2 Jul 2024 08:48:37 -0700 Subject: [PATCH 09/13] Add comment to ClusterMiddleware --- .../agent/instrumentation/redis/cluster_middleware.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/new_relic/agent/instrumentation/redis/cluster_middleware.rb b/lib/new_relic/agent/instrumentation/redis/cluster_middleware.rb index 849bb0e12a..5be2334b8b 100644 --- a/lib/new_relic/agent/instrumentation/redis/cluster_middleware.rb +++ b/lib/new_relic/agent/instrumentation/redis/cluster_middleware.rb @@ -7,6 +7,13 @@ module RedisClient module ClusterMiddleware include NewRelic::Agent::Instrumentation::Redis + # Until we decide to move our Redis instrumentation entirely off patches + # keep the middleware instrumentation for the call and connect methods + # limited to the redis-clustering instrumentation. + # + # Redis's middleware option does not capture errors as high in the stack + # as our patches. Leaving the patches for call and connect on the main + # Redis gem limits the feature disparity our customers experience. def call(*args, &block) call_with_tracing(args[0]) { super } end From 902eef0fa25f3a5256ae19f791a9b44cc08d666e Mon Sep 17 00:00:00 2001 From: Kayla Reopelle Date: Tue, 2 Jul 2024 08:58:54 -0700 Subject: [PATCH 10/13] Add Ruby version constraint for redis-clustering --- test/multiverse/suites/redis/Envfile | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/multiverse/suites/redis/Envfile b/test/multiverse/suites/redis/Envfile index 9f9a56829c..1f631f56f9 100644 --- a/test/multiverse/suites/redis/Envfile +++ b/test/multiverse/suites/redis/Envfile @@ -24,7 +24,9 @@ create_gemfiles(REDIS_VERSIONS) # limits our ability to run unit tests on the redis-clustering behavior. # Since the testing capability is limited, only test the latest version of the # redis-clustering gem. -gemfile <<~RB - gem 'rack' - gem 'redis-clustering' -RB +if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.0') + gemfile <<~RB + gem 'rack' + gem 'redis-clustering' + RB +end From e4a95b490b4d574d6bc5fa07d6f3aa67d2165379 Mon Sep 17 00:00:00 2001 From: "Kayla Reopelle (she/her)" <87386821+kaylareopelle@users.noreply.github.com> Date: Tue, 2 Jul 2024 13:41:58 -0700 Subject: [PATCH 11/13] Apply suggestions from code review Co-authored-by: James Bunch --- test/multiverse/suites/redis/Envfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/multiverse/suites/redis/Envfile b/test/multiverse/suites/redis/Envfile index 1f631f56f9..04d39db434 100644 --- a/test/multiverse/suites/redis/Envfile +++ b/test/multiverse/suites/redis/Envfile @@ -23,7 +23,7 @@ create_gemfiles(REDIS_VERSIONS) # We do not spin up a full Redis cluster in the testing environment, which # limits our ability to run unit tests on the redis-clustering behavior. # Since the testing capability is limited, only test the latest version of the -# redis-clustering gem. +# redis-clustering gem, which itself requires Ruby v2.7+. if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.0') gemfile <<~RB gem 'rack' From 982c3d2cc4490b9fbc976805bfc3527f884022cb Mon Sep 17 00:00:00 2001 From: Kayla Reopelle Date: Tue, 2 Jul 2024 16:32:18 -0700 Subject: [PATCH 12/13] Add changelog entry --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7f6e1094d..e03e3effcb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # New Relic Ruby Agent Release Notes +## + +Version improves instrumentation for the `redis-clustering` gem. + +- **Feature: Add instrumentation for redis-clustering** + + Version 5.x of the `redis` gem moved cluster behavior into a different gem, `redis-clustering`. This gem can access instrumentation registered through `RedisClient::Middleware`. Previously, the agent only instrumented the `call_pipelined` method through this approach, but now users of the `redis-clustering` gem will also have instrumentation registered for `connect` and `call` methods. In addition, the way the `database_name` attribute is set for Redis datastore spans is now compatible with all versions of Redis supported by the New Relic Ruby agent. Thank you, [@praveen-ks](https://github.com/praveen-ks) for bringing this to our attention. [Issue#2444](https://github.com/newrelic/newrelic-ruby-agent/issues/2444) [PR#2720](https://github.com/newrelic/newrelic-ruby-agent/pull/2720) + ## v9.11.0 Version 9.11.0 introduces instrumentation for the aws-sdk-sqs gem, fixes a bug related to expected errors not bearing a "true" value for the "expected" attribute if expected as a result of an HTTP status code match and changes the way Stripe instrumentation metrics are named to prevent high-cardinality issues. From 337f888423d489dcd5f1fa9151584ef096e2beec Mon Sep 17 00:00:00 2001 From: Kayla Reopelle Date: Wed, 3 Jul 2024 09:12:30 -0700 Subject: [PATCH 13/13] Refactor _nr_db * Log the failure message at the debug level * Check for the presence of the #db method on the client config object using respond_to? --- .../agent/instrumentation/redis/instrumentation.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/new_relic/agent/instrumentation/redis/instrumentation.rb b/lib/new_relic/agent/instrumentation/redis/instrumentation.rb index efa31df989..ca1ba59057 100644 --- a/lib/new_relic/agent/instrumentation/redis/instrumentation.rb +++ b/lib/new_relic/agent/instrumentation/redis/instrumentation.rb @@ -91,13 +91,11 @@ def _nr_redis_client_config def _nr_db # db is a method on the Redis client in versions < 5.x return db if respond_to?(:db) - - begin - _nr_redis_client_config.db - rescue StandardError => e - NewRelic::Agent.logger.error("Failed to determine configured Redis db value: #{e.class} - #{e.message}") - nil - end + # db is accessible through the RedisClient::Config object in versions > 5.x + return _nr_redis_client_config.db if _nr_redis_client_config.respond_to?(:db) + rescue StandardError => e + NewRelic::Agent.logger.debug("Failed to determine configured Redis db value: #{e.class} - #{e.message}") + nil end end end