class ElasticAPM::Span

@api private

Constants

DEFAULT_TYPE

Attributes

context[R]
duration[R]
name[RW]

rubocop:enable Metrics/ParameterLists

original_backtrace[RW]

rubocop:enable Metrics/ParameterLists

stacktrace[R]
timestamp[R]
trace_context[RW]

rubocop:enable Metrics/ParameterLists

transaction_id[R]
type[RW]

rubocop:enable Metrics/ParameterLists

Public Class Methods

new( name:, transaction_id:, trace_context:, type: nil, context: nil, stacktrace_builder: nil ) click to toggle source

rubocop:disable Metrics/ParameterLists

# File lib/elastic_apm/span.rb, line 18
def initialize(
  name:,
  transaction_id:,
  trace_context:,
  type: nil,
  context: nil,
  stacktrace_builder: nil
)
  @name = name
  @type = type || DEFAULT_TYPE

  @transaction_id = transaction_id
  @trace_context = trace_context

  @context = context || Span::Context.new
  @stacktrace_builder = stacktrace_builder
end

Public Instance Methods

done(end_time: Util.micros) click to toggle source
# File lib/elastic_apm/span.rb, line 52
def done(end_time: Util.micros)
  stop end_time

  build_stacktrace! if should_build_stacktrace?
  self.original_backtrace = nil # release original

  self
end
inspect() click to toggle source

relations

# File lib/elastic_apm/span.rb, line 75
def inspect
  "<ElasticAPM::Span id:#{id}" \
    " name:#{name.inspect}" \
    " type:#{type.inspect}" \
    '>'
end
running?() click to toggle source
# File lib/elastic_apm/span.rb, line 69
def running?
  started? && !stopped?
end
start(timestamp = Util.micros) click to toggle source

life cycle

# File lib/elastic_apm/span.rb, line 42
def start(timestamp = Util.micros)
  @timestamp = timestamp

  self
end
started?() click to toggle source
# File lib/elastic_apm/span.rb, line 65
def started?
  !!timestamp
end
stop(end_timestamp = Util.micros) click to toggle source
# File lib/elastic_apm/span.rb, line 48
def stop(end_timestamp = Util.micros)
  @duration ||= (end_timestamp - timestamp)
end
stopped?() click to toggle source
# File lib/elastic_apm/span.rb, line 61
def stopped?
  !!duration
end

Private Instance Methods

build_stacktrace!() click to toggle source
# File lib/elastic_apm/span.rb, line 84
def build_stacktrace!
  @stacktrace = @stacktrace_builder.build(original_backtrace, type: :span)
end
long_enough_for_stacktrace?() click to toggle source
# File lib/elastic_apm/span.rb, line 92
def long_enough_for_stacktrace?
  min_duration =
    @stacktrace_builder.config.span_frames_min_duration_us

  return true if min_duration < 0
  return false if min_duration == 0

  duration >= min_duration
end
should_build_stacktrace?() click to toggle source
# File lib/elastic_apm/span.rb, line 88
def should_build_stacktrace?
  @stacktrace_builder && original_backtrace && long_enough_for_stacktrace?
end