Sha256: 060108d0608380d2abdf4d08f5282f85533125e2b76876055c8c54a8836d30ad

Contents?: true

Size: 1.13 KB

Versions: 4

Compression:

Stored size: 1.13 KB

Contents

# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
# frozen_string_literal: true

require 'contrast/utils/job_servers_running'
require 'contrast/components/logger'

module Contrast
  module Framework
    module Rails
      # A Railtie to allow for the automatic hooking of the Agent into a Rails application.
      class Railtie < ::Rails::Railtie
        include Contrast::Components::Logger::InstanceMethods

        initializer 'Contrast Ruby Agent Initializer' do |app|
          log_rails = defined?(Rails) && defined?(Rails.logger)

          Rails.logger.debug { "In railtie ::#{ app.middleware.inspect }" } if log_rails

          if ::Contrast::APP_CONTEXT.instrument_middleware_stack?
            ::Contrast::AGENT.insert_middleware(app)
          else
            Rails.logger.debug('Detected a running job server, skipping Contrast middleware insertion.') if log_rails
            logger.debug('Disabling Contrast for process', p_id: Process.pid)
          end
        end

        rake_tasks do
          load 'contrast/tasks/config.rb'
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
contrast-agent-6.11.0 lib/contrast/framework/rails/railtie.rb
contrast-agent-6.10.0 lib/contrast/framework/rails/railtie.rb
contrast-agent-6.9.0 lib/contrast/framework/rails/railtie.rb
contrast-agent-6.8.0 lib/contrast/framework/rails/railtie.rb