Class: Trace::Span
- Inherits:
-
Object
- Object
- Trace::Span
- Defined in:
- lib/zipkin-tracer/trace.rb
Overview
A span may contain many annotations
Defined Under Namespace
Constant Summary collapse
- STATUS_ERROR_REGEXP =
/\A(4.*|5.*)\z/.freeze
Instance Attribute Summary collapse
-
#annotations ⇒ Object
Returns the value of attribute annotations.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#kind ⇒ Object
Returns the value of attribute kind.
-
#local_endpoint ⇒ Object
Returns the value of attribute local_endpoint.
-
#name ⇒ Object
Returns the value of attribute name.
-
#remote_endpoint ⇒ Object
Returns the value of attribute remote_endpoint.
-
#tags ⇒ Object
Returns the value of attribute tags.
Instance Method Summary collapse
- #close(timestamp = Time.now) ⇒ Object
- #has_parent_span? ⇒ Boolean
-
#initialize(name, span_id, timestamp = Time.now) ⇒ Span
constructor
A new instance of Span.
-
#record(value) ⇒ Object
We record information into spans, then we send these spans to zipkin.
- #record_local_component(value) ⇒ Object
- #record_status(status) ⇒ Object
- #record_tag(key, value) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(name, span_id, timestamp = Time.now) ⇒ Span
Returns a new instance of Span.
200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/zipkin-tracer/trace.rb', line 200 def initialize(name, span_id, = Time.now) @name = name @span_id = span_id @kind = nil @local_endpoint = nil @remote_endpoint = nil @annotations = [] @tags = {} @debug = span_id.debug? @timestamp = to_microseconds() @duration = UNKNOWN_DURATION end |
Instance Attribute Details
#annotations ⇒ Object
Returns the value of attribute annotations.
198 199 200 |
# File 'lib/zipkin-tracer/trace.rb', line 198 def annotations @annotations end |
#debug ⇒ Object
Returns the value of attribute debug.
198 199 200 |
# File 'lib/zipkin-tracer/trace.rb', line 198 def debug @debug end |
#kind ⇒ Object
Returns the value of attribute kind.
198 199 200 |
# File 'lib/zipkin-tracer/trace.rb', line 198 def kind @kind end |
#local_endpoint ⇒ Object
Returns the value of attribute local_endpoint.
198 199 200 |
# File 'lib/zipkin-tracer/trace.rb', line 198 def local_endpoint @local_endpoint end |
#name ⇒ Object
Returns the value of attribute name.
198 199 200 |
# File 'lib/zipkin-tracer/trace.rb', line 198 def name @name end |
#remote_endpoint ⇒ Object
Returns the value of attribute remote_endpoint.
198 199 200 |
# File 'lib/zipkin-tracer/trace.rb', line 198 def remote_endpoint @remote_endpoint end |
#tags ⇒ Object
Returns the value of attribute tags.
198 199 200 |
# File 'lib/zipkin-tracer/trace.rb', line 198 def @tags end |
Instance Method Details
#close(timestamp = Time.now) ⇒ Object
213 214 215 |
# File 'lib/zipkin-tracer/trace.rb', line 213 def close( = Time.now) @duration = to_microseconds() - @timestamp end |
#has_parent_span? ⇒ Boolean
249 250 251 |
# File 'lib/zipkin-tracer/trace.rb', line 249 def has_parent_span? !@span_id.parent_id.nil? end |
#record(value) ⇒ Object
We record information into spans, then we send these spans to zipkin
237 238 239 |
# File 'lib/zipkin-tracer/trace.rb', line 237 def record(value) annotations << Trace::Annotation.new(value.to_s) end |
#record_local_component(value) ⇒ Object
245 246 247 |
# File 'lib/zipkin-tracer/trace.rb', line 245 def record_local_component(value) record_tag(Tag::LOCAL_COMPONENT, value) end |
#record_status(status) ⇒ Object
255 256 257 258 259 260 |
# File 'lib/zipkin-tracer/trace.rb', line 255 def record_status(status) return if status.nil? status = status.to_s record_tag(Tag::STATUS, status) record_tag(Tag::ERROR, status) if STATUS_ERROR_REGEXP.match(status) end |
#record_tag(key, value) ⇒ Object
241 242 243 |
# File 'lib/zipkin-tracer/trace.rb', line 241 def record_tag(key, value) @tags[key] = value.to_s end |
#to_h ⇒ Object
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/zipkin-tracer/trace.rb', line 217 def to_h h = { name: @name, traceId: @span_id.trace_id.to_s, id: @span_id.span_id.to_s, localEndpoint: @local_endpoint.to_h, timestamp: @timestamp, duration: @duration, debug: @debug } h[:parentId] = @span_id.parent_id.to_s unless @span_id.parent_id.nil? h[:kind] = @kind unless @kind.nil? h[:remoteEndpoint] = @remote_endpoint.to_h unless @remote_endpoint.nil? h[:annotations] = @annotations.map(&:to_h) unless @annotations.empty? h[:tags] = @tags unless @tags.empty? h[:shared] = true if @span_id.shared && @kind == Kind::SERVER h end |