Sha256: 7dc47c31f9f9c691e6f826c06deb2a0d0055c575416e216a55417c4ca5b6f941

Contents?: true

Size: 922 Bytes

Versions: 2

Compression:

Stored size: 922 Bytes

Contents

# frozen_string_literal: true

require 'elastic_apm/span/context'

module ElasticAPM
  # @api private
  class Span
    DEFAULT_KIND = 'custom'.freeze

    # rubocop:disable Metrics/ParameterLists
    def initialize(
      transaction,
      id,
      name,
      type = DEFAULT_KIND,
      parent: nil,
      context: nil
    )
      @transaction = transaction
      @id = id
      @name = name
      @type = type
      @parent = parent
      @context = context
    end
    # rubocop:enable Metrics/ParameterLists

    attr_accessor :name, :context, :type
    attr_reader :id, :duration, :parent, :relative_start

    def start
      @relative_start = Util.micros - @transaction.timestamp

      self
    end

    def done
      @duration = Util.micros - @transaction.timestamp - relative_start

      self
    end

    def done?
      !!duration
    end

    def running?
      relative_start && !done?
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
elastic-apm-0.2.0 lib/elastic_apm/span.rb
elastic-apm-0.1.0 lib/elastic_apm/span.rb