Sha256: d1edb3b946353de21924aa21df9e313be14bd585fccdd2e898c66afe7db0a327

Contents?: true

Size: 1.97 KB

Versions: 4

Compression:

Stored size: 1.97 KB

Contents

module Jaeger
  module Client
    class Span
      attr_accessor :operation_name

      attr_reader :context, :start_time, :tags, :logs

      # Creates a new {Span}
      #
      # @param context [SpanContext] the context of the span
      # @param context [String] the operation name
      # @param collector [Collector] span collector
      #
      # @return [Span] a new Span
      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
        @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)
      end

      # Set a baggage item on the span
      #
      # @param key [String] the key of the baggage item
      # @param value [String] the value of the baggage item
      def set_baggage_item(key, value)
        self
      end

      # Get a baggage item
      #
      # @param key [String] the key of the baggage item
      #
      # @return Value of the baggage item
      def get_baggage_item(key)
        nil
      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}
      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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jaeger-client-0.4.1 lib/jaeger/client/span.rb
jaeger-client-0.4.0 lib/jaeger/client/span.rb
jaeger-client-0.3.0 lib/jaeger/client/span.rb
jaeger-client-0.2.0 lib/jaeger/client/span.rb