Class: Jaeger::Encoders::ThriftEncoder

Inherits:
Object
  • Object
show all
Defined in:
lib/jaeger/encoders/thrift_encoder.rb

Defined Under Namespace

Classes: DummyTransport

Instance Method Summary collapse

Constructor Details

#initialize(service_name:, logger:, tags: {}) ⇒ ThriftEncoder

Returns a new instance of ThriftEncoder.



6
7
8
9
10
11
# File 'lib/jaeger/encoders/thrift_encoder.rb', line 6

def initialize(service_name:, logger:, tags: {})
  @service_name = service_name
  @logger = logger
  @tags = prepare_tags(tags)
  @process = Jaeger::Thrift::Process.new('serviceName' => @service_name, 'tags' => @tags)
end

Instance Method Details

#encode(spans) ⇒ Object



13
14
15
# File 'lib/jaeger/encoders/thrift_encoder.rb', line 13

def encode(spans)
  encode_batch(spans.map(&method(:encode_span)))
end

#encode_limited_size(spans, protocol_class, max_message_length) ⇒ Object



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
42
43
44
# File 'lib/jaeger/encoders/thrift_encoder.rb', line 17

def encode_limited_size(spans, protocol_class, max_message_length)
  batches = []
  current_batch = []
  current_batch_size = 0

  max_spans_length = calculate_max_spans_length(protocol_class, max_message_length)

  spans.each do |span|
    encoded_span = encode_span(span)
    span_size = message_size(encoded_span, protocol_class)

    if span_size > max_spans_length
      @logger.warn("Skip span #{span.operation_name} with size #{span_size}")
      next
    end

    if (current_batch_size + span_size) > max_spans_length
      batches << encode_batch(current_batch)
      current_batch = []
      current_batch_size = 0
    end

    current_batch << encoded_span
    current_batch_size += span_size
  end
  batches << encode_batch(current_batch) unless current_batch.empty?
  batches
end