Class: Object

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

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.

Parameters:

  • method_name (Symbol)

    The name of the class method to instrument.

  • options (Hash<Symbol, String>) (defaults to: {})

    Options for instrumentation.

Options Hash (options):

  • :name (String)

    Custom event name for the instrumentation.

Returns:

  • (Symbol)

See Also:



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

  if singleton_class.respond_to?(:ruby2_keywords, true) # rubocop:disable Style/GuardClause
    singleton_class.send(:ruby2_keywords, method_name)
  end
end

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

Instruments an instance method with AppSignal monitoring.

Parameters:

  • method_name (Symbol)

    The name of the instance method to instrument.

  • options (Hash<Symbol, String>) (defaults to: {})

    Options for instrumentation.

Options Hash (options):

  • :name (String)

    Custom event name for the instrumentation.

Returns:

  • (Symbol)

See Also:



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