Module: Datadog::Contrib::Rails::ActionControllerPatch::ProcessActionPatch

Includes:
ProcessActionCompatibilityPatch
Defined in:
lib/ddtrace/contrib/rails/action_controller_patch.rb

Overview

ActionController patch

Instance Method Summary collapse

Instance Method Details

#datadog_response_statusObject



64
65
66
67
68
69
70
71
72
73
# File 'lib/ddtrace/contrib/rails/action_controller_patch.rb', line 64

def datadog_response_status
  case response
  when ActionDispatch::Response
    response.status
  when Array
    # Likely a Rack response array: first element is the status.
    status = response.first
    status.class <= Integer ? status : nil
  end
end

#process_action(*args) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ddtrace/contrib/rails/action_controller_patch.rb', line 30

def process_action(*args)
  # mutable payload with a tracing context that is used in two different
  # signals; it propagates the request span so that it can be finished
  # no matter what
  payload = {
    controller: self.class,
    action: action_name,
    env: request.env,
    headers: {
      # The exception this controller was given in the request,
      # which is typical if the controller is configured to handle exceptions.
      request_exception: request.headers['action_dispatch.exception']
    },
    tracing_context: {}
  }

  begin
    # process and catch request exceptions
    Datadog::Contrib::Rails::ActionController.start_processing(payload)
    result = super(*args)
    status = datadog_response_status
    payload[:status] = status unless status.nil?
    result
  # rubocop:disable Lint/RescueException
  rescue Exception => e
    payload[:exception] = [e.class.name, e.message]
    payload[:exception_object] = e
    raise e
  end
# rubocop:enable Lint/RescueException
ensure
  Datadog::Contrib::Rails::ActionController.finish_processing(payload)
end