Class: Eyeloupe::Processors::InRequest
- Inherits:
-
Object
- Object
- Eyeloupe::Processors::InRequest
- Includes:
- Singleton
- Defined in:
- lib/eyeloupe/processors/in_request.rb
Instance Attribute Summary collapse
- #env ⇒ Hash?
- #ex ⇒ Eyeloupe::Exception?
- #headers ⇒ Hash?
- #request ⇒ ActionDispatch::Request
- #response ⇒ String, ...
- #started_at ⇒ Time?
- #status ⇒ Integer?
- #subs ⇒ Array
- #timings ⇒ Hash
Instance Method Summary collapse
- #init(request, env, status, headers, response, ex) ⇒ Eyeloupe::Processors::InRequest
-
#initialize ⇒ InRequest
constructor
A new instance of InRequest.
- #process ⇒ Eyeloupe::InRequest
- #start_timer ⇒ Object
Constructor Details
#initialize ⇒ InRequest
Returns a new instance of InRequest.
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/eyeloupe/processors/in_request.rb', line 37 def initialize @env = {} @request = ActionDispatch::Request.new(@env) @status = nil @headers = nil @response = nil @timings = {} @started_at = nil @subs = [] @ex = nil end |
Instance Attribute Details
#env ⇒ Hash?
14 15 16 |
# File 'lib/eyeloupe/processors/in_request.rb', line 14 def env @env end |
#ex ⇒ Eyeloupe::Exception?
35 36 37 |
# File 'lib/eyeloupe/processors/in_request.rb', line 35 def ex @ex end |
#headers ⇒ Hash?
20 21 22 |
# File 'lib/eyeloupe/processors/in_request.rb', line 20 def headers @headers end |
#request ⇒ ActionDispatch::Request
11 12 13 |
# File 'lib/eyeloupe/processors/in_request.rb', line 11 def request @request end |
#response ⇒ String, ...
23 24 25 |
# File 'lib/eyeloupe/processors/in_request.rb', line 23 def response @response end |
#started_at ⇒ Time?
29 30 31 |
# File 'lib/eyeloupe/processors/in_request.rb', line 29 def started_at @started_at end |
#status ⇒ Integer?
17 18 19 |
# File 'lib/eyeloupe/processors/in_request.rb', line 17 def status @status end |
#subs ⇒ Array
32 33 34 |
# File 'lib/eyeloupe/processors/in_request.rb', line 32 def subs @subs end |
#timings ⇒ Hash
26 27 28 |
# File 'lib/eyeloupe/processors/in_request.rb', line 26 def timings @timings end |
Instance Method Details
#init(request, env, status, headers, response, ex) ⇒ Eyeloupe::Processors::InRequest
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/eyeloupe/processors/in_request.rb', line 56 def init(request, env, status, headers, response, ex) unsubscribe @request = request @env = env @status = status @headers = headers @response = response @ex = ex self end |
#process ⇒ Eyeloupe::InRequest
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/eyeloupe/processors/in_request.rb', line 80 def process req = Eyeloupe::InRequest.create( verb: @request.request_method, hostname: @request.host, path: @env["REQUEST_URI"], controller: get_controller, status: @status, format: @request.format, duration: get_total_duration, db_duration: @timings[:db_time].present? ? @timings[:db_time].round : nil, view_duration: @timings[:view_time].present? ? @timings[:view_time].round : nil, ip: @request.ip, payload: @env['rack.input'].read, headers: @headers&.to_json, session: (@request.session || {}).to_json, response: get_response, ) @ex.update(in_request_id: req.id) if @ex.present? && @ex.in_request_id.blank? req end |
#start_timer ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/eyeloupe/processors/in_request.rb', line 69 def start_timer @started_at = Time.now subscribe('process_action.action_controller') do |event| @timings[:controller_time] = event.duration @timings[:db_time] = event.payload[:db_runtime] @timings[:view_time] = event.payload[:view_runtime] end end |