Class: OpenTracing::Instrumentation::Redis::SpanBuilder
- Inherits:
-
Object
- Object
- OpenTracing::Instrumentation::Redis::SpanBuilder
- Extended by:
- Forwardable
- Defined in:
- lib/opentracing/instrumentation/redis/span_builder.rb
Overview
SpanBuilder create span with tags and logs
Constant Summary collapse
- REDACTED_ARG =
['*'].freeze
Instance Method Summary collapse
- #build_tags(connection_class, peer_addr) ⇒ Object
-
#initialize(config: Config.new, error_writer: Common::ErrorWriter.new) ⇒ SpanBuilder
constructor
A new instance of SpanBuilder.
- #start_active_scope(command, connection_class, peer_addr) ⇒ Object
- #write_error_reply(span, reply) ⇒ Object
- #write_log_command(span, command) ⇒ Object
- #write_log_reply(span, reply) ⇒ Object
Constructor Details
#initialize(config: Config.new, error_writer: Common::ErrorWriter.new) ⇒ SpanBuilder
Returns a new instance of SpanBuilder.
12 13 14 15 16 17 18 |
# 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 |
Instance Method Details
#build_tags(connection_class, peer_addr) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/opentracing/instrumentation/redis/span_builder.rb', line 39 def (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) ⇒ Object
30 31 32 33 34 35 36 37 |
# 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) = (connection_class, peer_addr) tracer.start_active_span( operation_name, tags: , ) end |
#write_error_reply(span, reply) ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# 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) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# 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) ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# 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 |