class OpenTracing::Instrumentation::Redis::SpanBuilder

SpanBuilder create span with tags and logs

Constants

REDACTED_ARG

Public Class Methods

new( config: Config.new, error_writer: Common::ErrorWriter.new ) click to toggle source
# File lib/opentracing/instrumentation/redis/span_builder.rb, line 12
def initialize(
  config: Config.new,
  error_writer: Common::ErrorWriter.new
)
  @config = config
  @error_writer = error_writer
end

Public Instance Methods

build_tags(connection_class, peer_addr) click to toggle source
# File lib/opentracing/instrumentation/redis/span_builder.rb, line 39
def build_tags(connection_class, peer_addr)
  {
    'span.kind' => 'client',
    'component' => component,
    'peer.address' => peer_addr,
    'peer.service' => 'redis',
    'redis.driver' => connection_class.to_s,
  }.compact
end
start_active_scope(command, connection_class, peer_addr) click to toggle source
# File lib/opentracing/instrumentation/redis/span_builder.rb, line 30
def start_active_scope(command, connection_class, peer_addr)
  operation_name = build_operation_name(command)
  tags = build_tags(connection_class, peer_addr)
  tracer.start_active_span(
    operation_name,
    tags: tags,
  )
end
write_error_reply(span, reply) click to toggle source
# File lib/opentracing/instrumentation/redis/span_builder.rb, line 62
def write_error_reply(span, reply)
  return unless reply.is_a?(::Redis::CommandError)

  span.set_tag('error', true)
  span.log_kv(
    'error.kind': 'redis_error',
    message: reply.to_s,
    event: EVENT_READ,
  )
end
write_log_command(span, command) click to toggle source
# File lib/opentracing/instrumentation/redis/span_builder.rb, line 51
def write_log_command(span, command)
  command_name, *args = command
  args_value = log_args ? JSON.dump(args) : REDACTED_ARG * args.size

  span.log_kv(
    event: EVENT_WRITE,
    'redis.command': command_name,
    'redis.args': args_value,
  )
end
write_log_reply(span, reply) click to toggle source
# File lib/opentracing/instrumentation/redis/span_builder.rb, line 73
def write_log_reply(span, reply)
  write_error_reply(span, reply)

  return unless log_reply

  span.log_kv(
    event: EVENT_READ,
    'redis.reply': JSON.dump(reply),
  )
end

Private Instance Methods

build_operation_name(command) click to toggle source
# File lib/opentracing/instrumentation/redis/span_builder.rb, line 86
def build_operation_name(command)
  command_name, * = command
  format(operation_name_pattern, command: command_name)
end