zuora_connect 1.7.81m → 1.7.81n

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dcd4ab73cc717bce5eac02625dce3b529e47b4e67115b1a021920e92c524a125
4
- data.tar.gz: d1b3c9a49d47f3f9e45e1806388f3504d9b085940c0850e82f7966f185272a5e
3
+ metadata.gz: 2cb0e1379ddbd07af3fd79825ad35f8a1f4528d0300e5c8342d03d22041419a8
4
+ data.tar.gz: d5f574fc73e82666995a9ca0179989b9409c13b979d8583345745e1817171b3b
5
5
  SHA512:
6
- metadata.gz: c22ad5afdcaef9bde0f1ad8a37f90dd313a286270e548480520940cc0570517c37309da67285a64f2255985e67796fc76671e8e63d9a8b3e9756463ea19ab655
7
- data.tar.gz: a834c3f09e0a698255ed9a1bacf8784175d27e4cf2bc2dd2341ef8f3a87f02a3929d04a767a97ec968624820eaf8882c57da05abf87d68d56003fb69cdf3fab1
6
+ metadata.gz: 25e81479fb15f06b3f12db242ddc1f403548fbb736b34c77857ce8b4bcec14954e3d5c2a370b2741666b122aad757afd14332d33a7ad13933424a9929e38820f
7
+ data.tar.gz: 3db1858e6cb78215e8d0663f143938f0fe95720b1e7d0ad6e3ba3368f18c0c3ec0666db7a6ad8853885436ef7d994ac4a0f2bb1ebff8a31734bbd97f3960dc5d
@@ -120,26 +120,26 @@ module ZuoraConnect
120
120
 
121
121
  if session.empty?
122
122
  self.new_session_message = "REFRESHING - Session Empty"
123
- Rails.logger.add(log_level, self.new_session_message)
123
+ ZuoraConnect.logger.add(log_level, self.new_session_message)
124
124
  raise ZuoraConnect::Exceptions::HoldingPattern if holding_pattern && !self.mark_for_refresh
125
125
  self.refresh(session: session)
126
126
 
127
127
  elsif (self.id != session["appInstance"].to_i)
128
128
  self.new_session_message = "REFRESHING - AppInstance ID(#{self.id}) does not match session id(#{session["appInstance"].to_i})"
129
- Rails.logger.add(log_level, self.new_session_message)
129
+ ZuoraConnect.logger.add(log_level, self.new_session_message)
130
130
  raise ZuoraConnect::Exceptions::HoldingPattern if holding_pattern && !self.mark_for_refresh
131
131
  self.refresh(session: session)
132
132
 
133
133
  elsif session["#{self.id}::task_data"].blank?
134
134
  self.new_session_message = "REFRESHING - Task Data Blank"
135
- Rails.logger.add(log_level, self.new_session_message)
135
+ ZuoraConnect.logger.add(log_level, self.new_session_message)
136
136
  raise ZuoraConnect::Exceptions::HoldingPattern if holding_pattern && !self.mark_for_refresh
137
137
  self.refresh(session: session)
138
138
 
139
139
  elsif session["#{self.id}::last_refresh"].blank?
140
140
  self.new_session_message = "REFRESHING - No Time on Cookie"
141
141
  recoverable_session = true
142
- Rails.logger.add(log_level, self.new_session_message)
142
+ ZuoraConnect.logger.add(log_level, self.new_session_message)
143
143
  raise ZuoraConnect::Exceptions::HoldingPattern if holding_pattern && !self.mark_for_refresh
144
144
  self.refresh(session: session)
145
145
 
@@ -147,7 +147,7 @@ module ZuoraConnect
147
147
  elsif (session["#{self.id}::last_refresh"].to_i < INSTANCE_REFRESH_WINDOW.ago.to_i) && self.mark_for_refresh
148
148
  self.new_session_message = "REFRESHING - Session Old by #{time_expire.abs} second"
149
149
  recoverable_session = true
150
- Rails.logger.add(log_level, self.new_session_message)
150
+ ZuoraConnect.logger.add(log_level, self.new_session_message)
151
151
  self.refresh(session: session)
152
152
 
153
153
  else
@@ -156,14 +156,14 @@ module ZuoraConnect
156
156
  else
