Module: ZuoraConnect
- Defined in:
- lib/zuora_connect.rb,
lib/zuora_connect/engine.rb,
lib/zuora_connect/railtie.rb,
lib/zuora_connect/version.rb,
lib/zuora_connect/exceptions.rb,
app/models/zuora_connect/login.rb,
lib/zuora_connect/configuration.rb,
lib/middleware/json_parse_errors.rb,
app/models/zuora_connect/telegraf.rb,
lib/middleware/metrics_middleware.rb,
app/models/zuora_connect/zuora_user.rb,
lib/middleware/request_id_middleware.rb,
app/models/zuora_connect/app_instance.rb,
lib/zuora_connect/controllers/helpers.rb,
app/models/zuora_connect/app_instance_base.rb,
app/helpers/zuora_connect/application_helper.rb,
app/controllers/zuora_connect/static_controller.rb,
app/controllers/zuora_connect/application_controller.rb,
app/helpers/zuora_connect/api/v1/app_instance_helper.rb,
app/controllers/zuora_connect/admin/tenant_controller.rb,
app/controllers/zuora_connect/api/v1/app_instance_controller.rb
Defined Under Namespace
Modules: ApplicationHelper, Controllers, Exceptions Classes: AppInstance, AppInstanceBase, ApplicationController, Configuration, Engine, JsonParseErrors, Login, MetricsMiddleware, PageRequest, Railtie, RequestIdMiddleware, StaticController, Telegraf, ZuoraUser
Constant Summary collapse
- VERSION =
"2.0.24"
Class Attribute Summary collapse
-
.configuration ⇒ Object
Returns the value of attribute configuration.
- .logger ⇒ Object
Class Method Summary collapse
- .configure {|configuration| ... } ⇒ Object
- .custom_logger(name: "", level: Rails.logger.present? ? Rails.logger.level : MonoLogger::INFO, type: :ougai) ⇒ Object
- .elastic_apm_defaults ⇒ Object
- .reset ⇒ Object
Class Attribute Details
.configuration ⇒ Object
Returns the value of attribute configuration.
18 19 20 |
# File 'lib/zuora_connect.rb', line 18 def configuration @configuration end |
.logger ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/zuora_connect.rb', line 21 def logger case Rails.env.to_s when 'development' Rails.logger else @logger ||= custom_logger(name: "Connect", level: Rails.logger.level) end end |
Class Method Details
.configure {|configuration| ... } ⇒ Object
121 122 123 124 125 126 127 |
# File 'lib/zuora_connect.rb', line 121 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 |
.custom_logger(name: "", level: Rails.logger.present? ? Rails.logger.level : MonoLogger::INFO, type: :ougai) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/zuora_connect.rb', line 30 def custom_logger(name: "", level: Rails.logger.present? ? Rails.logger.level : MonoLogger::INFO, type: :ougai) #puts name + ' - ' + {Logger::WARN => 'Logger::WARN', Logger::ERROR => 'Logger::ERROR', Logger::DEBUG => 'Logger::DEBUG', Logger::INFO => 'Logger::INFO' }[level] + ' - ' if type == :ougai require 'ougai' require "ougai/formatters/customizable" #logger = Ougai::Logger.new(MonoLogger.new(STDOUT)) logger = Ougai::Logger.new(STDOUT) logger.level = level if ZuoraConnect.configuration.json_logging logger.formatter = Ougai::Formatters::ConnectFormatter.new(name) logger.before_log = lambda do |data| data[:trace_id] = ZuoraConnect::RequestIdMiddleware.request_id if ZuoraConnect::RequestIdMiddleware.request_id.present? data[:zuora_trace_id] = ZuoraConnect::RequestIdMiddleware.zuora_request_id if ZuoraConnect::RequestIdMiddleware.zuora_request_id.present? #data[:traces] = {amazon_id: data[:trace_id], zuora_id: data[:zuora_trace_id]} if !['ElasticAPM', 'ResqueScheduler', 'ResquePool', 'Resque', 'Makara'].include?(name) if Thread.current[:appinstance].present? && Thread.current[:appinstance].id.present? data[:app_instance_id] = Thread.current[:appinstance].id logitems = Thread.current[:appinstance].logitems if logitems.present? && logitems.class == Hash data[:tenant_ids] = logitems[:tenant_ids] if logitems[:tenant_ids].present? data[:organization] = logitems[:organization] if logitems[:organization].present? end end end end else logger.formatter = Ougai::Formatters::Customizable.new( format_err: proc do |data| next nil unless data.key?(:err) err = data.delete(:err) " #{err[:name]} (#{err[:message]})\n #{err[:stack]}" end, format_data: proc do |data| format('%s %s: %s', 'DATA'.ljust(6), Time.now.strftime('%FT%T.%6NZ'), "#{data.to_json}") if data.present? end, format_msg: proc do |severity, datetime, _progname, data| msg = data.delete(:msg) format('%s %s: %s', severity.ljust(6), datetime, msg) end ) logger.formatter.datetime_format = '%FT%T.%6NZ' end else 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 if ZuoraConnect.configuration.json_logging require 'json' store = { name: name, level: serverity, timestamp: datetime.strftime('%FT%T.%6NZ'), pid: Process.pid, message: name == "ActionMailer" ? msg.strip : msg } if !['ElasticAPM', 'ResqueScheduler', 'ResquePool','Resque', 'Makara'].include?(name) if Thread.current[:appinstance].present? && Thread.current[:appinstance].id.present? store[:app_instance_id] = Thread.current[:appinstance].id logitems = Thread.current[:appinstance].logitems if logitems.present? && logitems.class == Hash store[:tenant_ids] = logitems[:tenant_ids] if logitems[:tenant_ids].present? store[:organization] = logitems[:organization] if logitems[:organization].present? end end end JSON.dump(store) + "\n" else format('%s %s: %s', serverity.ljust(6), datetime, msg) + "\n" end end end return logger end |
.elastic_apm_defaults ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/zuora_connect.rb', line 129 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!({ disable_start_message: true, 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 |
.reset ⇒ Object
117 118 119 |
# File 'lib/zuora_connect.rb', line 117 def self.reset @configuration = Configuration.new end |