Sha256: e16934a7e35d6050626535a840e73d63effb6eb31997d498af7516c3f6d34afa

Contents?: true

Size: 1.27 KB

Versions: 5

Compression:

Stored size: 1.27 KB

Contents

# 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/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

        # 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
          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'
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
contrast-agent-3.10.2 lib/contrast/agent/railtie.rb
contrast-agent-3.10.1 lib/contrast/agent/railtie.rb
contrast-agent-3.10.0 lib/contrast/agent/railtie.rb
contrast-agent-3.9.1 lib/contrast/agent/railtie.rb
contrast-agent-3.9.0 lib/contrast/agent/railtie.rb