157
157
  self.new_session_message = "REBUILDING - Expires in #{time_expire} seconds"
158
158
  end
159
- Rails.logger.add(log_level, self.new_session_message)
159
+ ZuoraConnect.logger.add(log_level, self.new_session_message)
160
160
  self.build_task(task_data: session["#{self.id}::task_data"], session: session)
161
161
  end
162
162
  end
163
163
  return self
164
164
  rescue ZuoraConnect::Exceptions::HoldingPattern => ex
165
165
  while self.marked_for_refresh?
166
- Rails.logger.info("Holding - Expires in #{self.reset_mark_expires_at}. '#{self.new_session_message}'")
166
+ ZuoraConnect.logger.info("Holding - Expires in #{self.reset_mark_expires_at}. '#{self.new_session_message}'")
167
167
  sleep(HOLDING_PATTERN_SLEEP)
168
168
  end
169
169
  self.reload_attributes([:refresh_token, :oauth_expires_at, :access_token])
@@ -171,7 +171,7 @@ module ZuoraConnect
171
171
  retry
172
172
  rescue => ex
173
173
  if recoverable_session
174
- Rails.logger.error("REBUILDING - Using backup expired cache")
174
+ ZuoraConnect.logger.error("REBUILDING - Using backup expired cache")
175
175
  self.build_task(task_data: session["#{self.id}::task_data"], session: session)
176
176
  return self
177
177
  else
@@ -181,7 +181,7 @@ module ZuoraConnect
181
181
  begin
182
182
  I18n.locale = self.locale
183
183
  rescue I18n::InvalidLocale => ex
184
- Rails.logger.debug("Invalid Locale: #{ex.message}")
184
+ ZuoraConnect.logger.debug("Invalid Locale: #{ex.message}")
185
185
  end
186
186
  Time.zone = self.timezone
187
187
  tenants = self.task_data.dig('tenant_ids') || []
@@ -200,33 +200,33 @@ module ZuoraConnect
200
200
  response = HTTParty.get(ZuoraConnect.configuration.url + "/api/#{self.api_version}/tools/tasks/#{self.id}.json",:body => {:access_token => self.access_token})
201
201
  response_time = Time.now - start
202
202
 
203
- Rails.logger.debug("[#{self.id}] REFRESH TASK - Connect Task Info Request Time #{response_time.round(2).to_s}")
203
+ ZuoraConnect.logger.debug("[#{self.id}] REFRESH TASK - Connect Task Info Request Time #{response_time.round(2).to_s}")
204
204
  if response.code == 200
205
205
  self.build_task(task_data: JSON.parse(response.body), session: session)
206
206
  self.last_refresh = Time.now.to_i
207
207
  self.cache_app_instance
208
208
  self.reset_mark_for_refresh
209
209
  else
210
- Rails.logger.fatal("[#{self.id}] REFRESH TASK - Failed Code #{response.code}")
210
+ ZuoraConnect.logger.fatal("[#{self.id}] REFRESH TASK - Failed Code #{response.code}")
211
211
  raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("Error Communicating with Connect", response.body, response.code)
212
212
  end
213
213
  rescue *(ZuoraAPI::Login::CONNECTION_EXCEPTIONS).concat(ZuoraAPI::Login::CONNECTION_READ_EXCEPTIONS) => ex
214
214
  if (refresh_count += 1) < 3
215
- Rails.logger.info("[#{self.id}] REFRESH TASK - #{ex.class} Retrying(#{refresh_count})")
215
+ ZuoraConnect.logger.info("[#{self.id}] REFRESH TASK - #{ex.class} Retrying(#{refresh_count})")
216
216
  retry
217
217
  else
218
- Rails.logger.fatal("[#{self.id}] REFRESH TASK - #{ex.class} Failed #{refresh_count}x")
218
+ ZuoraConnect.logger.fatal("[#{self.id}] REFRESH TASK - #{ex.class} Failed #{refresh_count}x")
219
219
  raise
220
220
  end
221
221
  rescue ZuoraConnect::Exceptions::ConnectCommunicationError => ex
222
222
  if (refresh_count += 1) < 3
223
- Rails.logger.info("[#{self.id}] REFRESH TASK - Failed Retrying(#{refresh_count})")
223
+ ZuoraConnect.logger.info("[#{self.id}] REFRESH TASK - Failed Retrying(#{refresh_count})")
224
224
  if ex.code == 401
