class ElasticAPM::Span

@api private

def build_stacktrace!

def build_stacktrace!
  @stacktrace = @stacktrace_builder.build(original_backtrace, type: :span)
end

def done(clock_end: Util.monotonic_micros)

def done(clock_end: Util.monotonic_micros)
  stop clock_end
  build_stacktrace! if should_build_stacktrace?
  self.original_backtrace = nil # release original
  self
end

def initialize(

rubocop:disable Metrics/ParameterLists, Metrics/MethodLength
def initialize(
  name:,
  transaction:,
  trace_context:,
  parent:,
  type: nil,
  subtype: nil,
  action: nil,
  context: nil,
  stacktrace_builder: nil
)
  @name = name
  if subtype.nil? && type&.include?('.')
    @type, @subtype, @action = type.split('.')
  else
    @type = type || DEFAULT_TYPE
    @subtype = subtype
    @action = action
  end
  @transaction = transaction
  @parent = parent
  @trace_context = trace_context || parent.trace_context.child
  @context = context || Span::Context.new
  @stacktrace_builder = stacktrace_builder
end

def inspect

def inspect
  "<ElasticAPM::Span id:#{trace_context&.id}" \
    " name:#{name.inspect}" \
    " type:#{type.inspect}" \
    '>'
end

def long_enough_for_stacktrace?

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

def running?

def running?
  started? && !stopped?
end

def should_build_stacktrace?

def should_build_stacktrace?
  @stacktrace_builder && original_backtrace && long_enough_for_stacktrace?
end

def start(clock_start = Util.monotonic_micros)

def start(clock_start = Util.monotonic_micros)
  @timestamp = Util.micros
  @clock_start = clock_start
  @parent.child_started
  self
end

def started?

def started?
  !!timestamp
end

def stop(clock_end = Util.monotonic_micros)

def stop(clock_end = Util.monotonic_micros)
  @duration ||= (clock_end - @clock_start)
  @parent.child_stopped
  @self_time = @duration - child_durations.duration
  self
end

def stopped?

def stopped?
  !!duration
end