class Slimy::Rack::SLIMiddleware
rack middleware for tracking http request SLIs
Constants
- MIDDLEWARE_CONTEXT_KEY
Public Class Methods
new(app, options = {})
click to toggle source
# File lib/slimy/rack/middleware.rb, line 9 def initialize(app, options = {}) @app = app @reporter = if options.key? :reporter options[:reporter] else Slimy::Configuration.default.reporter end end
Public Instance Methods
call(env)
click to toggle source
# File lib/slimy/rack/middleware.rb, line 23 def call(env) context = init_context(env) response = nil begin response = @app.call(env) context.result_error! if response[0] >= 500 rescue StandardError => e context.result_error! raise e ensure context.finish report(context) end response end
init_context(env)
click to toggle source
# File lib/slimy/rack/middleware.rb, line 18 def init_context(env) context = Slimy::Context.new(deadline: 200, type: "rack") env[MIDDLEWARE_CONTEXT_KEY] = context end
report(context)
click to toggle source
# File lib/slimy/rack/middleware.rb, line 39 def report(context) @reporter&.report(context) end