Class: ActionController::StructuredEventSubscriber
- Inherits:
-
ActiveSupport::StructuredEventSubscriber
- Object
- ActiveSupport::StructuredEventSubscriber
- ActionController::StructuredEventSubscriber
- Defined in:
- lib/action_controller/structured_event_subscriber.rb
Overview
:nodoc:
Constant Summary collapse
- INTERNAL_PARAMS =
%w(controller action format _method only_path)
Instance Method Summary collapse
- #exist_fragment?(event) ⇒ Boolean
- #expire_fragment(event) ⇒ Object
- #halted_callback(event) ⇒ Object
- #process_action(event) ⇒ Object
- #read_fragment(event) ⇒ Object
- #redirect_to(event) ⇒ Object
- #rescue_from_callback(event) ⇒ Object
- #send_data(event) ⇒ Object
- #send_file(event) ⇒ Object
- #start_processing(event) ⇒ Object
- #unpermitted_parameters(event) ⇒ Object
- #write_fragment(event) ⇒ Object
Instance Method Details
#exist_fragment?(event) ⇒ Boolean
87 88 89 |
# File 'lib/action_controller/structured_event_subscriber.rb', line 87 def exist_fragment?(event) fragment_cache(__method__, event) end |
#expire_fragment(event) ⇒ Object
91 92 93 |
# File 'lib/action_controller/structured_event_subscriber.rb', line 91 def expire_fragment(event) fragment_cache(__method__, event) end |
#halted_callback(event) ⇒ Object
43 44 45 |
# File 'lib/action_controller/structured_event_subscriber.rb', line 43 def halted_callback(event) emit_event("action_controller.callback_halted", filter: event.payload[:filter]) end |
#process_action(event) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/action_controller/structured_event_subscriber.rb', line 25 def process_action(event) 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) ⇒ Object
83 84 85 |
# File 'lib/action_controller/structured_event_subscriber.rb', line 83 def read_fragment(event) fragment_cache(__method__, event) end |
#redirect_to(event) ⇒ Object
60 61 62 |
# File 'lib/action_controller/structured_event_subscriber.rb', line 60 def redirect_to(event) emit_event("action_controller.redirected", location: event.payload[:location]) end |
#rescue_from_callback(event) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/action_controller/structured_event_subscriber.rb', line 47 def rescue_from_callback(event) exception = event.payload[:exception] emit_event("action_controller.rescue_from_handled", exception_class: exception.class.name, exception_message: exception., exception_backtrace: exception.backtrace&.first&.delete_prefix("#{Rails.root}/") ) end |
#send_data(event) ⇒ Object
64 65 66 |
# File 'lib/action_controller/structured_event_subscriber.rb', line 64 def send_data(event) emit_event("action_controller.data_sent", filename: event.payload[:filename], duration_ms: event.duration.round(1)) end |
#send_file(event) ⇒ Object
56 57 58 |
# File 'lib/action_controller/structured_event_subscriber.rb', line 56 def send_file(event) emit_event("action_controller.file_sent", path: event.payload[:path], duration_ms: event.duration.round(1)) end |
#start_processing(event) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/action_controller/structured_event_subscriber.rb', line 7 def start_processing(event) 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.to_s.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) ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/action_controller/structured_event_subscriber.rb', line 68 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) ⇒ Object
79 80 81 |
# File 'lib/action_controller/structured_event_subscriber.rb', line 79 def write_fragment(event) fragment_cache(__method__, event) end |