225
225
  self.refresh_oauth
226
226
  end
227
227
  retry
228
228
  else
229
- Rails.logger.fatal("[#{self.id}] REFRESH TASK - Failed #{refresh_count}x")
229
+ ZuoraConnect.logger.fatal("[#{self.id}] REFRESH TASK - Failed #{refresh_count}x")
230
230
  raise
231
231
  end
232
232
  end
@@ -316,8 +316,8 @@ module ZuoraConnect
316
316
  end
317
317
  end
318
318
  rescue => ex
319
- Rails.logger.error("Task Data: #{task_data}") if task_data.present?
320
- Rails.logger.error("Task Session: #{session.to_h}") if session.present?
319
+ ZuoraConnect.logger.error("Task Data: #{task_data}") if task_data.present?
320
+ ZuoraConnect.logger.error("Task Session: #{session.to_h}") if session.present?
321
321
  raise
322
322
  end
323
323
 
@@ -393,7 +393,7 @@ module ZuoraConnect
393
393
  def check_oauth_state(method)
394
394
  #Refresh token if already expired
395
395
  if self.oauth_expired?
396
- Rails.logger.debug("[#{self.id}] Before '#{method}' method, Oauth expired")
396
+ ZuoraConnect.logger.debug("[#{self.id}] Before '#{method}' method, Oauth expired")
397
397
  self.refresh_oauth
398
398
  end
399
399
  end
@@ -412,7 +412,7 @@ module ZuoraConnect
412
412
  }
413
413
  response = HTTParty.post("#{ZuoraConnect.configuration.url}/oauth/token",:body => params)
414
414
  response_time = Time.now - start
415
- Rails.logger.info("[#{self.id}] REFRESH OAUTH - In #{response_time.round(2).to_s}")
415
+ ZuoraConnect.logger.debug("[#{self.id}] REFRESH OAUTH - In #{response_time.round(2).to_s}")
416
416
 
417
417
  if response.code == 200
418
418
  response_body = JSON.parse(response.body)
@@ -422,15 +422,15 @@ module ZuoraConnect
422
422
  self.oauth_expires_at = Time.at(response_body["created_at"].to_i) + response_body["expires_in"].seconds
423
423
  self.save(:validate => false)
424
424
  else
425
- Rails.logger.fatal("[#{self.id}] REFRESH OAUTH - Failed Code #{response.code}")
425
+ ZuoraConnect.logger.fatal("[#{self.id}] REFRESH OAUTH - Failed Code #{response.code}")
426
426
  raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("Error Refreshing Access Token", response.body, response.code)
427
427
  end
428
428
  rescue *(ZuoraAPI::Login::CONNECTION_EXCEPTIONS).concat(ZuoraAPI::Login::CONNECTION_READ_EXCEPTIONS) => ex
429
429
  if (refresh_oauth_count += 1) < 3
430
- Rails.logger.info("[#{self.id}] REFRESH OAUTH - #{ex.class} Retrying(#{refresh_oauth_count})")
430
+ ZuoraConnect.logger.info("[#{self.id}] REFRESH OAUTH - #{ex.class} Retrying(#{refresh_oauth_count})")
431
431
  retry
432
432
  else
433
- Rails.logger.fatal("[#{self.id}] REFRESH OAUTH - #{ex.class} Failed #{refresh_oauth_count}x")
433
+ ZuoraConnect.logger.fatal("[#{self.id}] REFRESH OAUTH - #{ex.class} Failed #{refresh_oauth_count}x")
434
434
  raise
435
435
  end
436
436
  rescue ZuoraConnect::Exceptions::ConnectCommunicationError => ex
@@ -441,10 +441,10 @@ module ZuoraConnect
441
441
  return if !self.oauth_expired?
442
442
 
443
443
  if (refresh_oauth_count += 1) < 3
444
- Rails.logger.info("[#{self.id}] REFRESH OAUTH - Failed Retrying(#{refresh_oauth_count})")
444
+ ZuoraConnect.logger.info("[#{self.id}] REFRESH OAUTH - Failed Retrying(#{refresh_oauth_count})")
445
445
  retry
