Class: Speedshop::Cloudwatch::Rack

Inherits:
Object
  • Object
show all
Defined in:
lib/speedshop/cloudwatch/rack.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Rack



6
7
8
# File 'lib/speedshop/cloudwatch/rack.rb', line 6

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/speedshop/cloudwatch/rack.rb', line 10

def call(env)
  begin
    if (header = env["HTTP_X_REQUEST_START"] || env["HTTP_X_QUEUE_START"])
      queue_time = (Time.now.to_f * 1000) - header.gsub("t=", "").to_f
      Reporter.instance.report(metric: :RequestQueueTime, value: queue_time)
    end
  rescue => e
    Speedshop::Cloudwatch.log_error("Failed to collect Rack metrics: #{e.message}", e)
  end
  @app.call(env)
end