Sha256: 243e4518851eefffb81e10d6c966ef888b1ebf1263349ffb8dfc2e220086be74

Contents?: true

Size: 1.47 KB

Versions: 108

Compression:

Stored size: 1.47 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

    if singleton_class.respond_to?(:ruby2_keywords, true) # rubocop:disable Style/GuardClause
      singleton_class.send(:ruby2_keywords, method_name)
    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
    ruby2_keywords method_name if respond_to?(:ruby2_keywords, true)
  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

108 entries across 108 versions & 1 rubygems

Version Path
appsignal-3.3.11-java lib/appsignal/integrations/object.rb
appsignal-3.3.11 lib/appsignal/integrations/object.rb
appsignal-3.4.0-java lib/appsignal/integrations/object.rb
appsignal-3.4.0 lib/appsignal/integrations/object.rb
appsignal-3.3.10-java lib/appsignal/integrations/object.rb
appsignal-3.3.10 lib/appsignal/integrations/object.rb
appsignal-3.3.9-java lib/appsignal/integrations/object.rb
appsignal-3.3.9 lib/appsignal/integrations/object.rb
appsignal-3.3.8-java lib/appsignal/integrations/object.rb
appsignal-3.3.8 lib/appsignal/integrations/object.rb
appsignal-3.3.7-java lib/appsignal/integrations/object.rb
appsignal-3.3.7 lib/appsignal/integrations/object.rb
appsignal-3.3.6-java lib/appsignal/integrations/object.rb
appsignal-3.3.6 lib/appsignal/integrations/object.rb
appsignal-3.3.5-java lib/appsignal/integrations/object.rb
appsignal-3.3.5 lib/appsignal/integrations/object.rb
appsignal-3.3.4-java lib/appsignal/integrations/object.rb
appsignal-3.3.4 lib/appsignal/integrations/object.rb
appsignal-3.3.3-java lib/appsignal/integrations/object.rb
appsignal-3.3.3 lib/appsignal/integrations/object.rb