Class: Zipkin::Collector

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

Defined Under Namespace

Modules: LogAnnotations, Timestamp Classes: Buffer

Constant Summary collapse

OT_KIND_TO_ZIPKIN_KIND =
{
  'server' => 'SERVER',
  'client' => 'CLIENT',
  'producer' => 'PRODUCER',
  'consumer' => 'CONSUMER'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(local_endpoint) ⇒ Collector

Returns a new instance of Collector.



17
18
19
20
# File 'lib/zipkin/collector.rb', line 17

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

Instance Method Details

#retrieveObject



22
23
24
# File 'lib/zipkin/collector.rb', line 22

def retrieve
  @buffer.retrieve
end

#send_span(span, end_time) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/zipkin/collector.rb', line 26

def send_span(span, end_time)
  finish_ts = Timestamp.create(end_time)
  start_ts = Timestamp.create(span.start_time)
  duration = finish_ts - start_ts
  return unless span.context.sampled?

  @buffer << {
    traceId: span.context.trace_id,
    id: span.context.span_id,
    parentId: span.context.parent_id,
    name: span.operation_name,
    kind: OT_KIND_TO_ZIPKIN_KIND[span.tags[:'span.kind'] || 'server'],
    timestamp: start_ts,
    duration: duration,
    debug: false,
    shared: false,
    localEndpoint: @local_endpoint,
    remoteEndpoint: Endpoint.remote_endpoint(span),
    annotations: LogAnnotations.build(span),
    tags: span.tags
  }
end