Sha256: a06b7e476822f8630cbf6a8c8161edd588dd876cb5214457c82c1463e8e3d157

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

require "forwardable"
require "securerandom"
require "honeycomb/span"
require "honeycomb/propagation"

module Honeycomb
  # Represents a Honeycomb trace, which groups spans together
  class Trace
    include PropagationParser
    extend Forwardable

    def_delegators :@root_span, :send

    attr_reader :id, :fields, :root_span, :rollup_fields

    def initialize(builder:, context:, serialized_trace: nil)
      trace_id, parent_span_id, trace_fields, dataset =
        parse serialized_trace
      dataset && builder.dataset = dataset
      @id = trace_id || SecureRandom.uuid
      @rollup_fields = Hash.new(0)
      @fields = trace_fields || {}
      @root_span = Span.new(trace: self,
                            parent_id: parent_span_id,
                            is_root: true,
                            builder: builder,
                            context: context)
    end

    def add_field(key, value)
      @fields[key] = value
    end

    def add_rollup_field(key, value)
      @rollup_fields[key] += value
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
honeycomb-beeline-1.0.0.pre.alpha1 lib/honeycomb/trace.rb