class Jaeger::Client::Collector

Public Class Methods

new() click to toggle source
# File lib/jaeger/client/collector.rb, line 8
def initialize
  @buffer = Buffer.new
end

Public Instance Methods

retrieve() click to toggle source
# File lib/jaeger/client/collector.rb, line 32
def retrieve
  @buffer.retrieve
end
send_span(span, end_time) click to toggle source
# File lib/jaeger/client/collector.rb, line 12
def send_span(span, end_time)
  context = span.context
  start_ts, duration = build_timestamps(span, end_time)
  return if !context.sampled? && !context.debug?

  @buffer << Jaeger::Thrift::Span.new(
    'traceIdLow' => context.thrift_trace_id,
    'traceIdHigh' => 0,
    'spanId' => context.thrift_span_id,
    'parentSpanId' => context.thrift_parent_id,
    'operationName' => span.operation_name,
    'references' => build_references(span.references || []),
    'flags' => context.flags,
    'startTime' => start_ts,
    'duration' => duration,
    'tags' => span.tags,
    'logs' => span.logs
  )
end

Private Instance Methods

build_references(references) click to toggle source
# File lib/jaeger/client/collector.rb, line 38
def build_references(references)
  references.map do |ref|
    Jaeger::Thrift::SpanRef.new(
      'refType' => span_ref_type(ref.type),
      'traceIdLow' => ref.context.thrift_trace_id,
      'traceIdHigh' => 0,
      'spanId' => ref.context.thrift_span_id
    )
  end
end
build_timestamps(span, end_time) click to toggle source
# File lib/jaeger/client/collector.rb, line 49
def build_timestamps(span, end_time)
  start_ts = (span.start_time.to_f * 1_000_000).to_i
  end_ts = (end_time.to_f * 1_000_000).to_i
  duration = end_ts - start_ts
  [start_ts, duration]
end
span_ref_type(type) click to toggle source
# File lib/jaeger/client/collector.rb, line 56
def span_ref_type(type)
  case type
  when OpenTracing::Reference::CHILD_OF
    Jaeger::Thrift::SpanRefType::CHILD_OF
  when OpenTracing::Reference::FOLLOWS_FROM
    Jaeger::Thrift::SpanRefType::FOLLOWS_FROM
  else
    warn "Jaeger::Client with format #{type} is not supported yet"
    nil
  end
end