class ElasticAPM::Transaction

@api private

def add_response(*args)

def add_response(*args)
  context.response = Context::Response.new(*args)
end

def done(result = nil)

def done(result = nil)
  stop
  self.result = result if result
  self
end

def done?

def done?
  stopped?
end

def ensure_parent_id

def ensure_parent_id
  @parent_id ||= SecureRandom.hex(8)
  @parent_id
end

def inc_dropped_spans!

def inc_dropped_spans!
  @dropped_spans += 1
end

def inc_started_spans!

def inc_started_spans!
  @started_spans += 1
end

def initialize(

rubocop:disable Metrics/ParameterLists, Metrics/MethodLength
def initialize(
  name = nil,
  type = nil,
  sampled: true,
  context: nil,
  tags: nil,
  traceparent: nil
)
  @name = name
  @type = type || DEFAULT_TYPE
  @sampled = sampled
  @context = context || Context.new # TODO: Lazy generate this?
  Util.reverse_merge!(@context.tags, tags) if tags
  @id = SecureRandom.hex(8)
  if traceparent
    @traceparent = traceparent
    @parent_id = traceparent.span_id
  else
    @traceparent = Traceparent.from_transaction(self)
  end
  @started_spans = 0
  @dropped_spans = 0
  @notifications = [] # for AS::Notifications
end

def inspect

def inspect
  "<ElasticAPM::Transaction id:#{id}" \
    " name:#{name.inspect} type:#{type.inspect}>"
end

def max_spans_reached?(config)

def max_spans_reached?(config)
  started_spans > config.transaction_max_spans
end

def sampled?

def sampled?
  @sampled
end

def start

def start
  @timestamp = Util.micros
  self
end

def stop

def stop
  raise 'Transaction not yet start' unless timestamp
  @duration = Util.micros - timestamp
  self
end

def stopped?

def stopped?
  !!duration
end

def trace_id

def trace_id
  traceparent&.trace_id
end