Module: Datadog::Tracing::Contrib::Redis::TraceMiddleware

Defined in:
lib/datadog/tracing/contrib/redis/trace_middleware.rb

Overview

Instrumentation for Redis 5+

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(client, command, service_name, command_args) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/datadog/tracing/contrib/redis/trace_middleware.rb', line 27

def call(client, command, service_name, command_args)
  Tracing.trace(Redis::Ext::SPAN_COMMAND, type: Redis::Ext::TYPE, service: service_name) do |span|
    span.set_tag(Tracing::::Ext::TAG_SVC_SRC, Redis::Ext::TAG_COMPONENT)
    raw_command = get_command(command, true)
    span.resource = command_args ? raw_command : get_command(command, false)

    Contrib::Redis::Tags.set_common_tags(client, span, raw_command)

    yield
  end
end

.call_pipelined(client, commands, service_name, command_args) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/datadog/tracing/contrib/redis/trace_middleware.rb', line 39

def call_pipelined(client, commands, service_name, command_args)
  # `redis-client` sends its per-connection handshake (`HELLO`, `CLIENT SETINFO`/`SETNAME`)
  # as a pipeline through this same code path. Excluding those from resource naming keeps
  # the resource focused on application-issued commands (e.g. a lone `SELECT` prelude).
  traced_commands = commands.reject { |c| Contrib::Redis::Quantize.connection_setup_command?(c) }
  return yield if traced_commands.empty? && !commands.empty?

  Tracing.trace(Redis::Ext::SPAN_COMMAND, type: Redis::Ext::TYPE, service: service_name) do |span|
    span.set_tag(Tracing::::Ext::TAG_SVC_SRC, Redis::Ext::TAG_COMPONENT)
    raw_command = get_pipeline_commands(traced_commands, true)
    span.resource = command_args ? raw_command : get_pipeline_commands(traced_commands, false)

    span.set_metric Contrib::Redis::Ext::METRIC_PIPELINE_LEN, traced_commands.length

    Contrib::Redis::Tags.set_common_tags(client, span, raw_command)

    yield
  end
end

Instance Method Details

#call(command, redis_config) ⇒ Object

Instruments RedisClient::ConnectionMixin#call.



15
16
17
18
# File 'lib/datadog/tracing/contrib/redis/trace_middleware.rb', line 15

def call(command, redis_config)
  config = resolve(redis_config)
  TraceMiddleware.call(redis_config, command, config[:service_name], config[:command_args]) { super }
end

#call_pipelined(commands, redis_config) ⇒ Object

Instruments RedisClient::ConnectionMixin#call_pipelined.



21
22
23
24
# File 'lib/datadog/tracing/contrib/redis/trace_middleware.rb', line 21

def call_pipelined(commands, redis_config)
  config = resolve(redis_config)
  TraceMiddleware.call_pipelined(redis_config, commands, config[:service_name], config[:command_args]) { super }
end