lib/jaeger/client/span.rb in jaeger-client-0.4.2 vs lib/jaeger/client/span.rb in jaeger-client-0.5.0

- old
+ new

@@ -1,5 +1,10 @@ +# frozen_string_literal: true + +require_relative 'span/thrift_tag_builder' +require_relative 'span/thrift_log_builder' + module Jaeger module Client class Span attr_accessor :operation_name @@ -15,21 +20,22 @@ def initialize(context, operation_name, collector, start_time: Time.now, tags: {}) @context = context @operation_name = operation_name @collector = collector @start_time = start_time - @tags = tags + @tags = tags.map { |key, value| ThriftTagBuilder.build(key, value) } @logs = [] end # Set a tag value on this span # # @param key [String] the key of the tag # @param value [String, Numeric, Boolean] the value of the tag. If it's not # a String, Numeric, or Boolean it will be encoded with to_s def set_tag(key, value) - @tags = @tags.merge(key => value) + # Using Thrift::Tag to avoid unnecessary memory allocations + @tags << ThriftTagBuilder.build(key, value) end # Set a baggage item on the span # # @param key [String] the key of the baggage item @@ -47,28 +53,30 @@ nil end # Add a log entry to this span # + # @deprecated Use {#log_kv} instead. + def log(*args) + warn 'Span#log is deprecated. Please use Span#log_kv instead.' + log_kv(*args) + end + + # Add a log entry to this span + # # @param timestamp [Time] time of the log # @param fields [Hash] Additional information to log - def log(timestamp: Time.now, **fields) - @logs << { timestamp: timestamp, fields: fields } + def log_kv(timestamp: Time.now, **fields) + # Using Thrift::Log to avoid unnecessary memory allocations + @logs << ThriftLogBuilder.build(timestamp, fields) + nil end # Finish the {Span} # # @param end_time [Time] custom end time, if not now def finish(end_time: Time.now) @collector.send_span(self, end_time) - end - - private - - def build_binary_annotations - @tags.map do |name, value| - { key: name, value: value.to_s } - end end end end end