lib/contrast/agent/railtie.rb in contrast-agent-3.8.5 vs lib/contrast/agent/railtie.rb in contrast-agent-3.9.0

- old
+ new

@@ -1,25 +1,31 @@ # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true -cs__scoped_require 'contrast/utils/operating_environment' +cs__scoped_require 'contrast/utils/job_servers_running' module Contrast module Agent # A Railtie to allow for the automatic hooking of the Agent into a Rails # application. class Railtie < Rails::Railtie + include Contrast::Components::Interface + access_component :agent, :app_context, :logging + initializer 'Contrast Ruby Agent Initializer' do |app| if defined?(Rails) && defined?(Rails.logger) Rails.logger.debug('In railtie ::') Rails.logger.debug(app.middleware.inspect) end - if Contrast::Utils::OperatingEnvironment.unsupported? - Rails.logger.debug('Detected a non-webserver context, skipping Contrast middleware insertion.') + # TODO: RUBY-564 This logic is not specific to Rails and should be used more broadly + # with all web frameworks. Move this check to be a part of our new initialization + # routine. + if APP_CONTEXT.instrument_middleware_stack? + AGENT.insert_middleware(app) else - # Keep our middleware at the outermost layer of the onion - app.middleware.insert_before 0, Contrast::Agent::Middleware + Rails.logger.debug('Detected a running job server, skipping Contrast middleware insertion.') + logger.debug(nil, "Disabling Contrast for process #{ Process.pid }") end end rake_tasks do load 'contrast/tasks/service.rb'