class OpenTracing::Instrumentation::Redis::TracingDriverWrapper

TracingDriverWrapper wrap redis driver

Constants

DEAFULT_BACKGROUND_DRIVER

Attributes

connection[R]
error_writer[R]
pipeline_scope[R]
span_builder[R]

Public Class Methods

connect(options) click to toggle source
# File lib/opentracing/instrumentation/redis/tracing_driver_wrapper.rb, line 16
def connect(options)
  connection = connect_backround_driver(options)

  span_builder = options.fetch(:span_builder, SpanBuilder.new)

  new(
    connection: connection,
    span_builder: span_builder,
    host: options[:host],
    port: options[:port],
  )
end
new( connection:, span_builder:, host:, port: ) click to toggle source
# File lib/opentracing/instrumentation/redis/tracing_driver_wrapper.rb, line 41
def initialize(
  connection:,
  span_builder:,
  host:,
  port:
)
  @connection = connection
  @span_builder = span_builder
  @host = host
  @port = port
end

Private Class Methods

connect_backround_driver(options) click to toggle source
# File lib/opentracing/instrumentation/redis/tracing_driver_wrapper.rb, line 31
def connect_backround_driver(options)
  background_driver =
    options.fetch(:background_driver, DEAFULT_BACKGROUND_DRIVER)
  background_driver.connect(options)
end

Public Instance Methods

read() click to toggle source
# File lib/opentracing/instrumentation/redis/tracing_driver_wrapper.rb, line 69
def read
  scope = pipeline_scope
  connection.read.tap do |reply|
    span_builder.write_log_reply(scope.span, reply) if scope
  end
rescue StandardError => e
  span_builder.write_error(scope.span, e, event: EVENT_READ) if scope
  raise
ensure
  close_pipeline_scope
end
write(command) click to toggle source
# File lib/opentracing/instrumentation/redis/tracing_driver_wrapper.rb, line 58
def write(command)
  scope = start_pipeline_scope(command)
  connection.write(command).tap do
    span_builder.write_log_command(scope.span, command) if scope
  end
rescue StandardError => e
  span_builder.write_error(scope.span, e, event: EVENT_WRITE) if scope
  close_pipeline_scope
  raise
end

Private Instance Methods

close_pipeline_scope() click to toggle source
# File lib/opentracing/instrumentation/redis/tracing_driver_wrapper.rb, line 109
def close_pipeline_scope
  return unless @pipeline_scope

  @pipeline_queue_size -= 1

  return if @pipeline_queue_size.positive?

  @pipeline_scope.close
  @pipeline_scope = nil
end
new_pipeline_scope(command) click to toggle source
# File lib/opentracing/instrumentation/redis/tracing_driver_wrapper.rb, line 99
def new_pipeline_scope(command)
  @pipeline_queue_size = 1
  @pipeline_scope =
    span_builder.start_active_scope(
      command,
      connection.class,
      peer_addr,
    )
end
peer_addr() click to toggle source
# File lib/opentracing/instrumentation/redis/tracing_driver_wrapper.rb, line 86
def peer_addr
  "#{@host}:#{@port}"
end
start_pipeline_scope(command) click to toggle source
# File lib/opentracing/instrumentation/redis/tracing_driver_wrapper.rb, line 90
def start_pipeline_scope(command)
  if @pipeline_scope
    @pipeline_queue_size += 1
    return @pipeline_scope
  end

  new_pipeline_scope(command)
end