446
446
  else
447
- Rails.logger.fatal("[#{self.id}] REFRESH OAUTH - Failed #{refresh_oauth_count}x")
447
+ ZuoraConnect.logger.fatal("[#{self.id}] REFRESH OAUTH - Failed #{refresh_oauth_count}x")
448
448
  raise
449
449
  end
450
450
  end
@@ -494,10 +494,10 @@ module ZuoraConnect
494
494
  end
495
495
  end
496
496
  if cached_instance.blank?
497
- Rails.logger.debug("[#{self.id}] Cached AppInstance Missing")
497
+ ZuoraConnect.logger.debug("[#{self.id}] Cached AppInstance Missing")
498
498
  return session
499
499
  else
500
- Rails.logger.debug("[#{self.id}] Cached AppInstance Found")
500
+ ZuoraConnect.logger.debug("[#{self.id}] Cached AppInstance Found")
501
501
  return decrypt_data(data: cached_instance, rescue_return: session).merge(session)
502
502
  end
503
503
  else
@@ -509,7 +509,7 @@ module ZuoraConnect
509
509
  if defined?(Redis.current)
510
510
  #Task data must be present and the last refresh cannot be old. We dont want to overwite new cache data with old
511
511
  if self.task_data.present? && (self.last_refresh.to_i > INSTANCE_REFRESH_WINDOW.ago.to_i)
512
- Rails.logger.debug("[#{self.id}] Caching AppInstance")
512
+ ZuoraConnect.logger.debug("[#{self.id}] Caching AppInstance")
513
513
  Redis.current.setex("AppInstance:#{self.id}", INSTANCE_REDIS_CACHE_PERIOD.to_i, self.encrypt_data(data: self.save_data))
514
514
  end
515
515
  end
@@ -570,7 +570,7 @@ module ZuoraConnect
570
570
  begin
571
571
  return JSON.parse(encryptor.decrypt_and_verify(CGI::unescape(data)))
572
572
  rescue ActiveSupport::MessageVerifier::InvalidSignature => ex
573
- Rails.logger.add(Logger::FATAL, 'Error Decrypting') if log_fatal
573
+ ZuoraConnect.logger.add(Logger::FATAL, 'Error Decrypting') if log_fatal
574
574
  return rescue_return
575
575
  rescue JSON::ParserError => ex
576
576
  return encryptor.decrypt_and_verify(CGI::unescape(data))
@@ -632,8 +632,8 @@ module ZuoraConnect
632
632
  self.update_column(:catalog_update_attempt_at, Time.now.utc)
633
633
 
634
634
  entity_reference = entity_id.blank? ? 'Default' : entity_id
635
- Rails.logger.debug("Fetch Catalog")
636
- Rails.logger.debug("Zuora Entity: #{entity_id.blank? ? 'default' : entity_id}")
635
+ ZuoraConnect.logger.debug("Fetch Catalog")
636
+ ZuoraConnect.logger.debug("Zuora Entity: #{entity_id.blank? ? 'default' : entity_id}")
637
637
 
638
638
  login = zuora_login.client(entity_reference)
639
639
 
@@ -644,12 +644,12 @@ module ZuoraConnect
644
644
  response = {'nextPage' => login.rest_endpoint("catalog/products?pageSize=#{page_size}")}
645
645
  while !response["nextPage"].blank?
646
646
  url = login.rest_endpoint(response["nextPage"].split('/v1/').last)
647
- Rails.logger.debug("Fetch Catalog URL #{url}")
647
+ ZuoraConnect.logger.debug("Fetch Catalog URL #{url}")
648
648
  output_json, response = login.rest_call(:debug => false, :url => url, :errors => [ZuoraAPI::Exceptions::ZuoraAPISessionError], :timeout_retry => true)
649
- Rails.logger.debug("Fetch Catalog Response Code #{response.code}")
649
+ ZuoraConnect.logger.debug("Fetch Catalog Response Code #{response.code}")
650
650
 
651
651
  if !output_json['success'] =~ (/(true|t|yes|y|1)$/i) || output_json['success'].class != TrueClass
652
- Rails.logger.error("Fetch Catalog DATA #{output_json.to_json}")
652
+ ZuoraConnect.logger.error("Fetch Catalog DATA #{output_json.to_json}")
653
653
  raise ZuoraAPI::Exceptions::ZuoraAPIError.new("Error Getting Catalog: #{output_json}")
