Class: ScoutApm::Middleware
- Inherits:
-
Object
- Object
- ScoutApm::Middleware
- Defined in:
- lib/scout_apm/middleware.rb
Constant Summary collapse
- MAX_ATTEMPTS =
5
Instance Method Summary collapse
- #attempt_to_start_agent ⇒ Object
-
#call(env) ⇒ Object
If we get a web request in, then we know we’re running in some sort of app server.
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
5 6 7 8 9 10 11 12 |
# File 'lib/scout_apm/middleware.rb', line 5 def initialize(app) @app = app @attempts = 0 # @enabled = ScoutApm::Agent.instance.context.apm_enabled? # XXX: Figure out if this middleware should even know @enabled = true @started = ScoutApm::Agent.instance.context.started? && ScoutApm::Agent.instance.background_worker_running? end |
Instance Method Details
#attempt_to_start_agent ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/scout_apm/middleware.rb', line 24 def attempt_to_start_agent @attempts += 1 ScoutApm::Agent.instance.start @started = ScoutApm::Agent.instance.context.started? && ScoutApm::Agent.instance.background_worker_running? rescue => e ScoutApm::Agent.instance.context.logger.info("Failed to start via Middleware: #{e.}\n\t#{e.backtrace.join("\n\t")}") end |
#call(env) ⇒ Object
If we get a web request in, then we know we’re running in some sort of app server
15 16 17 18 19 20 21 22 |
# File 'lib/scout_apm/middleware.rb', line 15 def call(env) if !@enabled || @started || @attempts > MAX_ATTEMPTS @app.call(env) else attempt_to_start_agent @app.call(env) end end |