Class: ScoutApm::Instruments::MiddlewareDetailed

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

Defined Under Namespace

Classes: MiddlewareWrapper

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ MiddlewareDetailed

Returns a new instance of MiddlewareDetailed.



14
15
16
17
# File 'lib/scout_apm/instruments/middleware_detailed.rb', line 14

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

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



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

def context
  @context
end

Instance Method Details

#installObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/scout_apm/instruments/middleware_detailed.rb', line 27

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

    ActionDispatch::MiddlewareStack::Middleware.class_eval do
      def build(app)
        ScoutApm::Agent.instance.context.logger.info("Instrumenting Middleware #{klass.name}")
        new_mw = klass.new(app, *args, &block)
        MiddlewareWrapper.new(new_mw, klass.name)
      end
    end
  end
end

#installed?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/scout_apm/instruments/middleware_detailed.rb', line 23

def installed?
  @installed
end

#loggerObject



19
20
21
# File 'lib/scout_apm/instruments/middleware_detailed.rb', line 19

def logger
  context.logger
end