Class: OpenTracing::Instrumentation::Redis::TracingDriverWrapper

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/opentracing/instrumentation/redis/tracing_driver_wrapper.rb

Overview

TracingDriverWrapper wrap redis driver

Constant Summary collapse

DEAFULT_BACKGROUND_DRIVER =
::Redis::Connection::Ruby

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection:, span_builder:, host:, port:) ⇒ TracingDriverWrapper

Returns a new instance of TracingDriverWrapper.



41
42
43
44
45
46
47
48
49
50
51
# 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

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



38
39
40
# File 'lib/opentracing/instrumentation/redis/tracing_driver_wrapper.rb', line 38

def connection
  @connection
end

#span_builderObject (readonly)

Returns the value of attribute span_builder.



38
39
40
# File 'lib/opentracing/instrumentation/redis/tracing_driver_wrapper.rb', line 38

def span_builder
  @span_builder
end

Class Method Details

.connect(options) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# 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

Instance Method Details

#readObject



69
70
71
72
73
74
75
76
77
78
79
# 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) ⇒ Object



58
59
60
61
62
63
64
65
66
67
# 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