lib/opentracing/instrumentation/thrift/traced_protocol.rb in opentracing-instrumentation-0.1.14 vs lib/opentracing/instrumentation/thrift/traced_protocol.rb in opentracing-instrumentation-0.1.15
- old
+ new
@@ -31,87 +31,96 @@
def initialize(protocol, config: TracedProtocolConfig.new)
super(protocol)
@config = config.dup
yield @config if block_given?
- @static_tags = config.tags_builder.build_static_tags(protocol)
+ @protocol_tags = config.tags_builder.build_protocol_tags(protocol)
end
+ def ==(other)
+ protocol == other.protocol &&
+ config == other.config &&
+ protocol_tags == other.protocol_tags
+ end
+
def write_message_begin(name, type, seqid)
- self.write_scope = \
- safe_start_active_span(WRITE_DIRECTION, name, type)
+ 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_scope&.span, e)
- safe_close_span(write_scope)
+ write_error(write_span, e)
+ safe_close_span(write_span)
raise e
end
def write_message_end
super
ensure
- safe_close_span(write_scope)
+ safe_close_span(write_span)
end
def read_message_begin
start_time = Time.now.utc
name, type, rseqid = super
- self.read_scope = \
- safe_start_active_span(READ_DIRECTION, name, type,
- start_time: start_time)
+ self.read_span = \
+ safe_start_span(READ_DIRECTION, name, type,
+ start_time: start_time)
[name, type, rseqid]
end
def read_message_end
super
ensure
- safe_close_span(read_scope)
+ safe_close_span(read_span)
end
- private
+ protected
- attr_reader :static_tags
+ attr_reader :protocol_tags
attr_reader :protocol
+ attr_reader :config
- def_delegators :@config,
+ private
+
+ def_delegators :config,
:tracer,
:tags_builder,
:operation_name_builder,
:error_writer,
:logger
- attr_accessor :write_scope,
- :read_scope
+ attr_accessor :write_span,
+ :read_span
- def safe_start_active_span(
+ 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_active_span(
+ tracer.start_span(
operation_name,
tags: request_tags,
start_time: start_time,
)
rescue StandardError => e
logger&.error(e)
end
- def safe_close_span(scope)
- return if scope.nil?
+ def safe_close_span(span)
+ return if span.nil?
- scope.close
+ span.finish
rescue StandardError => e
logger&.error(e)
end
def write_error(span, exception)
@@ -129,10 +138,10 @@
type,
)
end
def build_tags(name, type)
- static_tags
+ protocol_tags
.merge(tags_builder.build_message_tags(name, type))
.compact
end
end
end