654
654
  end
655
655
 
@@ -939,9 +939,9 @@ module ZuoraConnect
939
939
 
940
940
  def method_missing(method_sym, *arguments, &block)
941
941
  if method_sym.to_s.include?("login")
942
- Rails.logger.fatal("Method Missing #{method_sym}")
943
- Rails.logger.fatal("Instance Data: #{self.task_data}")
944
- Rails.logger.fatal("Instance Logins: #{self.logins}")
942
+ ZuoraConnect.logger.fatal("Method Missing #{method_sym}")
943
+ ZuoraConnect.logger.fatal("Instance Data: #{self.task_data}")
944
+ ZuoraConnect.logger.fatal("Instance Logins: #{self.logins}")
945
945
  end
946
946
  super
947
947
  end
@@ -12,14 +12,14 @@ module ZuoraConnect
12
12
  end
13
13
 
14
14
  def connect
15
- Rails.logger.debug(self.format_metric_log('Telegraf','Need new connection')) if ZuoraConnect.configuration.telegraf_debug
15
+ ZuoraConnect.logger.debug(self.format_metric_log('Telegraf','Need new connection')) if ZuoraConnect.configuration.telegraf_debug
16
16
  uri = URI.parse(ZuoraConnect.configuration.telegraf_endpoint)
17
17
  self.host = UDPSocket.new.tap do |socket|
18
18
  socket.connect uri.host, uri.port
19
19
  end
20
20
  rescue => ex
21
21
  self.host = nil
22
- Rails.logger.warn(self.format_metric_log('Telegraf', "Failed to connect: #{ex.class}"))
22
+ ZuoraConnect.logger.warn(self.format_metric_log('Telegraf', "Failed to connect: #{ex.class}"))
23
23
  end
24
24
 
25
25
  def write(direction: 'Unknown', tags: {}, values: {})
@@ -44,9 +44,9 @@ module ZuoraConnect
44
44
  end
45
45
  end
46
46
  if ZuoraConnect.configuration.telegraf_debug
47
- Rails.logger.debug(self.format_metric_log('Telegraf', tags.to_s))
48
- Rails.logger.debug(self.format_metric_log('Telegraf', values.to_s))
49
- Rails.logger.debug(self.format_metric_log('Telegraf', "Writing '#{direction.capitalize}': #{time.real.round(5)} ms"))
47
+ ZuoraConnect.logger.debug(self.format_metric_log('Telegraf', tags.to_s))
48
+ ZuoraConnect.logger.debug(self.format_metric_log('Telegraf', values.to_s))
49
+ ZuoraConnect.logger.debug(self.format_metric_log('Telegraf', "Writing '#{direction.capitalize}': #{time.real.round(5)} ms"))
50
50
  end
51
51
  end
52
52
 
@@ -56,14 +56,18 @@ module ZuoraConnect
56
56
  self.host.write InfluxDB::PointValue.new({series: series, tags: tags, values: values}).dump
57
57
  rescue => ex
58
58
  self.connect
59
- Rails.logger.warn(self.format_metric_log('Telegraf',"Failed to write udp: #{ex.class}"))
59
+ ZuoraConnect.logger.warn(self.format_metric_log('Telegraf',"Failed to write udp: #{ex.class}"))
60
60
  end
61
61
 
62
62
  def format_metric_log(message, dump = nil)
63
63
  message_color, dump_color = "1;91", "0;1"
64
64
  log_entry = " \e[#{message_color}m#{message}\e[0m "
65
65
  log_entry << "\e[#{dump_color}m%#{String === dump ? 's' : 'p'}\e[0m" % dump if dump
66
- log_entry
66
+ if Rails.env == :development
67
+ log_entry
68
+ else
69
+ message
70
+ end
67
71
  end
68
72
 
69
73
  def self.app_name
@@ -19,4 +19,13 @@ Resque.module_eval do
19
19
 
20
20
  Hash[queue_names.zip(sizes)]
21
21
  end
