Class: BuilderApm::Middleware::Timing

Inherits:
Object
  • Object
show all
Defined in:
lib/builder_apm/middleware/timing.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, redis_client: BuilderApm::RedisClient.client) ⇒ Timing

Returns a new instance of Timing.



4
5
6
7
# File 'lib/builder_apm/middleware/timing.rb', line 4

def initialize(app, redis_client: BuilderApm::RedisClient.client)
  @redis_client = redis_client
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/builder_apm/middleware/timing.rb', line 9

def call(env)
  start_time = Time.now.to_f * 1000
  request_id = env["action_dispatch.request_id"]
  Thread.current[:request_id] = request_id
  Thread.current[:n_plus_one_duration] = 0
  Thread.current[:has_n_plus_one] = false
  Thread.current[:db_runtime] = 0
  Thread.current[:method_tracing] = 0
  Thread.current[:db_tracing] = 0
  Thread.current[:trace_point].disable if Thread.current[:trace_point]
  Thread.current[:trace_point] = nil
    
  @status, @headers, @response = @app.call(env)

ensure
  end_time = Time.now.to_f * 1000
  handle_timing(start_time, end_time, request_id)

  clean_up_thread_values

  [@status, @headers, @response]
end