class ElasticAPM::Instrumenter

@api private

def current_transaction

def current_transaction
  @transaction_info.current
end

def current_transaction=(transaction)

def current_transaction=(transaction)
  @transaction_info.current = transaction
end

def initialize(agent)

def initialize(agent)
  @agent = agent
  @config = agent.config
  @transaction_info = TransactionInfo.new
end

def inspect

def inspect
  '<ElasticAPM::Instrumenter ' \
    "current_transaction=#{current_transaction.inspect}" \
    '>'
end

def random_sample?

def random_sample?
  rand <= config.transaction_sample_rate
end

def set_custom_context(context)

def set_custom_context(context)
  return unless current_transaction
  current_transaction.context.custom.merge!(context)
end

def set_tag(key, value)

def set_tag(key, value)
  return unless current_transaction
  current_transaction.context.tags[key] = value.to_s
end

def set_user(user)

def set_user(user)
  return unless current_transaction
  current_transaction.context.user = Context::User.new(config, user)
end

def span(*args, &block)

def span(*args, &block)
  unless current_transaction
    return yield if block_given?
    return
  end
  current_transaction.span(*args, &block)
end

def start

def start
end

def stop

def stop
  current_transaction.release if current_transaction
  @subscriber.unregister! if @subscriber
end

def submit_transaction(transaction)

def submit_transaction(transaction)
  agent.enqueue_transaction transaction
  return unless config.debug_transactions
  debug('Submitted transaction:') { Util.inspect_transaction transaction }
end

def subscriber=(subscriber)

def subscriber=(subscriber)
  @subscriber = subscriber
  @subscriber.register!
end

def transaction(*args)

rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
rubocop:disable Metrics/MethodLength, Metrics/AbcSize
def transaction(*args)
  unless config.instrument
    yield if block_given?
    return
  end
  if (transaction = current_transaction)
    yield transaction if block_given?
    return transaction
  end
  if args.last.is_a? Hash
    args.last[:sampled] = random_sample?
  else
    args.push(sampled: random_sample?)
  end
  transaction = Transaction.new self, *args
  self.current_transaction = transaction
  return transaction unless block_given?
  begin
    yield transaction
  ensure
    self.current_transaction = nil
    transaction.done
  end
  transaction
end