require 'zuora_connect/configuration' require "zuora_connect/engine" require 'zuora_connect/exceptions' require 'zuora_connect/controllers/helpers' require 'zuora_connect/views/helpers' require 'zuora_connect/railtie' require 'resque/additions' require 'resque/dynamic_queues' require 'resque/silence_done' require 'resque/self_lookup' require 'resque/plugins/custom_logger' require 'metrics/influx/point_value' require 'metrics/net' module ZuoraConnect class << self attr_accessor :configuration attr_writer :logger def logger case Rails.env.to_s when 'development' Rails.logger else @logger ||= custom_logger(name: "Connect", level: Rails.logger.level) end end def custom_logger(name: "", level: Rails.logger.level) logger = MonoLogger.new(STDOUT) logger.level = level logger.formatter = proc do |serverity, datetime, progname, msg| begin msg = JSON.parse(msg) rescue JSON::ParserError => ex end require 'json' JSON.dump( name: name, level: serverity, timestamp: datetime.strftime('%FT%T.%6N'), pid: Process.pid, message: name == "ActionMailer" ? msg.strip : msg ) + "\n" end return logger end end module Controllers autoload :Helpers, 'zuora_connect/controllers/helpers' end module Views ActionView::Base.send(:include, Helpers) end def self.configuration @configuration ||= Configuration.new end def self.reset @configuration = Configuration.new end def self.configure yield(configuration) ::Apartment.excluded_models << "Delayed::Job" if configuration.delayed_job ::Apartment.excluded_models.concat(configuration.additional_apartment_models) if configuration.additional_apartment_models.class == Array return configuration end def self.elastic_apm_defaults defaults = {} case Rails.env.to_s when 'production' defaults = { server_url: "http://apm-server.logging:8200", transaction_sample_rate: 0.20, capture_body: 'errors' } when 'staging' defaults = { server_url: "http://apm-server.logging:8200", transaction_sample_rate: 1.0 } when 'development' defaults = { server_url: "http://logging.0.ecc.auw2.zuora:8200", transaction_sample_rate: 1.0 } when 'test' defaults = { active: false, disable_send: true } end defaults.merge!({ pool_size: 1, transaction_max_spans: 500, ignore_url_patterns: ['^\/admin\/resque.*', '^\/admin\/redis.*', '^\/admin\/peek.*', '^\/peek.*'], verify_server_cert: false, log_level: Logger::INFO, service_name: ENV['DEIS_APP'].present? ? ENV['DEIS_APP'] : Rails.application.class.parent_name, logger: ZuoraConnect.custom_logger(name: "ElasticAPM", level: MonoLogger::WARN) }) defaults.merge!({disable_send: true}) if defined?(Rails::Console) return defaults end end