Skip to content

Commit

Permalink
Fix Datadog.configure_onto(redis)
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyCTHsu committed Nov 14, 2022
1 parent 3ff2d1b commit 7b3b51d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/datadog/tracing/contrib/redis/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module InstanceMethods
def call(*args, &block)
response = nil
Tracing.trace(Contrib::Redis::Ext::SPAN_COMMAND) do |span|
span.service = Datadog.configuration_for(self, :service_name) || datadog_configuration[:service_name]
span.service = Datadog.configuration_for(redis_instance, :service_name) || datadog_configuration[:service_name]
span.span_type = Contrib::Redis::Ext::TYPE
span.resource = get_command(args)
Contrib::Redis::Tags.set_common_tags(self, span)
Expand All @@ -35,7 +35,7 @@ def call(*args, &block)
def call_pipeline(*args, &block)
response = nil
Tracing.trace(Contrib::Redis::Ext::SPAN_COMMAND) do |span|
span.service = Datadog.configuration_for(self, :service_name) || datadog_configuration[:service_name]
span.service = Datadog.configuration_for(redis_instance, :service_name) || datadog_configuration[:service_name]
span.span_type = Contrib::Redis::Ext::TYPE
commands = get_pipeline_commands(args)
span.resource = commands.any? ? commands.join("\n") : '(none)'
Expand Down
37 changes: 37 additions & 0 deletions lib/datadog/tracing/contrib/redis/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,38 @@ module Redis
module Patcher
include Contrib::Patcher

module InstancePatch
def self.included(base)
base.prepend(InstanceMethods)
end

module InstanceMethods
def initialize(options = {})
options[:redis_instance] = self

super(options)
end
end
end

module ClientPatch
def self.included(base)
base.prepend(InstanceMethods)
end

module InstanceMethods
def initialize(options = {})
@redis_instance = options[:redis_instance]

super(options)
end

private

attr_reader :redis_instance
end
end

module_function

def target_version
Expand All @@ -26,6 +58,11 @@ def patch
require_relative 'quantize'
require_relative 'instrumentation'

# InstancePatch and ClientPatch allows the client object to access pin on redis instance
::Redis.include(InstancePatch)
::Redis::Client.include(ClientPatch)

# TODO: To support redis-rb 5.x, Redis::Client -> RedisClient
::Redis::Client.include(Instrumentation)
end
end
Expand Down

0 comments on commit 7b3b51d

Please sign in to comment.