Class: Object

Inherits:
BasicObject
Defined in:
lib/appsignal/integrations/object.rb,
sig/appsignal.rbs

Overview

Extensions to Object for AppSignal method instrumentation.

Class Method Summary collapse

Class Method Details

.appsignal_instrument_class_method(method_name, options = {}) ⇒ Symbol

Instruments a class method with AppSignal monitoring.

@param method_name — The name of the class method to instrument.

@param options — Options for instrumentation.

@see https://docs.appsignal.com/ruby/instrumentation/method-instrumentation.html — Method instrumentation documentation.

Parameters:

  • method_name (Symbol)
  • options (::Hash[Symbol, String]) (defaults to: {})

Returns:

  • (Symbol)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/appsignal/integrations/object.rb', line 18

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

  return unless singleton_class.respond_to?(:ruby2_keywords, true)

  singleton_class.send(:ruby2_keywords, method_name)
end

.appsignal_instrument_method(method_name, options = {}) ⇒ Symbol

Instruments an instance method with AppSignal monitoring.

@param method_name — The name of the instance method to instrument.

@param options — Options for instrumentation.

@see https://docs.appsignal.com/ruby/instrumentation/method-instrumentation.html — Method instrumentation documentation.

Parameters:

  • method_name (Symbol)
  • options (::Hash[Symbol, String]) (defaults to: {})

Returns:

  • (Symbol)


43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/appsignal/integrations/object.rb', line 43

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