22
- end
22
+ end
23
+
24
+ if defined?(Resque)
25
+ Resque.logger = ZuoraConnect.custom_logger(name: "Resque")
26
+ Resque::Scheduler.logger = ZuoraConnect.custom_logger(name: "ResqueScheduler") if defined?(Resque::Scheduler)
27
+ end
28
+
29
+ Makara::Logging::Logger.logger = ZuoraConnect.custom_logger(name: "Makara") if defined?(Makara)
30
+ ElasticAPM.agent.config.logger = ZuoraConnect.custom_logger(name: "ElasticAPM") if defined?(ElasticAPM) && ElasticAPM.running?
31
+ ActionMailer::Base.logger = ZuoraConnect.custom_logger(name: "ActionMailer") if defined?(ActionMailer)
data/lib/metrics/net.rb CHANGED
@@ -212,7 +212,7 @@ if defined?(Rails)
212
212
  if defined?(ActiveSupport) && ActiveSupport.respond_to?(:on_load)
213
213
  # Rails3
214
214
  ActiveSupport.on_load(:after_initialize) do
215
- HttpLogger.logger = Rails.logger unless HttpLogger.logger
215
+ HttpLogger.logger = ZuoraConnect.logger unless HttpLogger.logger
216
216
  end
217
217
  end
218
218
  end
@@ -27,7 +27,6 @@ module Resque
27
27
  ) + "\n"
28
28
  end
29
29
 
30
- Resque.logger = logger
31
30
  Rails.logger = logger
32
31
  case args.class.to_s
33
32
  when "Array"
@@ -13,18 +13,18 @@ module ZuoraConnect
13
13
  start_time = Time.now
14
14
  if request.headers["API-Token"].present?
15
15
  @appinstance = ZuoraConnect::AppInstance.where(:api_token => request.headers["API-Token"]).first
16
- Rails.logger.debug("[#{@appinstance.id}] API REQUEST - API token") if @appinstance.present?
16
+ ZuoraConnect.logger.debug("[#{@appinstance.id}] API REQUEST - API token") if @appinstance.present?
17
17
  check_instance
18
18
  else
19
19
  authenticate_or_request_with_http_basic do |username, password|
20
20
  @appinstance = ZuoraConnect::AppInstance.where(:token => password).first
21
21
  @appinstance ||= ZuoraConnect::AppInstance.where(:api_token => password).first
22
- Rails.logger.debug("[#{@appinstance.id}] API REQUEST - Basic Auth") if @appinstance.present?
22
+ ZuoraConnect.logger.debug("[#{@appinstance.id}] API REQUEST - Basic Auth") if @appinstance.present?
23
23
  check_instance
24
24
  end
25
25
  end
26
26
  if @appinstance.present?
27
- Rails.logger.debug("[#{@appinstance.id}] Authenticate App API Request Completed In - #{(Time.now - start_time).round(2)}s")
27
+ ZuoraConnect.logger.debug("[#{@appinstance.id}] Authenticate App API Request Completed In - #{(Time.now - start_time).round(2)}s")
28
28
  end
29
29
  end
30
30
 
@@ -66,7 +66,7 @@ module ZuoraConnect
66
66
  render "zuora_connect/static/invalid_launch_request"
67
67
  end
68
68
  rescue => ex
69
- Rails.logger.debug("Error parsing Instance ID's: #{ex.message}")
69
+ ZuoraConnect.logger.debug("Error parsing Instance ID's: #{ex.message}")
70
70
  render "zuora_connect/static/invalid_launch_request"
71
71
  end
72
72
  end
@@ -86,7 +86,7 @@ module ZuoraConnect
86
86
  @appinstance.cache_app_instance
87
87
  session["appInstance"] = app_instance_ids[0]
88
88
  else
89
- Rails.logger.fatal("Launch Error: Param Instance didnt match session data")
89
+ ZuoraConnect.logger.fatal("Launch Error: Param Instance didnt match session data")
90
90
  render "zuora_connect/static/invalid_launch_request"
91
91
  return
92
92
  end
@@ -95,7 +95,7 @@ module ZuoraConnect
95
95
  return
96
96
  end
97
97
  rescue => ex
98
- Rails.logger.fatal("Launch Error: #{ex.message}")
98
+ ZuoraConnect.logger.fatal("Launch Error: #{ex.message}")
99
99
  render "zuora_connect/static/invalid_launch_request"
