123456789_123456789_123456789_123456789_123456789_

Class: ActionController::StructuredEventSubscriber

Do not use. This class is for internal use only.

Constant Summary

Class Attribute Summary

::ActiveSupport::StructuredEventSubscriber - Inherited

::ActiveSupport::Subscriber - Inherited

.namespace, .notifier, .subscriber,
.event_method_names

::Method names for the ::String patterns attached on this class, frozen and replaced on change so that it can be read concurrently and from other Ractors.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

This class inherits a constructor from ActiveSupport::StructuredEventSubscriber

Class Attribute Details

._rescue_from_event_backtrace (rw)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/structured_event_subscriber.rb', line 7

class_attribute :_rescue_from_event_backtrace, instance_accessor: false, default: nil # :nodoc:

._rescue_from_event_backtrace? ⇒ Boolean (rw)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/structured_event_subscriber.rb', line 7

class_attribute :_rescue_from_event_backtrace, instance_accessor: false, default: nil # :nodoc:

Instance Method Details

#additions_for(payload) (private)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/structured_event_subscriber.rb', line 151

def additions_for(payload)
  payload.slice(:view_runtime, :db_runtime, :queries_count, :cached_queries_count)
end

#csrf_javascript_blocked(event)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/structured_event_subscriber.rb', line 112

def csrf_javascript_blocked(event)
  emit_csrf_event "action_controller.csrf_javascript_blocked", event.payload
end

#csrf_request_blocked(event)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/structured_event_subscriber.rb', line 108

def csrf_request_blocked(event)
  emit_csrf_event "action_controller.csrf_request_blocked", event.payload
end

#csrf_token_fallback(event)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/structured_event_subscriber.rb', line 104

def csrf_token_fallback(event)
  emit_csrf_event "action_controller.csrf_token_fallback", event.payload
end

#emit_csrf_event(name, payload) (private)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/structured_event_subscriber.rb', line 116

private def emit_csrf_event(name, payload)
  emit_event name,
    controller: payload[:controller],
    action: payload[:action],
    sec_fetch_site: payload[:sec_fetch_site],
    message: payload[:message]
end

#exist_fragment?(event) ⇒ Boolean

[ GitHub ]

  
# File 'actionpack/lib/action_controller/structured_event_subscriber.rb', line 132

def exist_fragment?(event)
  fragment_cache(__method__, event)
end

#expire_fragment(event)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/structured_event_subscriber.rb', line 136

def expire_fragment(event)
  fragment_cache(__method__, event)
end

#fragment_cache(method_name, event) (private)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/structured_event_subscriber.rb', line 141

def fragment_cache(method_name, event)
  key = ActiveSupport::Cache.expand_cache_key(event.payload[:key] || event.payload[:path])

  emit_event("action_controller.fragment_cache",
    method: "#{method_name}",
    key: key,
    duration_ms: event.duration.round(1)
  )
end

#halted_callback(event)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/structured_event_subscriber.rb', line 49

def halted_callback(event)
  emit_event("action_controller.callback_halted", filter: event.payload[:filter])
end

#open_redirect(event)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/structured_event_subscriber.rb', line 82

def open_redirect(event)
  payload = event.payload

  emit_event("action_controller.open_redirect",
    location: payload[:location],
    request_method: payload[:request]&.method,
    request_path: payload[:request]&.path,
    stacktrace: payload[:stack_trace],
  )
end

#process_action(event)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/structured_event_subscriber.rb', line 29

def process_action(event)
  return unless emitting?("action_controller.request_completed")

  payload = event.payload
  status = payload[:status]

  if status.nil? && (exception_class_name = payload[:exception]&.first)
    status = ActionDispatch::ExceptionWrapper.status_code_for_exception(exception_class_name)
  end

  emit_event("action_controller.request_completed", {
    controller: payload[:controller],
    action: payload[:action],
    status: status,
    **additions_for(payload),
    duration_ms: event.duration.round(2),
    gc_time_ms: event.gc_time.round(1),
  }.compact)
end

#read_fragment(event)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/structured_event_subscriber.rb', line 128

def read_fragment(event)
  fragment_cache(__method__, event)
end

#redirect_to(event)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/structured_event_subscriber.rb', line 74

def redirect_to(event)
  emit_event("action_controller.redirected", location: event.payload[:location])
end

#rescue_from_callback(event)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/structured_event_subscriber.rb', line 53

def rescue_from_callback(event)
  exception = event.payload[:exception]

  if self.class._rescue_from_event_backtrace == :array
    exception_backtrace = exception.backtrace
  else
    exception_backtrace = exception.backtrace&.first
    exception_backtrace = exception_backtrace&.delete_prefix("#{Rails.root}/") if defined?(Rails.root) && Rails.root
  end

  emit_event("action_controller.rescue_from_handled",
    exception_class: exception.class.name,
    exception_message: exception.message,
    exception_backtrace:
  )
end

#send_data(event)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/structured_event_subscriber.rb', line 78

def send_data(event)
  emit_event("action_controller.data_sent", filename: event.payload[:filename], duration_ms: event.duration.round(1))
end

#send_file(event)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/structured_event_subscriber.rb', line 70

def send_file(event)
  emit_event("action_controller.file_sent", path: event.payload[:path], duration_ms: event.duration.round(1))
end

#start_processing(event)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/structured_event_subscriber.rb', line 9

def start_processing(event)
  return unless emitting?("action_controller.request_started")

  payload = event.payload
  params = {}
  payload[:params].each_pair do |k, v|
    params[k] = v unless INTERNAL_PARAMS.include?(k)
  end
  format = payload[:format]
  format = format.name.upcase if format.is_a?(Symbol)
  format = "*/*" if format.nil?

  emit_event("action_controller.request_started",
    controller: payload[:controller],
    action: payload[:action],
    format:,
    params:,
  )
end

#unpermitted_parameters(event)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/structured_event_subscriber.rb', line 93

def unpermitted_parameters(event)
  unpermitted_keys = event.payload[:keys]
  context = event.payload[:context]

  emit_debug_event("action_controller.unpermitted_parameters",
    unpermitted_keys:,
    context: context.except(:request)
  )
end

#write_fragment(event)

[ GitHub ]

  
# File 'actionpack/lib/action_controller/structured_event_subscriber.rb', line 124

def write_fragment(event)
  fragment_cache(__method__, event)
end