Module: InstrumentAllTheThings::MethodProxy::Instrumentor

Defined in:
lib/instrument_all_the_things/method_proxy.rb

Instance Method Summary collapse

Instance Method Details

#_iatt_built_forObject



45
46
47
# File 'lib/instrument_all_the_things/method_proxy.rb', line 45

def _iatt_built_for
  @_iatt_built_for
end

#_iatt_built_for=(val) ⇒ Object



49
50
51
# File 'lib/instrument_all_the_things/method_proxy.rb', line 49

def _iatt_built_for=(val)
  @_iatt_built_for = val
end

#inspectObject



41
42
43
# File 'lib/instrument_all_the_things/method_proxy.rb', line 41

def inspect
  "InstrumentAllTheThings::#{@_iatt_built_for}Proxy"
end

#set_context_tags(klass, settings, args, kwargs) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/instrument_all_the_things/method_proxy.rb', line 53

def set_context_tags(klass, settings, args, kwargs)
  return unless settings.is_a?(Hash) && settings[:trace].is_a?(Hash) && settings[:trace][:tags]

  settings[:context][:tags] = settings[:trace][:tags].map do |tag|
    if tag.is_a?(Proc)
      case tag.arity
      when 2
        tag.call(args, kwargs)
      when 1
        tag.parameters[0][1].to_s == 'args' ? tag.call(args) : tag.call(kwargs)
      else
        klass.instance_exec(&tag)
      end
    else
      tag
    end
  rescue StandardError
    nil
  end.compact
end

#wrap_implementation(method_name, settings) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/instrument_all_the_things/method_proxy.rb', line 74

def wrap_implementation(method_name, settings)
  wrap = MethodInstrumentor.new(**settings)
  set_tags = method(:set_context_tags)

  define_method(method_name) do |*args, **kwargs, &blk|
    set_tags.call(self, settings, args, kwargs)
    wrap.invoke(klass: is_a?(Class) ? self : self.class) do
      super(*args, **kwargs, &blk)
    end
  end
end