ocean-rails 1.29.5 → 1.29.6

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
  SHA1:
3
- metadata.gz: d3158e42571cf6f00d22e0673c30d2d60b40612d
4
- data.tar.gz: 1e0c86ded7990b0957cd3b1f2c30e7d9bd43c03d
3
+ metadata.gz: 097810be82ab1986758b0b6bd05520922804a791
4
+ data.tar.gz: 7eb017ccf1fa33788cdde74ff79697309bfc0114
5
5
  SHA512:
6
- metadata.gz: d2b4c2823bf36030c272d0e8650ab15620248d34348336470cff7fa5055c5c720b043df74c71ab4c836bd38f07e43c686334e9480e91a852770345834296f65c
7
- data.tar.gz: e8830b8a60562633db5a8604c2570eab91a4314db2ab5e4a54403b9325894549b12188e6138ddcd874d4c2f2cdc4b3f2dfef9c7bb4732abb9d3d05b017b0fb9b
6
+ metadata.gz: 66c096332ee4b2a6d3983cb7a57516ae8d6eb87af3d19b86d5424d48879e372d44e1353d59c225792ab00f4268e1a9cd152edc4ab8510dde75dcaf8c93ad81f3
7
+ data.tar.gz: d06c0e369c4ecb8ffc5820f02bf6b562ea624213187658044ea1bec7a83d7ca833c957fea8bf67ecbf994c32513cac64ceef99994caced189acf255417b56aaa
@@ -1,5 +1,111 @@
1
1
  if Rails.env == 'production' && ENV['NO_ZEROMQ_LOGGING'].blank?
2
2
 
