lib/request_tracer/trace.rb in request-tracer-0.5.5 vs lib/request_tracer/trace.rb in request-tracer-0.5.6
- old
+ new
@@ -26,19 +26,23 @@
elsif v.is_a?(SpanId)
v
end
end
+ attr_reader :value, :i64
def initialize(value)
@value = value
@i64 = if @value > MAX_SIGNED_I64
-1 * ((@value ^ MASK) + 1)
else
@value
end
end
+ def ==(other_span)
+ other_span&.value == @value
+ end
def to_s; "%016x" % @value; end
def to_i; @i64; end
end
# A trace is a set of spans that are associated with the same request
@@ -76,21 +80,19 @@
end
end
def create
span_id = generate_id
- trace_id = TraceId.new(span_id, nil, span_id)
- stack.push(trace_id)
- trace_id
+ TraceId.new(span_id, nil, span_id)
end
def latest
stack.last
end
def latest_or_create
- latest || create
+ latest || stack.push(create)
end
def push(trace_info)
trace = if trace_info.include?("trace_id") && trace_info.include?("span_id")
TraceId.create(trace_info)
@@ -125,10 +127,10 @@
end
end
end
def record(annotation = nil, &block)
- tracer.record(latest.next_id, annotation, &block)
+ tracer.record(latest&.next_id || create, annotation, &block)
end
def tracer=(tracer)
@tracer = tracer
end