Class: Trace::Span
- Inherits:
-
Object
- Object
- Trace::Span
- Defined in:
- lib/zipkin-tracer/trace.rb
Overview
A span may contain many annotations This class is defined in finagle-thrift. We are adding extra methods here
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(name, span_id) ⇒ Span
constructor
A new instance of Span.
-
#record(value, endpoint = Trace.default_endpoint) ⇒ Object
We record information into spans, then we send these spans to zipkin.
- #record_local_component(value) ⇒ Object
- #record_tag(key, value, type = Trace::BinaryAnnotation::Type::STRING, endpoint = Trace.default_endpoint) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(name, span_id) ⇒ Span
Returns a new instance of Span.
21 22 23 24 25 26 27 28 29 |
# File 'lib/zipkin-tracer/trace.rb', line 21 def initialize(name, span_id) @name = name @span_id = span_id @annotations = [] @binary_annotations = [] @debug = span_id.debug? @timestamp = to_microseconds(Time.now) @duration = UNKNOWN_DURATION end |
Instance Method Details
#close ⇒ Object
31 32 33 |
# File 'lib/zipkin-tracer/trace.rb', line 31 def close @duration = to_microseconds(Time.now) - @timestamp end |
#record(value, endpoint = Trace.default_endpoint) ⇒ Object
We record information into spans, then we send these spans to zipkin
50 51 52 |
# File 'lib/zipkin-tracer/trace.rb', line 50 def record(value, endpoint = Trace.default_endpoint) annotations << Trace::Annotation.new(value, endpoint) end |
#record_local_component(value) ⇒ Object
58 59 60 |
# File 'lib/zipkin-tracer/trace.rb', line 58 def record_local_component(value) record_tag(BinaryAnnotation::LOCAL_COMPONENT, value) end |
#record_tag(key, value, type = Trace::BinaryAnnotation::Type::STRING, endpoint = Trace.default_endpoint) ⇒ Object
54 55 56 |
# File 'lib/zipkin-tracer/trace.rb', line 54 def record_tag(key, value, type = Trace::BinaryAnnotation::Type::STRING, endpoint = Trace.default_endpoint) binary_annotations << Trace::BinaryAnnotation.new(key, value, type, endpoint) end |
#to_h ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/zipkin-tracer/trace.rb', line 35 def to_h { name: @name, traceId: @span_id.trace_id.to_s, id: @span_id.span_id.to_s, parentId: @span_id.parent_id.nil? ? nil : @span_id.parent_id.to_s, annotations: @annotations.map(&:to_h), binaryAnnotations: @binary_annotations.map(&:to_h), timestamp: @timestamp, duration: @duration, debug: @debug } end |