lib/tracebin/middleware.rb in tracebin-0.0.11 vs lib/tracebin/middleware.rb in tracebin-0.0.12

- old
+ new

@@ -1,26 +1,31 @@ require 'tracebin/timer' require 'tracebin/puppet_master' +# require 'tracebin/initializer' module Tracebin class Middleware attr_reader :config, :logger def initialize(app) @app = app + @config = Tracebin::Agent.config @logger = Tracebin::Agent.logger - start_agent + start_agent_parent_process end def call(env) dup.__call(env) end def __call(env) + start_agent_child_process + if agent_disabled?(env) + @logger.debug "TRACEBIN: Tracebin disabled for this request." return @app.call env else @tracebin_timer = Timer.new @tracebin_timer.start! @@ -46,20 +51,22 @@ else 'RackTransaction' end end - def start_agent - Tracebin::Agent.start! - rescue => e - @logger.warn "TRACEBIN: Failed to start agent: #{e.message}" + def start_agent_child_process + Tracebin::Agent.start_child_process end + def start_agent_parent_process + Tracebin::Agent.start_parent_process + end + def agent_disabled?(env) path = env['REQUEST_PATH'] ignored_paths = config.ignored_paths.map { |root| %r{^#{root}} } - !Tracebin::Agent.started? || + !Tracebin::Agent.child_process_started? || ignored_paths.any? { |root| !!root.match(path) } end end end