Class: ScoutApm::Instruments::MiddlewareSummary::MiddlewareSummaryWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/scout_apm/instruments/middleware_summary.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ MiddlewareSummaryWrapper

Returns a new instance of MiddlewareSummaryWrapper.



44
45
46
# File 'lib/scout_apm/instruments/middleware_summary.rb', line 44

def initialize(app)
  @app = app
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *arguments, &block) ⇒ Object

Some code (found in resque_web initially) attempts to call methods directly on ‘MyApplication.app`, which is the middleware stack. If it hits our middleware instead of the object at the root of the app that it expected, then a method it expects will not be there, and an error thrown.

Specifically, resque_web assumes ‘ResqueWeb::Engine.app.url_helpers` is a method call on rails router for its own Engine, when in fact, we’ve added a middleware before it.

So method_missing just proxies anything to the nested @app object

While method_missing is not very performant, this is only here to handle edge-cases in other code, and should not be regularly called



71
72
73
74
75
76
77
# File 'lib/scout_apm/instruments/middleware_summary.rb', line 71

def method_missing(sym, *arguments, &block)
  if @app.respond_to?(sym)
    @app.send(sym, *arguments, &block)
  else
    super
  end
end

Instance Method Details

#call(env) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/scout_apm/instruments/middleware_summary.rb', line 48

def call(env)
  req = ScoutApm::RequestManager.lookup
  layer = ScoutApm::Layer.new("Middleware", "Summary")
  req.start_layer(layer)
  @app.call(env)
ensure
  req.stop_layer
end

#respond_to?(sym, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
82
83
84
85
# File 'lib/scout_apm/instruments/middleware_summary.rb', line 79

def respond_to?(sym, include_private = false)
  if @app.respond_to?(sym, include_private)
    true
  else
    super
  end
end