class OpenTracing::Instrumentation::Thrift::TracedProtocol
TracedProtocol
wrap any raw Thrift
protocol instance. Not thread safe!
Usage (without multiplexed):
buffered_transport = ::Thrift::BufferedTransport.new(transport) protocol = ::Thrift::BinaryProtocol.new(buffered_transport) traced_protocol = \ OpenTracing::Instrumentation::Thrift::TracedProtocol.new(protocol)
Usage (multiplexed):
buffered_transport = ::Thrift::BufferedTransport.new(transport) protocol = ::Thrift::BinaryProtocol.new(buffered_transport) traced_protocol = OpenTracing::Instrumentation::Thrift::TracedProtocol .new(protocol) multiplexed_protocol = ::Thrift::MultiplexedProtocol .new(traced_protocol, 'OrderService')
Constants
- READ_DIRECTION
- WRITE_DIRECTION
Attributes
config[R]
protocol[R]
read_span[RW]
write_span[RW]
Public Class Methods
new(protocol, config: TracedProtocolConfig.new) { |config| ... }
click to toggle source
Calls superclass method
# File lib/opentracing/instrumentation/thrift/traced_protocol.rb, line 32 def initialize(protocol, config: TracedProtocolConfig.new) super(protocol) @config = config.dup yield @config if block_given? @protocol_tags = config.tags_builder.build_protocol_tags(protocol) end
Public Instance Methods
==(other)
click to toggle source
# File lib/opentracing/instrumentation/thrift/traced_protocol.rb, line 39 def ==(other) protocol == other.protocol && config == other.config && protocol_tags == other.protocol_tags end
read_message_begin()
click to toggle source
Calls superclass method
# File lib/opentracing/instrumentation/thrift/traced_protocol.rb, line 64 def read_message_begin start_time = Time.now.utc name, type, rseqid = super self.read_span = \ safe_start_span(READ_DIRECTION, name, type, start_time: start_time) [name, type, rseqid] end
read_message_end()
click to toggle source
Calls superclass method
# File lib/opentracing/instrumentation/thrift/traced_protocol.rb, line 76 def read_message_end super ensure safe_close_span(read_span) end
write_message_begin(name, type, seqid)
click to toggle source
# File lib/opentracing/instrumentation/thrift/traced_protocol.rb, line 45 def write_message_begin(name, type, seqid) self.write_span = \ safe_start_span(WRITE_DIRECTION, name, type) # Call protocol instaed super, beacaus ProtocolDecorator do not # pass arguments to protocol.write_message_begin protocol.write_message_begin(name, type, seqid) rescue StandardError => e write_error(write_span, e) safe_close_span(write_span) raise e end
write_message_end()
click to toggle source
Calls superclass method
# File lib/opentracing/instrumentation/thrift/traced_protocol.rb, line 58 def write_message_end super ensure safe_close_span(write_span) end
Private Instance Methods
build_operation_name(direction, name, type)
click to toggle source
# File lib/opentracing/instrumentation/thrift/traced_protocol.rb, line 134 def build_operation_name(direction, name, type) operation_name_builder.build_operation_name( direction, name, type, ) end
safe_close_span(span)
click to toggle source
# File lib/opentracing/instrumentation/thrift/traced_protocol.rb, line 118 def safe_close_span(span) return if span.nil? span.finish rescue StandardError => e logger&.error(e) end
safe_start_span( direction, name, type, start_time: Time.now.utc )
click to toggle source
# File lib/opentracing/instrumentation/thrift/traced_protocol.rb, line 100 def safe_start_span( direction, name, type, start_time: Time.now.utc ) operation_name = build_operation_name(direction, name, type) request_tags = build_tags(name, type) tracer.start_span( operation_name, tags: request_tags, start_time: start_time, ) rescue StandardError => e logger&.error(e) end
write_error(span, exception)
click to toggle source
# File lib/opentracing/instrumentation/thrift/traced_protocol.rb, line 126 def write_error(span, exception) return if span.nil? error_writer.write_error(span, exception) rescue StandardError => e logger&.error(e) end