class ElasticAPM::OpenTracing::Span

def finish(clock_end: Util.monotonic_micros, end_time: nil)

rubocop:disable Metrics/MethodLength
def finish(clock_end: Util.monotonic_micros, end_time: nil)
  return unless (agent = ElasticAPM.agent)
  if end_time
    warn '[ElasticAPM] DEPRECATED: Setting a custom end time as a ' \
      '`Time` is deprecated. Use `clock_end:` and monotonic time instead.'
    clock_end = end_time
  end
  elastic_span.done clock_end: clock_end
  case elastic_span
  when ElasticAPM::Transaction
    agent.instrumenter.current_transaction = nil
  when ElasticAPM::Span
    agent.instrumenter.current_spans.delete(elastic_span)
  end
  agent.enqueue elastic_span
end