rails_spotlight 0.3.9 → 0.4.1
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 +4 -4
- data/lib/rails_spotlight/channels/handlers/live_console_handler.rb +1 -1
- data/lib/rails_spotlight/channels/handlers/logs_handler.rb +1 -1
- data/lib/rails_spotlight/configuration.rb +2 -3
- data/lib/rails_spotlight/event.rb +21 -8
- data/lib/rails_spotlight/log_interceptor.rb +53 -5
- data/lib/rails_spotlight/version.rb +1 -1
- data/lib/tasks/init.rake +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b079149e67ffc19722fc8f79f87bc06318ca607e5ec4e4f306b4b166dfe4b0a
|
4
|
+
data.tar.gz: 49fe7c6ef53eb6674d5b49983ccb7a77b3b4fcad9b7c1fda4164ba32d6911016
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 534a0d962aede9bb99c2108f1e0eea6f655bf7bacf56d6227fa37fd89aa858ad6581ea2bb24df6ef79b3f38589f017f4ed2a128620dd36e95fdd25f82f25f609
|
7
|
+
data.tar.gz: ca834260ee821483898464fb1132b9b7add515844bc62c768c908715d6f56989e745489b3d31dbc81f58e2f4be2a1ba090fffa1bed3cd754c9cc31c0f080674e
|
@@ -13,7 +13,7 @@ module RailsSpotlight
|
|
13
13
|
attr_reader :data
|
14
14
|
|
15
15
|
def call
|
16
|
-
return unless ::RailsSpotlight.config.
|
16
|
+
return unless ::RailsSpotlight.config.live_logs_enabled?
|
17
17
|
return unless data['type'] == TYPE
|
18
18
|
|
19
19
|
for_project = Array(data['project'])
|
@@ -9,9 +9,7 @@ module RailsSpotlight
|
|
9
9
|
'ActiveRecord' => [
|
10
10
|
'ActiveRecord::ConnectionAdapters::AbstractAdapter',
|
11
11
|
'ActiveRecord::ConnectionAdapters::PostgreSQLAdapter',
|
12
|
-
'ActiveRecord::ConnectionAdapters::RealTransaction'
|
13
|
-
'ActiveRecord::SchemaMigration',
|
14
|
-
'ActiveRecord::Transaction'
|
12
|
+
'ActiveRecord::ConnectionAdapters::RealTransaction'
|
15
13
|
],
|
16
14
|
'ActionDispatch' => ['ActionDispatch::Request', 'ActionDispatch::Response']
|
17
15
|
}.freeze
|
@@ -79,6 +77,7 @@ module RailsSpotlight
|
|
79
77
|
|
80
78
|
alias live_console_enabled? live_console_enabled
|
81
79
|
alias live_logs_enabled? live_logs_enabled
|
80
|
+
alias use_action_cable? use_action_cable
|
82
81
|
|
83
82
|
def request_completed_broadcast_enabled
|
84
83
|
@request_completed_broadcast_enabled && use_action_cable && action_cable_present?
|
@@ -34,34 +34,47 @@ module RailsSpotlight
|
|
34
34
|
|
35
35
|
private
|
36
36
|
|
37
|
-
def json_encodable(payload)
|
37
|
+
def json_encodable(payload) # rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
|
38
38
|
return {} unless payload.is_a?(Hash)
|
39
39
|
|
40
40
|
transform_hash(payload, deep: true) do |hash, key, value|
|
41
|
-
|
42
|
-
if value_class == 'ActionDispatch::Http::Headers'
|
41
|
+
if value.class.to_s == 'ActionDispatch::Http::Headers'
|
43
42
|
value = value.to_h.select { |k, _| k.upcase == k }
|
44
|
-
elsif
|
43
|
+
elsif value.is_a?(Array) && defined?(ActiveRecord::Relation::QueryAttribute) && value.first.is_a?(ActiveRecord::Relation::QueryAttribute)
|
44
|
+
value = value.map(&method(:map_relation_query_attribute))
|
45
|
+
elsif not_encodable?(value)
|
45
46
|
value = NOT_JSON_ENCODABLE
|
46
47
|
end
|
47
48
|
|
48
49
|
begin
|
49
50
|
value.to_json(methods: [:duration])
|
50
51
|
new_value = value
|
51
|
-
rescue
|
52
|
+
rescue # rubocop:disable Lint/RedundantCopDisableDirective, Style/RescueStandardError
|
52
53
|
new_value = NOT_JSON_ENCODABLE
|
53
54
|
end
|
54
|
-
hash[key] = new_value
|
55
|
+
hash[key] = new_value # encode_value(value)
|
55
56
|
end.with_indifferent_access
|
56
57
|
end
|
57
58
|
|
59
|
+
# ActiveRecord::Relation::QueryAttribute implementation changed in Rails 7.1 it getting binds need to be manually added
|
60
|
+
def map_relation_query_attribute(attr)
|
61
|
+
{
|
62
|
+
name: attr.name,
|
63
|
+
value: attr.value,
|
64
|
+
value_before_type_cast: attr.value_before_type_cast,
|
65
|
+
value_for_database: attr.value_for_database
|
66
|
+
# resign from type and original_attribute for now
|
67
|
+
# type: attr.type,
|
68
|
+
# original_attribute: attr.original_attribute or attr.original_value_for_database,
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
58
72
|
def not_encodable?(value)
|
59
73
|
::RailsSpotlight.config.not_encodable_event_values.any? do |module_name, class_names|
|
60
74
|
next unless defined?(module_name.constantize)
|
61
75
|
|
62
76
|
class_names.any? { |class_name| value.is_a?(class_name.constantize) }
|
63
|
-
rescue # rubocop:disable Lint/
|
64
|
-
false
|
77
|
+
rescue # rubocop:disable Lint/SuppressedException, Style/RescueStandardError
|
65
78
|
end
|
66
79
|
end
|
67
80
|
|
@@ -23,26 +23,74 @@ module RailsSpotlight
|
|
23
23
|
end
|
24
24
|
return true if _skip_logging?(message)
|
25
25
|
|
26
|
-
|
26
|
+
_rails_spotlight_log(SEVERITY_MAP[severity], message, progname, :broadcast)
|
27
27
|
super(severity, message, progname) if defined?(super)
|
28
28
|
true
|
29
29
|
end
|
30
30
|
|
31
|
+
def debug(message = nil, *args)
|
32
|
+
message = yield if message.nil? && block_given?
|
33
|
+
_rails_spotlight_log(:debug, message)
|
34
|
+
super
|
35
|
+
end
|
36
|
+
|
37
|
+
def info(message = nil, *args)
|
38
|
+
message = yield if message.nil? && block_given?
|
39
|
+
_rails_spotlight_log(:info, message)
|
40
|
+
super
|
41
|
+
end
|
42
|
+
|
43
|
+
def warn(message = nil, *args)
|
44
|
+
message = yield if message.nil? && block_given?
|
45
|
+
_rails_spotlight_log(:warn, message)
|
46
|
+
super
|
47
|
+
end
|
48
|
+
|
49
|
+
def error(message = nil, *args)
|
50
|
+
message = yield if message.nil? && block_given?
|
51
|
+
_rails_spotlight_log(:error, message)
|
52
|
+
super
|
53
|
+
end
|
54
|
+
|
55
|
+
def fatal(message = nil, *args)
|
56
|
+
message = yield if message.nil? && block_given?
|
57
|
+
_rails_spotlight_log(:fatal, message)
|
58
|
+
super
|
59
|
+
end
|
60
|
+
|
61
|
+
def unknown(message = nil, *args)
|
62
|
+
message = yield if message.nil? && block_given?
|
63
|
+
_rails_spotlight_log(:unknown, message)
|
64
|
+
super
|
65
|
+
end
|
66
|
+
|
31
67
|
private
|
32
68
|
|
33
69
|
def _skip_logging?(message)
|
34
|
-
return false unless ::RailsSpotlight.config.
|
70
|
+
return false unless ::RailsSpotlight.config.use_action_cable?
|
35
71
|
return false unless message.is_a?(String)
|
36
72
|
|
37
73
|
message.include?(::RailsSpotlight::Channels::SPOTLIGHT_CHANNEL)
|
38
74
|
end
|
39
75
|
|
40
|
-
def
|
76
|
+
def _rails_spotlight_log(level, message, progname = nil, output = :event)
|
41
77
|
callsite = Utils.dev_callsite(caller.drop(1))
|
42
78
|
name = progname.is_a?(String) || progname.is_a?(Symbol) ? progname : nil
|
43
|
-
|
79
|
+
output == :event ? _push_event(level, message, name) : _broadcast_log(message, level, callsite, name)
|
80
|
+
rescue StandardError => e
|
81
|
+
RailsSpotlight.config.logger.fatal("#{e.message}\n #{e.backtrace.join("\n ")}")
|
82
|
+
end
|
83
|
+
|
84
|
+
def _push_event(level, message, progname = nil)
|
85
|
+
callsite = Utils.dev_callsite(caller.drop(1)) || {}
|
86
|
+
name = progname.is_a?(String) || progname.is_a?(Symbol) ? progname : nil
|
87
|
+
AppRequest.current.events << Event.new('rsl.notification.log', 0, 0, 0, callsite.merge(message: message, level: level, progname: name)) if AppRequest.current
|
88
|
+
rescue StandardError => e
|
89
|
+
RailsSpotlight.config.logger.fatal("#{e.message}\n #{e.backtrace.join("\n ")}")
|
90
|
+
end
|
44
91
|
|
45
|
-
|
92
|
+
def _broadcast_log(message, level, callsite = {}, name = nil)
|
93
|
+
return unless ::RailsSpotlight.config.use_action_cable?
|
46
94
|
return if message.blank?
|
47
95
|
|
48
96
|
id = AppRequest.current ? AppRequest.current.id : nil # rubocop:disable Style/SafeNavigation
|
data/lib/tasks/init.rake
CHANGED
@@ -16,7 +16,7 @@ namespace :rails_spotlight do # rubocop:disable Metrics/BlockLength
|
|
16
16
|
STORAGE_PATH: <%=Rails.root.join('tmp', 'data', 'rails_spotlight')%>
|
17
17
|
STORAGE_POOL_SIZE: 20
|
18
18
|
LOGGER: <%=Logger.new(Rails.root.join('log', 'rails_spotlight.log'))%>
|
19
|
-
# Prevent from processing and sending some data to the extension
|
19
|
+
# Prevent from processing and sending some data to the extension
|
20
20
|
MIDDLEWARE_SKIPPED_PATHS: []
|
21
21
|
NOT_ENCODABLE_EVENT_VALUES:
|
22
22
|
SKIP_RENDERED_IVARS: []
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_spotlight
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pawel Niemczyk
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-09-
|
11
|
+
date: 2024-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack-contrib
|