Sha256: 57d73410f5cd3f649aa99f9dceeda14273b95026943d0f16150c4848e8e1d756

Contents?: true

Size: 1.25 KB

Versions: 24

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

if defined?(Appsignal)
  Appsignal::Environment.report_enabled("object_instrumentation")
end

class Object
  def self.appsignal_instrument_class_method(method_name, options = {})
    singleton_class.send \
      :alias_method, "appsignal_uninstrumented_#{method_name}", method_name
    singleton_class.send(:define_method, method_name) do |*args, &block|
      name = options.fetch(:name) do
        "#{method_name}.class_method.#{appsignal_reverse_class_name}.other"
      end
      Appsignal.instrument name do
        send "appsignal_uninstrumented_#{method_name}", *args, &block
      end
    end
  end

  def self.appsignal_instrument_method(method_name, options = {})
    alias_method "appsignal_uninstrumented_#{method_name}", method_name
    define_method method_name do |*args, &block|
      name = options.fetch(:name) do
        "#{method_name}.#{appsignal_reverse_class_name}.other"
      end
      Appsignal.instrument name do
        send "appsignal_uninstrumented_#{method_name}", *args, &block
      end
    end
  end

  def self.appsignal_reverse_class_name
    return "AnonymousClass" unless name
    name.split("::").reverse.join(".")
  end

  def appsignal_reverse_class_name
    self.class.appsignal_reverse_class_name
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
appsignal-2.11.3-java lib/appsignal/integrations/object.rb
appsignal-2.11.3 lib/appsignal/integrations/object.rb
appsignal-2.11.2-java lib/appsignal/integrations/object.rb
appsignal-2.11.2 lib/appsignal/integrations/object.rb
appsignal-2.11.1-java lib/appsignal/integrations/object.rb
appsignal-2.11.1 lib/appsignal/integrations/object.rb
appsignal-2.11.1.beta.2 lib/appsignal/integrations/object.rb
appsignal-2.11.1.beta.2-java lib/appsignal/integrations/object.rb
appsignal-2.11.0-java lib/appsignal/integrations/object.rb
appsignal-2.11.0 lib/appsignal/integrations/object.rb
appsignal-2.11.0.beta.5 lib/appsignal/integrations/object.rb
appsignal-2.11.0.beta.5-java lib/appsignal/integrations/object.rb
appsignal-2.11.0.beta.4 lib/appsignal/integrations/object.rb
appsignal-2.11.0.beta.4-java lib/appsignal/integrations/object.rb
appsignal-2.11.0.beta.3 lib/appsignal/integrations/object.rb
appsignal-2.11.0.beta.3-java lib/appsignal/integrations/object.rb
appsignal-2.11.0.beta.2 lib/appsignal/integrations/object.rb
appsignal-2.11.0.beta.2-java lib/appsignal/integrations/object.rb
appsignal-2.11.0.beta.1-java lib/appsignal/integrations/object.rb
appsignal-2.11.0.beta.1 lib/appsignal/integrations/object.rb