100
100
  return
101
101
  end
@@ -113,7 +113,7 @@ module ZuoraConnect
113
113
  return
114
114
  end
115
115
  rescue => ex
116
- Rails.logger.fatal("Launch Error: #{ex.message}")
116
+ ZuoraConnect.logger.fatal("Launch Error: #{ex.message}")
117
117
  render "zuora_connect/static/invalid_launch_request"
118
118
  return
119
119
  end
@@ -142,10 +142,10 @@ module ZuoraConnect
142
142
  begin
143
143
  I18n.locale = session["#{@appinstance.id}::user::locale"] ? session["#{@appinstance.id}::user::locale"] : @appinstance.locale
144
144
  rescue I18n::InvalidLocale => ex
145
- Rails.logger.error("Invalid Locale: #{ex.message}")
145
+ ZuoraConnect.logger.error("Invalid Locale: #{ex.message}")
146
146
  end
147
147
  Time.zone = session["#{@appinstance.id}::user::timezone"] ? session["#{@appinstance.id}::user::timezone"] : @appinstance.timezone
148
- Rails.logger.debug("[#{@appinstance.blank? ? "N/A" : @appinstance.id}] Authenticate App Request Completed In - #{(Time.now - start_time).round(2)}s")
148
+ ZuoraConnect.logger.debug("[#{@appinstance.blank? ? "N/A" : @appinstance.id}] Authenticate App Request Completed In - #{(Time.now - start_time).round(2)}s")
149
149
  end
150
150
 
151
151
  def persist_connect_app_session
@@ -170,7 +170,7 @@ module ZuoraConnect
170
170
  def setup_instance_via_data
171
171
  session.clear
172
172
  values = JSON.parse(ZuoraConnect::AppInstance.decrypt_response(Base64.urlsafe_decode64(request["data"])))
173
- Rails.logger.debug("Data: #{values.to_json}")
173
+ ZuoraConnect.logger.debug("Data: #{values.to_json}")
174
174
  if values["param_data"]
175
175
  values["param_data"].each do |k ,v|
176
176
  params[k] = v
@@ -185,7 +185,7 @@ module ZuoraConnect
185
185
  session["#{values["appInstance"]}::user::email"] = values["current_user"]["email"]
186
186
  end
187
187
 
188
- Rails.logger.debug("App Params: #{values.to_json}}") if Rails.env != "production"
188
+ ZuoraConnect.logger.debug("App Params: #{values.to_json}}") if Rails.env != "production"
189
189
 
190
190
  @appinstance = ZuoraConnect::AppInstance.where(:id => values["appInstance"].to_i).first
191
191
  if @appinstance.blank?
@@ -193,7 +193,7 @@ module ZuoraConnect
193
193
  begin
194
194
  Apartment::Tenant.create(values["appInstance"].to_s)
195
195
  rescue Apartment::TenantExists => ex
196
- Rails.logger.debug("Tenant Already Exists")
196
+ ZuoraConnect.logger.debug("Tenant Already Exists")
197
197
  end
198
198
  @appinstance = ZuoraConnect::AppInstance.new(:api_token => values[:api_token],:id => values["appInstance"].to_i, :access_token => values["access_token"].blank? ? values["user"] : values["access_token"], :token => values["refresh_token"] , :refresh_token => values["refresh_token"].blank? ? values["key"] : values["refresh_token"], :oauth_expires_at => values["expires"])
199
199
  @appinstance.save(:validate => false)
@@ -1,3 +1,3 @@
1
1
  module ZuoraConnect
2
- VERSION = "1.7.81m"
2
+ VERSION = "1.7.81n"
3
3
  end
data/lib/zuora_connect.rb CHANGED
@@ -15,7 +15,34 @@ require 'metrics/net'
15
15
  module ZuoraConnect
16
16
  class << self
17
17
  attr_accessor :configuration
