Sha256: 7a050e013c0a8157d24810039dbe16432f732c3840788447afa6b27a504d09c5

Contents?: true

Size: 1.02 KB

Versions: 9

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

require 'elastic_apm/subscriber'

module ElasticAPM
  # @api private
  class Railtie < Rails::Railtie
    config.elastic_apm = ActiveSupport::OrderedOptions.new

    Config::DEFAULTS.each { |option, value| config.elastic_apm[option] = value }

    initializer 'elastic_apm.initialize' do |app|
      config = app.config.elastic_apm.merge(app: app).tap do |c|
        # Prepend Rails.root to log_path if present
        if c.log_path && !c.log_path.start_with?('/')
          c.log_path = Rails.root.join(c.log_path)
        end
      end

      begin
        agent = ElasticAPM.start config

        if agent
          agent.instrumenter.subscriber = ElasticAPM::Subscriber.new(agent)

          app.middleware.insert 0, Middleware
        end
      rescue StandardError => e
        Rails.logger.error "#{Log::PREFIX}Failed to start: #{e.message}"
        Rails.logger.debug e.backtrace.join("\n")
      end
    end

    config.after_initialize do
      require 'elastic_apm/spies/action_dispatch'
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
elastic-apm-1.1.0 lib/elastic_apm/railtie.rb
elastic-apm-1.0.2 lib/elastic_apm/railtie.rb
elastic-apm-1.0.1 lib/elastic_apm/railtie.rb
elastic-apm-1.0.0 lib/elastic_apm/railtie.rb
elastic-apm-1.0.0.beta2 lib/elastic_apm/railtie.rb
elastic-apm-1.0.0.beta1 lib/elastic_apm/railtie.rb
elastic-apm-0.8.0 lib/elastic_apm/railtie.rb
elastic-apm-0.7.4 lib/elastic_apm/railtie.rb
elastic-apm-0.7.3 lib/elastic_apm/railtie.rb