3
+ def remove_existing_log_subscriptions
4
+ ActiveSupport::LogSubscriber.log_subscribers.each do |subscriber|
5
+ case subscriber
6
+ when ActionView::LogSubscriber
7
+ unsubscribe(:action_view, subscriber)
8
+ when ActionController::LogSubscriber
9
+ unsubscribe(:action_controller, subscriber)
10
+ end
11
+ end
12
+ end
13
+
14
+ def unsubscribe(component, subscriber)
15
+ events = subscriber.public_methods(false).reject{ |method| method.to_s == 'call' }
16
+ events.each do |event|
17
+ ActiveSupport::Notifications.notifier.listeners_for("#{event}.#{component}").each do |listener|
18
+ if listener.instance_variable_get('@delegate') == subscriber
19
+ ActiveSupport::Notifications.unsubscribe listener
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ remove_existing_log_subscriptions
26
+
27
+
28
+ ActiveSupport::Notifications.subscribe "halted_callback.action_controller" do |*args|
29
+ data = args.extract_options!
30
+ Thread.current[:filter] = data[:filter]
31
+ end
32
+
33
+
34
+ INTERNAL_PARAMS = %w(controller action format _method only_path)
35
+
36
+ ActiveSupport::Notifications.subscribe "process_action.action_controller" do |name, started, finished, unique_id, payload|
37
+ path = payload[:path]
38
+ if path != '/alive'
39
+
40
+ runtime = finished - started
41
+ param_method = payload[:params]['_method']
42
+ method = param_method ? param_method.upcase : payload[:method]
43
+ status = compute_status(payload)
44
+ params = payload[:params].except(*INTERNAL_PARAMS)
45
+
46
+ data = {
47
+ timestamp: (started.utc.to_f * 1000).to_i,
48
+ method: method,
49
+ status: status,
50
+ runtime: (runtime * 1000).round(0),
51
+ view_runtime: payload[:view_runtime].round(0),
52
+ db_runtime: payload[:db_runtime].round(0)
53
+ }
54
+ data[:params] = params if params.present?
55
+ data[:filter] = Thread.current[:filter] if Thread.current[:filter]
56
+
57
+ Thread.current[:logdata] = data
58
+ end
59
+ end
60
+
61
+ def compute_status payload
62
+ status = payload[:status]
63
+ if status.nil? && payload[:exception].present?
64
+ exception_class_name = payload[:exception].first
65
+ status = ActionDispatch::ExceptionWrapper.status_code_for_exception(exception_class_name)
66
+ end
67
+ status
68
+ end
69
+
70
+
71
+ ActiveSupport::Notifications.subscribe 'request.action_dispatch' do |*args|
72
+ x = args.extract_options!
73
+ request = x[:request]
74
+
75
+ data = Thread.current[:logdata] || {}
76
+ data[:remote_ip] = request.remote_ip
77
+ data[:path] = request.filtered_path
78
+
79
+ if (ac = request.env["action_controller.instance"]) &&
80
+ (response = ac.response) &&
81
+ (body = response.body) &&
82
+ body.present? &&
83
+ body =~ /\A\{"_api_error"/
84
+ data[:_api_error] = JSON.parse(body)['_api_error']
85
+ end
86
+
87
+ ex = request.env["action_dispatch.exception"]
88
+ if ex
89
+ if data[:status] == 404
90
+ data[:path] = request.env["REQUEST_PATH"]
91
+ else
92
+ # We might want to send an email here - exceptions in production
93
+ # should be taken seriously
94
+ data[:exception_message] = ex.message
95
+ data[:exception_backtrace] = ex.backtrace.to_json
96
+ end
97
+ end
98
+
99
+ if data[:status] >= 500
100
+ Rails.logger.fatal data
101
+ elsif data[:status] >= 400
102
+ Rails.logger.error data
103
+ else
104
+ Rails.logger.info data
105
+ end
106
+ end
107
+
108
+
3
109
  # Announce us
4
110
  Rails.logger.info "Initialising Rails process"
5
111
 
data/lib/ocean/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ocean
2
- VERSION = "1.29.5"
2
+ VERSION = "1.29.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ocean-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.29.5
4
+ version: 1.29.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Bengtson
@@ -252,7 +252,6 @@ files:
252
252
  - config/initializers/api_constants.rb
253
253
  - config/initializers/aws_constants.rb
254
254
  - config/initializers/ocean_constants.rb
255
- - config/initializers/one_line_logging.rb
256
255
  - config/initializers/zeromq_logger.rb
257
256
  - config/routes.rb
258
257
  - lib/generators/ocean_scaffold/USAGE
@@ -1,107 +0,0 @@
1
- exit unless Rails.env == 'production'
2
-
3
- def remove_existing_log_subscriptions
4
- ActiveSupport::LogSubscriber.log_subscribers.each do |subscriber|
5
- case subscriber
6
- when ActionView::LogSubscriber
7
- unsubscribe(:action_view, subscriber)
8
- when ActionController::LogSubscriber
9
- unsubscribe(:action_controller, subscriber)
10
- end
11
- end
12
- end
13
-
14
- def unsubscribe(component, subscriber)
15
- events = subscriber.public_methods(false).reject{ |method| method.to_s == 'call' }
16
- events.each do |event|
17
- ActiveSupport::Notifications.notifier.listeners_for("#{event}.#{component}").each do |listener|
18
- if listener.instance_variable_get('@delegate') == subscriber
19
- ActiveSupport::Notifications.unsubscribe listener
20
- end
21
- end
22
- end
23
- end
24
-
25
- remove_existing_log_subscriptions
26
-
27
-
28
- ActiveSupport::Notifications.subscribe "halted_callback.action_controller" do |*args|
29
- data = args.extract_options!
30
- Thread.current[:filter] = data[:filter]
31
- end
32
-
33
-
34
- INTERNAL_PARAMS = %w(controller action format _method only_path)
35
-
36
- ActiveSupport::Notifications.subscribe "process_action.action_controller" do |name, started, finished, unique_id, payload|
37
- path = payload[:path]
38
- if path != '/alive'
39
-
40
- runtime = finished - started
41
- param_method = payload[:params]['_method']
42
- method = param_method ? param_method.upcase : payload[:method]
43
- status = compute_status(payload)
44
- params = payload[:params].except(*INTERNAL_PARAMS)
45
-
46
- data = {
47
- timestamp: (started.utc.to_f * 1000).to_i,
48
- method: method,
49
- status: status,
50
- runtime: (runtime * 1000).round(0),
51
- view_runtime: payload[:view_runtime].round(0),
52
- db_runtime: payload[:db_runtime].round(0)
53
- }
54
- data[:params] = params if params.present?
55
- data[:filter] = Thread.current[:filter] if Thread.current[:filter]
56
-
57
- Thread.current[:logdata] = data
58
- end
59
- end
60
-
61
- def compute_status payload
62
- status = payload[:status]
63
- if status.nil? && payload[:exception].present?
64
- exception_class_name = payload[:exception].first
65
- status = ActionDispatch::ExceptionWrapper.status_code_for_exception(exception_class_name)
66
- end
67
- status
68
- end
69
-
70
-
71
- ActiveSupport::Notifications.subscribe 'request.action_dispatch' do |*args|
72
- x = args.extract_options!
73
- request = x[:request]
74
-
75
- data = Thread.current[:logdata] || {}
76
- data[:remote_ip] = request.remote_ip
77
- data[:path] = request.filtered_path
78
-
79
- if (ac = request.env["action_controller.instance"]) &&
80
- (response = ac.response) &&
81
- (body = response.body) &&
82
- body.present? &&
83
- body =~ /\A\{"_api_error"/
84
- data[:_api_error] = JSON.parse(body)['_api_error']
85
- end
86
-
87
- ex = request.env["action_dispatch.exception"]
88
- if ex
89
- if data[:status] == 404
90
- data[:path] = request.env["REQUEST_PATH"]
91
- else
92
- # We might want to send an email here - exceptions in production
93
- # should be taken seriously
94
- data[:exception_message] = ex.message
95
- data[:exception_backtrace] = ex.backtrace.to_json
96
- end
97
- end
98
-
99
- if data[:status] >= 500
100
- Rails.logger.fatal data
101
- elsif data[:status] >= 400
102
- Rails.logger.error data
103
- else
104
- Rails.logger.info data
105
- end
106
- end
107
-