Class: Zipkin::Collector

Inherits:
Object
  • Object
show all
Defined in:
lib/zipkin/collector.rb

Defined Under Namespace

Classes: Buffer

Instance Method Summary collapse

Constructor Details

#initialize(local_endpoint) ⇒ Collector

Returns a new instance of Collector.



5
6
7
8
# File 'lib/zipkin/collector.rb', line 5

def initialize(local_endpoint)
  @buffer = Buffer.new
  @local_endpoint = local_endpoint
end

Instance Method Details

#retrieveObject



10
11
12
# File 'lib/zipkin/collector.rb', line 10

def retrieve
  @buffer.retrieve
end

#send_span(span, end_time) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/zipkin/collector.rb', line 14

def send_span(span, end_time)
  finish_ts = (end_time.to_f * 1_000_000).to_i
  start_ts = (span.start_time.to_f * 1_000_000).to_i
  duration = finish_ts - start_ts
  is_server = ['server', 'consumer'].include?(span.tags['span.kind'] || 'server')

  @buffer << {
    traceId: span.context.trace_id,
    id: span.context.span_id,
    parentId: span.context.parent_id,
    name: span.operation_name,
    timestamp: start_ts,
    duration: duration,
    annotations: [
      {
        timestamp: start_ts,
        value: is_server ? 'sr' : 'cs',
        endpoint: @local_endpoint
      },
      {
        timestamp: finish_ts,
        value: is_server ? 'ss': 'cr',
        endpoint: @local_endpoint
      }
    ],
    binaryAnnotations: build_binary_annotations(span)
  }
end