Class: Trace::ZipkinSenderBase

Inherits:
Object
  • Object
show all
Defined in:
lib/zipkin-tracer/zipkin_sender_base.rb

Overview

This class is a base for senders sending information to Zipkin. It knows about zipkin types of annotations and send traces when the server is done with its request Senders dealing with zipkin should inherit from this class and implement the flush! method which actually sends the information

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ZipkinSenderBase

Returns a new instance of ZipkinSenderBase.



10
11
12
13
# File 'lib/zipkin-tracer/zipkin_sender_base.rb', line 10

def initialize(options = {})
  @options = options
  reset
end

Instance Method Details

#end_span(span, timestamp = Time.now) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/zipkin-tracer/zipkin_sender_base.rb', line 22

def end_span(span, timestamp = Time.now)
  span.close(timestamp)
  # If in a thread not handling incoming http requests, it will not have Kind::SERVER, so the span
  # will never be flushed and will cause memory leak.
  # If no parent span, then current span needs to flush when it ends.
  return if skip_flush?(span)

  flush!
  reset
end

#flush!Object



46
47
48
# File 'lib/zipkin-tracer/zipkin_sender_base.rb', line 46

def flush!
  raise "not implemented"
end

#skip_flush?(span) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
43
44
# File 'lib/zipkin-tracer/zipkin_sender_base.rb', line 40

def skip_flush?(span)
  return false if span.kind == Trace::Span::Kind::SERVER || span.kind == Trace::Span::Kind::CONSUMER

  spans.any? { |s| s.kind == Trace::Span::Kind::SERVER || s.kind == Trace::Span::Kind::CONSUMER }
end

#start_span(trace_id, name, timestamp = Time.now) ⇒ Object



33
34
35
36
37
38
# File 'lib/zipkin-tracer/zipkin_sender_base.rb', line 33

def start_span(trace_id, name, timestamp = Time.now)
  span = Span.new(name, trace_id, timestamp)
  span.local_endpoint = Trace.default_endpoint
  store_span(trace_id, span)
  span
end

#with_new_span(trace_id, name) ⇒ Object



15
16
17
18
19
20
# File 'lib/zipkin-tracer/zipkin_sender_base.rb', line 15

def with_new_span(trace_id, name)
  span = start_span(trace_id, name)
  result = yield span
  end_span(span)
  result
end