require 'rails/railtie'
require 'trashed/rack'
require 'trashed/reporter'

module Trashed
  class Railtie < ::Rails::Railtie
    config.trashed = Trashed::Reporter.new

    # Middleware would like to emit tagged logs after Rails::Rack::Logger
    # pops its tags. Introduce this haxware to stash the tags in the Rack
    # env so we can reuse them later.
    class ExposeLoggerTagsToRackEnv
      def initialize(app)
        @app = app
      end

      def call(env)
        @app.call(env).tap do
          env['trashed.logger.tags'] = Array(Thread.current[:activesupport_tagged_logging_tags]).dup
        end
      end
    end

    initializer 'trashed' do |app|
      require 'statsd'

      app.config.trashed.timing_sample_rate ||= 0.1
      app.config.trashed.gauge_sample_rate ||= 0.05
      app.config.trashed.logger ||= Rails.logger

      app.middleware.insert_after Rack::Runtime, Trashed::Rack, app.config.trashed
      app.middleware.insert_after Rails::Rack::Logger, ExposeLoggerTagsToRackEnv
    end
  end
end

require 'rails/railtie'
require 'trashed/rack'
require 'trashed/reporter'

module Trashed
  class Railtie < ::Rails::Railtie
    config.trashed = Trashed::Reporter.new

    # Middleware would like to emit tagged logs after Rails::Rack::Logger
    # pops its tags. Introduce this haxware to stash the tags in the Rack
    # env so we can reuse them later.
    class ExposeLoggerTagsToRackEnv
      def initialize(app)
        @app = app
      end

      def call(env)
        @app.call(env).tap do
          env['trashed.logger.tags'] = Array(Thread.current[:activesupport_tagged_logging_tags]).dup
        end
      end
    end

    initializer 'trashed' do |app|
      require 'statsd'

      app.config.trashed.timing_sample_rate ||= 0.1
      app.config.trashed.gauge_sample_rate ||= 0.05
      app.config.trashed.logger ||= Rails.logger

      app.middleware.insert_after ::Rack::Runtime, Trashed::Rack, app.config.trashed
      app.middleware.insert_after ::Rails::Rack::Logger, ExposeLoggerTagsToRackEnv
    end
  end
end

Fix error when fixing deprecation warnings
Fix error when fixing deprecation warnings

These needed to be `::Rack::Runtime` not `Rack::Runtime` when the quotes
were removed to fix deprecation warnings from Rails.