18
+ attr_writer :logger
19
+
20
+ def logger
21
+ @logger ||= custom_logger(name: "Connect", level: MonoLogger::INFO)
22
+ end
23
+
24
+ def custom_logger(name: "", level: MonoLogger::INFO)
25
+ logger = MonoLogger.new(STDOUT)
26
+ logger.level = level
27
+ logger.formatter = proc do |serverity, datetime, progname, msg|
28
+ begin
29
+ msg = JSON.parse(msg)
30
+ rescue JSON::ParserError => ex
31
+ end
32
+
33
+ require 'json'
34
+ JSON.dump(
35
+ name: name,
36
+ level: serverity,
37
+ timestamp: datetime.strftime('%FT%T.%6N'),
38
+ pid: Process.pid,
39
+ message: msg
40
+ ) + "\n"
41
+ end
42
+ return logger
43
+ end
18
44
  end
45
+
19
46
  module Controllers
20
47
  autoload :Helpers, 'zuora_connect/controllers/helpers'
21
48
  end
@@ -39,4 +66,38 @@ module ZuoraConnect
39
66
 
40
67
  return configuration
41
68
  end
69
+
70
+ def self.elastic_apm_defaults
71
+ defaults = {}
72
+ case Rails.env.to_s
73
+ when 'production'
74
+ defaults = {
75
+ server_url: "http://apm-server.logging:8200",
76
+ transaction_sample_rate: 0.20,
77
+ capture_body: false
78
+ }
79
+ when 'staging'
80
+ defaults = {
81
+ server_url: "http://apm-server.logging:8200",
82
+ transaction_sample_rate: 1.0
83
+ }
84
+ when 'development'
85
+ defaults = {
86
+ server_url: "http://logging.0.ecc.auw2.zuora:8200",
87
+ transaction_sample_rate: 1.0
88
+ }
89
+ end
90
+
91
+ defaults.merge({
92
+ pool_size: 1,
93
+ transaction_max_spans: 500,
94
+ ignore_url_patterns: ['^\/admin\/resque.*', '^\/admin\/redis.*', '^\/admin\/peek.*', '^\/peek.*'],
95
+ verify_server_cert: false,
96
+ log_level: Logger::INFO,
97
+ service_name: ENV['DEIS_APP'].present? ? ENV['DEIS_APP'] : Rails.application.class.parent_name
98
+ })
99
+ defaults.merge({disable_send: true}) if defined?(Rails::Console)
100
+
101
+ return defaults
102
+ end
42
103
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zuora_connect
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.81m
4
+ version: 1.7.81n
5
5
  platform: ruby
6
6
  authors:
7
7
  - Connect Team
@@ -285,7 +285,6 @@ files:
285
285
  - app/views/zuora_connect/static/session_error.html.erb
286
286
  - config/initializers/apartment.rb
287
287
  - config/initializers/aws.rb
288
- - config/initializers/elastic_apm.rb
289
288
  - config/initializers/object_method_hooks.rb
290
289
  - config/initializers/postgresql_adapter.rb
291
290
  - config/initializers/prometheus.rb
@@ -1,25 +0,0 @@
1
- if defined?(ElasticAPM) && ElasticAPM.running?
2
- if !defined?(Rails::Console)
3
- ElasticAPM.agent.config.disable_send = false
4
- else
5
- ElasticAPM.agent.config.disable_send = true
6
- end
7
- case Rails.env.to_s
8
- when 'production'
9
- ElasticAPM.agent.config.server_url = "http://apm-server.logging:8200"
10
- ElasticAPM.agent.config.transaction_sample_rate = 0.20
11
- ElasticAPM.agent.config.capture_body = false
12
- when 'staging'
13
- ElasticAPM.agent.config.server_url = "http://apm-server.logging:8200"
14
- ElasticAPM.agent.config.transaction_sample_rate = 1.0
15
- when 'development'
16
- ElasticAPM.agent.config.server_url = "http://logging.0.ecc.auw2.zuora:8200"
17
- ElasticAPM.agent.config.transaction_sample_rate = 1.0
18
- end
19
- ElasticAPM.agent.config.pool_size = 1
20
- ElasticAPM.agent.config.transaction_max_spans = 500
21
- ElasticAPM.agent.config.ignore_url_patterns = ['^\/admin\/resque.*', '^\/admin\/redis.*', '^\/admin\/peek.*', '^\/peek.*']
22
- ElasticAPM.agent.config.verify_server_cert = false
23
- ElasticAPM.agent.config.log_level = Logger::INFO
24
- ElasticAPM.agent.config.service_name = ::ZuoraConnect::Telegraf.app_name
25
- end