module ElasticAPM::SpanHelpers::ClassMethods

def __span_method_on(klass, method, name = nil, type = nil, **kwargs)

def __span_method_on(klass, method, name = nil, type = nil, **kwargs)
  name ||= method.to_s
  type ||= Span::DEFAULT_TYPE
  klass.prepend(Module.new do
    ruby2_keywords(define_method(method) do |*args, &block|
      unless ElasticAPM.current_transaction
        return super(*args, &block)
      end
      ElasticAPM.with_span name.to_s, type.to_s, **kwargs do
        super(*args, &block)
      end
    end)
  end)
end

def span_class_method(method, name = nil, type = nil, **kwargs)

def span_class_method(method, name = nil, type = nil, **kwargs)
  __span_method_on(singleton_class, method, name, type, **kwargs)
end

def span_method(method, name = nil, type = nil, **kwargs)

def span_method(method, name = nil, type = nil, **kwargs)
  __span_method_on(self, method, name, type, **kwargs)
end