Module: Rails::Instrumentation::Patch

Defined in:
lib/rails/instrumentation/patch.rb

Class Method Summary collapse

Class Method Details

.patch_process_action(klass: ::ActionController::Instrumentation) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rails/instrumentation/patch.rb', line 4

def self.patch_process_action(klass: ::ActionController::Instrumentation)
  klass.class_eval do
    alias_method :process_action_original, :process_action

    def process_action(method_name, *args)
      # this naming scheme 'class.method' is how we ensure that the notification in the
      # subscriber is the same one
      name = "#{self.class.name}.#{method_name}"
      scope = ::Rails::Instrumentation.tracer.start_active_span(name)

      # skip adding tags here. Getting the complete set of information is
      # easiest in the notification

      process_action_original(method_name, *args)
    rescue Error => error
      if scope
        scope.span.set_tag('error', true)
        scope.span.log_kv(key: 'message', value: error.message)
      end

      raise
    ensure
      scope.close
    end
  end
end

.restore_process_action(klass: ::ActionController::Instrumentation) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/rails/instrumentation/patch.rb', line 31

def self.restore_process_action(klass: ::ActionController::Instrumentation)
  klass.class_eval do
    remove_method :process_action
    alias_method :process_action, :process_action_original
    remove_method :process_action_original
  end
end