Class: ScoutApm::Instruments::MiddlewareSummary

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

Defined Under Namespace

Classes: MiddlewareSummaryWrapper

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ MiddlewareSummary

Returns a new instance of MiddlewareSummary.



11
12
13
14
# File 'lib/scout_apm/instruments/middleware_summary.rb', line 11

def initialize(context)
  @context = context
  @installed = false
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



9
10
11
# File 'lib/scout_apm/instruments/middleware_summary.rb', line 9

def context
  @context
end

Instance Method Details

#installObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/scout_apm/instruments/middleware_summary.rb', line 24

def install
  if defined?(ActionDispatch) && defined?(ActionDispatch::MiddlewareStack)
    @installed = true

    logger.info("Instrumenting Middleware")
    ActionDispatch::MiddlewareStack.class_eval do
      def build_with_scout_instruments(app = nil, &block)
        mw_stack = build_without_scout_instruments(app) { block.call if block }
        if app == mw_stack
          # Return the raw middleware stack if it equaled app. No
          # middlewares were created, so nothing to wrap & test.
          #
          # Avoids instrumentation of something that doesn't exist
          mw_stack
        else
          MiddlewareSummaryWrapper.new(mw_stack)
        end
      end

      alias_method :build_without_scout_instruments, :build
      alias_method :build, :build_with_scout_instruments
    end
  end
end

#installed?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/scout_apm/instruments/middleware_summary.rb', line 20

def installed?
  @installed
end

#loggerObject



16
17
18
# File 'lib/scout_apm/instruments/middleware_summary.rb', line 16

def logger
  context.logger
end