logstasher 1.3.0 → 2.1.0
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/logstasher.rb +38 -37
- data/lib/logstasher/action_view/log_subscriber.rb +6 -7
- data/lib/logstasher/active_job/log_subscriber.rb +19 -13
- data/lib/logstasher/active_record/log_subscriber.rb +10 -7
- data/lib/logstasher/active_support/log_subscriber.rb +15 -16
- data/lib/logstasher/active_support/mailer_log_subscriber.rb +9 -4
- data/lib/logstasher/custom_fields.rb +1 -1
- data/lib/logstasher/device/redis.rb +5 -6
- data/lib/logstasher/event.rb +32 -0
- data/lib/logstasher/rails_ext/action_controller/base.rb +4 -4
- data/lib/logstasher/rails_ext/action_controller/metal/instrumentation.rb +16 -12
- data/lib/logstasher/rails_ext/rack/logger.rb +1 -2
- data/lib/logstasher/railtie.rb +12 -5
- data/lib/logstasher/version.rb +1 -1
- metadata +17 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7bf19f1cccbb941b087f15328764d07da66e7006a0db9dd64c14f192d0fbb9b
|
4
|
+
data.tar.gz: dc5af64c9333ac0c42a67977519049d6f78233a7c50e3ce353120ff382f9c97b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60064a14f73422c0a1be36a9052d8d73741287d370876592b610ac4f9b27e4fec42ab3173b8cfd9d65e75e8ae331558a1516aca17ede477e39a4b8d575f3ae67
|
7
|
+
data.tar.gz: 17323dff796913fd335fc6142f640c10a281e618ce08ce0836a33b26c669d1a669317a394ecc594e4a2e9d3b8c35bcb19b74200636118c6cf42ce2e12d62a9a4
|
data/lib/logstasher.rb
CHANGED
@@ -6,6 +6,7 @@ require 'logstasher/action_view/log_subscriber' if defined?(ActionView)
|
|
6
6
|
require 'logstasher/active_job/log_subscriber' if defined?(ActiveJob)
|
7
7
|
require 'logstasher/rails_ext/action_controller/base'
|
8
8
|
require 'logstasher/custom_fields'
|
9
|
+
require 'logstasher/event'
|
9
10
|
require 'request_store'
|
10
11
|
require 'active_support/core_ext/module/attribute_accessors'
|
11
12
|
require 'active_support/core_ext/string/inflections'
|
@@ -17,7 +18,8 @@ module LogStasher
|
|
17
18
|
REQUEST_CONTEXT_KEY = :logstasher_request_context
|
18
19
|
|
19
20
|
attr_accessor :logger, :logger_path, :enabled, :log_controller_parameters, :source, :backtrace,
|
20
|
-
|
21
|
+
:controller_monkey_patch, :field_renaming
|
22
|
+
|
21
23
|
# Setting the default to 'unknown' to define the default behaviour
|
22
24
|
@source = 'unknown'
|
23
25
|
# By default log the backtrace of exceptions
|
@@ -26,27 +28,27 @@ module LogStasher
|
|
26
28
|
def remove_existing_log_subscriptions
|
27
29
|
::ActiveSupport::LogSubscriber.log_subscribers.each do |subscriber|
|
28
30
|
case subscriber.class.name
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
31
|
+
when 'ActionView::LogSubscriber'
|
32
|
+
unsubscribe(:action_view, subscriber)
|
33
|
+
when 'ActionController::LogSubscriber'
|
34
|
+
unsubscribe(:action_controller, subscriber)
|
35
|
+
when 'ActionMailer::LogSubscriber'
|
36
|
+
unsubscribe(:action_mailer, subscriber)
|
37
|
+
when 'ActiveRecord::LogSubscriber'
|
38
|
+
unsubscribe(:active_record, subscriber)
|
39
|
+
when 'ActiveJob::LogSubscriber' # For Rails 6
|
40
|
+
unsubscribe(:active_job, subscriber)
|
41
|
+
when 'ActiveJob::Logging::LogSubscriber' # For Rails 5
|
42
|
+
unsubscribe(:active_job, subscriber)
|
39
43
|
end
|
40
44
|
end
|
41
45
|
end
|
42
46
|
|
43
47
|
def unsubscribe(component, subscriber)
|
44
|
-
events = subscriber.public_methods(false).reject{ |method| method.to_s == 'call' }
|
48
|
+
events = subscriber.public_methods(false).reject { |method| method.to_s == 'call' }
|
45
49
|
events.each do |event|
|
46
50
|
::ActiveSupport::Notifications.notifier.listeners_for("#{event}.#{component}").each do |listener|
|
47
|
-
if listener.instance_variable_get('@delegate') == subscriber
|
48
|
-
::ActiveSupport::Notifications.unsubscribe listener
|
49
|
-
end
|
51
|
+
::ActiveSupport::Notifications.unsubscribe listener if listener.instance_variable_get('@delegate') == subscriber
|
50
52
|
end
|
51
53
|
end
|
52
54
|
end
|
@@ -56,14 +58,14 @@ module LogStasher
|
|
56
58
|
payload[:route] = "#{request.params[:controller]}##{request.params[:action]}"
|
57
59
|
payload[:request_id] = request.env['action_dispatch.request_id']
|
58
60
|
LogStasher::CustomFields.add(:ip, :route, :request_id)
|
59
|
-
if
|
61
|
+
if log_controller_parameters
|
60
62
|
payload[:parameters] = payload[:params].except(*::ActionController::LogSubscriber::INTERNAL_PARAMS)
|
61
63
|
LogStasher::CustomFields.add(:parameters)
|
62
64
|
end
|
63
65
|
end
|
64
66
|
|
65
67
|
def add_custom_fields(&block)
|
66
|
-
wrapped_block =
|
68
|
+
wrapped_block = proc do |fields|
|
67
69
|
LogStasher::CustomFields.add(*LogStasher.store.keys)
|
68
70
|
instance_exec(fields, &block)
|
69
71
|
end
|
@@ -72,7 +74,7 @@ module LogStasher
|
|
72
74
|
end
|
73
75
|
|
74
76
|
def add_custom_fields_to_request_context(&block)
|
75
|
-
wrapped_block =
|
77
|
+
wrapped_block = proc do |fields|
|
76
78
|
instance_exec(fields, &block)
|
77
79
|
LogStasher::CustomFields.add(*fields.keys)
|
78
80
|
end
|
@@ -89,7 +91,6 @@ module LogStasher
|
|
89
91
|
end
|
90
92
|
|
91
93
|
def setup_before(config)
|
92
|
-
require 'logstash-event'
|
93
94
|
self.enabled = config.enabled
|
94
95
|
LogStasher::ActiveSupport::LogSubscriber.attach_to :action_controller if config.controller_enabled
|
95
96
|
LogStasher::ActiveSupport::MailerLogSubscriber.attach_to :action_mailer if config.mailer_enabled
|
@@ -100,27 +101,27 @@ module LogStasher
|
|
100
101
|
|
101
102
|
def setup(config)
|
102
103
|
# Path instrumentation class to insert our hook
|
103
|
-
if (!
|
104
|
+
if (!config.controller_monkey_patch && config.controller_monkey_patch != false) || config.controller_monkey_patch == true
|
104
105
|
require 'logstasher/rails_ext/action_controller/metal/instrumentation'
|
105
106
|
end
|
106
|
-
|
107
|
+
suppress_app_logs(config)
|
107
108
|
self.logger_path = config.logger_path || "#{Rails.root}/log/logstash_#{Rails.env}.log"
|
108
|
-
self.logger = config.logger || new_logger(
|
109
|
-
|
109
|
+
self.logger = config.logger || new_logger(logger_path)
|
110
|
+
logger.level = config.log_level || Logger::WARN
|
110
111
|
self.source = config.source unless config.source.nil?
|
111
|
-
self.log_controller_parameters = !!
|
112
|
-
self.backtrace = !!
|
113
|
-
|
114
|
-
|
112
|
+
self.log_controller_parameters = !!config.log_controller_parameters
|
113
|
+
self.backtrace = !!config.backtrace unless config.backtrace.nil?
|
114
|
+
set_data_for_rake
|
115
|
+
set_data_for_console
|
115
116
|
self.field_renaming = Hash(config.field_renaming)
|
116
117
|
end
|
117
118
|
|
118
119
|
def set_data_for_rake
|
119
|
-
|
120
|
+
request_context['request_id'] = ::Rake.application.top_level_tasks if called_as_rake?
|
120
121
|
end
|
121
122
|
|
122
123
|
def set_data_for_console
|
123
|
-
|
124
|
+
request_context['request_id'] = Process.pid.to_s if called_as_console?
|
124
125
|
end
|
125
126
|
|
126
127
|
def called_as_rake?
|
@@ -158,10 +159,10 @@ module LogStasher
|
|
158
159
|
# LogStasher.info("message", tags:["tag1", "tag2"])
|
159
160
|
# LogStasher.info("message", timing:1234)
|
160
161
|
# LogStasher.info(custom1:"yes", custom2:"no")
|
161
|
-
def log(severity, message, additional_fields={})
|
162
|
-
if
|
162
|
+
def log(severity, message, additional_fields = {})
|
163
|
+
if logger && logger.send("#{severity}?")
|
163
164
|
|
164
|
-
data = {'level' => severity}
|
165
|
+
data = { 'level' => severity }
|
165
166
|
if message.respond_to?(:to_hash)
|
166
167
|
data.merge!(message.to_hash)
|
167
168
|
else
|
@@ -172,16 +173,16 @@ module LogStasher
|
|
172
173
|
tags = Array(additional_fields.delete(:tags) || 'log')
|
173
174
|
|
174
175
|
data.merge!(additional_fields)
|
175
|
-
|
176
|
+
logger << build_logstash_event(data, tags).to_json + "\n"
|
176
177
|
|
177
178
|
end
|
178
179
|
end
|
179
180
|
|
180
181
|
def build_logstash_event(data, tags)
|
181
182
|
field_renaming.each do |old_name, new_name|
|
182
|
-
|
183
|
+
data[new_name] = data.delete(old_name) if data.key?(old_name)
|
183
184
|
end
|
184
|
-
|
185
|
+
Event.new(data.merge('source' => source, 'tags' => tags))
|
185
186
|
end
|
186
187
|
|
187
188
|
def store
|
@@ -204,7 +205,7 @@ module LogStasher
|
|
204
205
|
end
|
205
206
|
end
|
206
207
|
|
207
|
-
%w
|
208
|
+
%w[fatal error warn info debug unknown].each do |severity|
|
208
209
|
eval <<-EOM, nil, __FILE__, __LINE__ + 1
|
209
210
|
def #{severity}(message=nil, additional_fields={})
|
210
211
|
self.log(:#{severity}, message, additional_fields)
|
@@ -213,7 +214,7 @@ module LogStasher
|
|
213
214
|
end
|
214
215
|
|
215
216
|
def enabled?
|
216
|
-
|
217
|
+
enabled || false
|
217
218
|
end
|
218
219
|
|
219
220
|
private
|
@@ -10,8 +10,8 @@ module LogStasher
|
|
10
10
|
def render_template(event)
|
11
11
|
logstash_event(event)
|
12
12
|
end
|
13
|
-
alias
|
14
|
-
alias
|
13
|
+
alias render_partial render_template
|
14
|
+
alias render_collection render_template
|
15
15
|
|
16
16
|
def logger
|
17
17
|
LogStasher.logger
|
@@ -35,7 +35,7 @@ module LogStasher
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def extract_data(data)
|
38
|
-
{
|
38
|
+
{ identifier: from_rails_root(data[:identifier]) }
|
39
39
|
end
|
40
40
|
|
41
41
|
def request_context
|
@@ -49,16 +49,15 @@ module LogStasher
|
|
49
49
|
def event_data(event)
|
50
50
|
{
|
51
51
|
name: event.name,
|
52
|
-
transaction_id: event.transaction_id
|
52
|
+
transaction_id: event.transaction_id
|
53
53
|
}
|
54
54
|
end
|
55
55
|
|
56
56
|
def runtimes(event)
|
57
57
|
{
|
58
|
-
duration: event.duration
|
59
|
-
}.
|
58
|
+
duration: event.duration
|
59
|
+
}.each_with_object({}) do |(name, runtime), runtimes|
|
60
60
|
runtimes[name] = runtime.to_f.round(2) if runtime
|
61
|
-
runtimes
|
62
61
|
end
|
63
62
|
end
|
64
63
|
end
|
@@ -1,13 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
if ActiveJob::VERSION::MAJOR >= 6 && ActiveJob::VERSION::MINOR >= 1
|
2
|
+
require 'active_job/log_subscriber'
|
3
|
+
else
|
4
|
+
require 'active_job/logging'
|
5
5
|
end
|
6
6
|
|
7
7
|
module LogStasher
|
8
8
|
module ActiveJob
|
9
|
-
class LogSubscriber < ::ActiveJob::Logging::LogSubscriber
|
10
9
|
|
10
|
+
BASE_SUBSCRIBER = if defined?(::ActiveJob::LogSubscriber)
|
11
|
+
::ActiveJob::LogSubscriber
|
12
|
+
else
|
13
|
+
::ActiveJob::Logging::LogSubscriber
|
14
|
+
end
|
15
|
+
|
16
|
+
class LogSubscriber < BASE_SUBSCRIBER
|
11
17
|
def enqueue(event)
|
12
18
|
process_event(event, 'enqueue')
|
13
19
|
end
|
@@ -59,15 +65,15 @@ module LogStasher
|
|
59
65
|
|
60
66
|
def extract_metadata(event)
|
61
67
|
{
|
62
|
-
:
|
63
|
-
:
|
64
|
-
:
|
65
|
-
:
|
68
|
+
job_id: event.payload[:job].job_id,
|
69
|
+
queue_name: queue_name(event),
|
70
|
+
job_class: event.payload[:job].class.to_s,
|
71
|
+
job_args: args_info(event.payload[:job])
|
66
72
|
}
|
67
73
|
end
|
68
74
|
|
69
75
|
def extract_duration(event)
|
70
|
-
{ :
|
76
|
+
{ duration: event.duration.to_f.round(2) }
|
71
77
|
end
|
72
78
|
|
73
79
|
def extract_exception(event)
|
@@ -75,7 +81,7 @@ module LogStasher
|
|
75
81
|
end
|
76
82
|
|
77
83
|
def extract_scheduled_at(event)
|
78
|
-
{ :
|
84
|
+
{ scheduled_at: scheduled_at(event) }
|
79
85
|
end
|
80
86
|
|
81
87
|
def request_context
|
@@ -86,7 +92,7 @@ module LogStasher
|
|
86
92
|
def args_info(job)
|
87
93
|
job.arguments.map { |arg| arg.try(:to_global_id).try(:to_s) || arg }
|
88
94
|
end
|
89
|
-
|
90
95
|
end
|
91
96
|
end
|
92
|
-
end
|
97
|
+
end
|
98
|
+
|
@@ -9,11 +9,9 @@ module LogStasher
|
|
9
9
|
|
10
10
|
def identity(event)
|
11
11
|
lsevent = logstash_event(event)
|
12
|
-
if logger && lsevent
|
13
|
-
logger << lsevent.to_json + "\n"
|
14
|
-
end
|
12
|
+
logger << lsevent.to_json + "\n" if logger && lsevent
|
15
13
|
end
|
16
|
-
alias
|
14
|
+
alias sql identity
|
17
15
|
|
18
16
|
def logger
|
19
17
|
LogStasher.logger
|
@@ -22,17 +20,22 @@ module LogStasher
|
|
22
20
|
private
|
23
21
|
|
24
22
|
def logstash_event(event)
|
25
|
-
|
23
|
+
self.class.runtime += event.duration
|
24
|
+
data = event.payload.dup
|
26
25
|
|
27
26
|
return if 'SCHEMA' == data[:name]
|
28
27
|
|
28
|
+
# A connection cannot be converted to JSON as it fails with
|
29
|
+
# SystemStackError when running against ActiveSupport JSON patches.
|
30
|
+
data.delete(:connection)
|
31
|
+
|
29
32
|
data.merge! runtimes(event)
|
30
33
|
data.merge! extract_sql(data)
|
31
34
|
data.merge! request_context
|
32
35
|
data.merge! LogStasher.store
|
33
36
|
data.merge! extract_custom_fields(data)
|
34
37
|
|
35
|
-
tags = [
|
38
|
+
tags = ['request']
|
36
39
|
tags.push('exception') if data[:exception]
|
37
40
|
LogStasher.build_logstash_event(data, tags)
|
38
41
|
end
|
@@ -45,7 +48,7 @@ module LogStasher
|
|
45
48
|
if event.duration
|
46
49
|
{ duration: event.duration.to_f.round(2) }
|
47
50
|
else
|
48
|
-
{
|
51
|
+
{}
|
49
52
|
end
|
50
53
|
end
|
51
54
|
|
@@ -44,7 +44,7 @@ module LogStasher
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def extract_path(payload)
|
47
|
-
payload[:path].split(
|
47
|
+
payload[:path].split('?').first
|
48
48
|
end
|
49
49
|
|
50
50
|
def extract_format(payload)
|
@@ -57,27 +57,26 @@ module LogStasher
|
|
57
57
|
|
58
58
|
def extract_status(payload)
|
59
59
|
if payload[:status]
|
60
|
-
{ :
|
60
|
+
{ status: payload[:status].to_i }
|
61
61
|
else
|
62
|
-
{ :
|
62
|
+
{ status: 0 }
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
66
|
def runtimes(event)
|
67
67
|
{
|
68
|
-
:
|
69
|
-
:
|
70
|
-
:
|
71
|
-
}.
|
68
|
+
duration: event.duration,
|
69
|
+
view: event.payload[:view_runtime],
|
70
|
+
db: event.payload[:db_runtime]
|
71
|
+
}.each_with_object({}) do |(name, runtime), runtimes|
|
72
72
|
runtimes[name] = runtime.to_f.round(2) if runtime
|
73
|
-
runtimes
|
74
73
|
end
|
75
74
|
end
|
76
75
|
|
77
|
-
def location(
|
76
|
+
def location(_event)
|
78
77
|
if location = Thread.current[:logstasher_location]
|
79
78
|
Thread.current[:logstasher_location] = nil
|
80
|
-
{ :
|
79
|
+
{ location: location }
|
81
80
|
else
|
82
81
|
{}
|
83
82
|
end
|
@@ -88,13 +87,13 @@ module LogStasher
|
|
88
87
|
if payload[:exception]
|
89
88
|
exception, message = payload[:exception]
|
90
89
|
status = ::ActionDispatch::ExceptionWrapper.status_code_for_exception(exception)
|
91
|
-
if LogStasher.backtrace
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
90
|
+
backtrace = if LogStasher.backtrace
|
91
|
+
$!.backtrace.join("\n")
|
92
|
+
else
|
93
|
+
$!.backtrace.first
|
94
|
+
end
|
96
95
|
message = "#{exception}\n#{message}\n#{backtrace}"
|
97
|
-
{ :
|
96
|
+
{ status: status, error: message }
|
98
97
|
else
|
99
98
|
{}
|
100
99
|
end
|
@@ -4,18 +4,23 @@ require 'active_support/log_subscriber'
|
|
4
4
|
module LogStasher
|
5
5
|
module ActiveSupport
|
6
6
|
class MailerLogSubscriber < ::ActiveSupport::LogSubscriber
|
7
|
-
MAILER_FIELDS = [
|
7
|
+
MAILER_FIELDS = %i[mailer action message_id from to].freeze
|
8
8
|
|
9
9
|
def deliver(event)
|
10
|
-
process_event(event, [
|
10
|
+
process_event(event, %w[mailer deliver])
|
11
11
|
end
|
12
12
|
|
13
|
+
# This method will only be invoked on Rails 6.0 and prior.
|
14
|
+
# Starting in Rails 6.0 the receive method was deprecated in
|
15
|
+
# favor of ActionMailbox. The receive method was removed
|
16
|
+
# from ActionMailer in Rails 6.1, and there doesn't appear to
|
17
|
+
# be corresponding instrumentation for ActionMailbox.
|
13
18
|
def receive(event)
|
14
|
-
process_event(event, [
|
19
|
+
process_event(event, %w[mailer receive])
|
15
20
|
end
|
16
21
|
|
17
22
|
def process(event)
|
18
|
-
process_event(event, [
|
23
|
+
process_event(event, %w[mailer process])
|
19
24
|
end
|
20
25
|
|
21
26
|
def logger
|
@@ -3,7 +3,6 @@ require 'redis'
|
|
3
3
|
module LogStasher
|
4
4
|
module Device
|
5
5
|
class Redis
|
6
|
-
|
7
6
|
attr_reader :options, :redis
|
8
7
|
|
9
8
|
def initialize(options = {})
|
@@ -23,7 +22,7 @@ module LogStasher
|
|
23
22
|
def redis_options
|
24
23
|
unless @redis_options
|
25
24
|
default_keys = default_options.keys
|
26
|
-
@redis_options = options.select { |k,
|
25
|
+
@redis_options = options.select { |k, _v| !default_keys.include?(k) }
|
27
26
|
end
|
28
27
|
|
29
28
|
@redis_options
|
@@ -36,7 +35,7 @@ module LogStasher
|
|
36
35
|
when 'channel'
|
37
36
|
redis.publish(key, log)
|
38
37
|
else
|
39
|
-
|
38
|
+
raise "Unknown data type #{data_type}"
|
40
39
|
end
|
41
40
|
end
|
42
41
|
|
@@ -51,12 +50,12 @@ module LogStasher
|
|
51
50
|
end
|
52
51
|
|
53
52
|
def default_options
|
54
|
-
|
53
|
+
{ key: 'logstash', data_type: 'list' }
|
55
54
|
end
|
56
55
|
|
57
56
|
def validate_options
|
58
|
-
unless [
|
59
|
-
|
57
|
+
unless %w[list channel].include?(options[:data_type])
|
58
|
+
raise 'Expected :data_type to be either "list" or "channel"'
|
60
59
|
end
|
61
60
|
end
|
62
61
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'time'
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
module LogStasher
|
6
|
+
class Event
|
7
|
+
def initialize(data = {})
|
8
|
+
@cancelled = false
|
9
|
+
|
10
|
+
@data = data
|
11
|
+
if data.include?('@timestamp')
|
12
|
+
t = data['@timestamp']
|
13
|
+
data['@timestamp'] = Time.parse(t).gmtime.iso8601(3) if t.is_a?(String)
|
14
|
+
else
|
15
|
+
data['@timestamp'] = ::Time.now.utc.iso8601(3)
|
16
|
+
end
|
17
|
+
data['@version'] = '1' unless @data.include?('@version')
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
to_json.to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_json(*args)
|
25
|
+
@data.to_json(*args)
|
26
|
+
end
|
27
|
+
|
28
|
+
def [](key)
|
29
|
+
@data[key]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -9,17 +9,17 @@ module LogStasher
|
|
9
9
|
super(*args)
|
10
10
|
LogStasher::CustomFields.clear
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
private
|
14
14
|
|
15
15
|
# this method is called from within super of process_action.
|
16
16
|
def append_info_to_payload(payload) #:nodoc:
|
17
17
|
LogStasher.add_default_fields_to_payload(payload, request)
|
18
|
-
if
|
18
|
+
if respond_to?(:logstasher_add_custom_fields_to_request_context)
|
19
19
|
logstasher_add_custom_fields_to_request_context(LogStasher.request_context)
|
20
20
|
end
|
21
21
|
|
22
|
-
if
|
22
|
+
if respond_to?(:logstasher_add_custom_fields_to_payload)
|
23
23
|
before_keys = payload.keys.clone
|
24
24
|
logstasher_add_custom_fields_to_payload(payload)
|
25
25
|
after_keys = payload.keys
|
@@ -38,7 +38,7 @@ module LogStasher
|
|
38
38
|
payload[key] = value
|
39
39
|
end
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
def add_custom_fields_to_store
|
43
43
|
LogStasher.store[:ip] = request.remote_ip
|
44
44
|
LogStasher.store[:route] = "#{request.params[:controller]}##{request.params[:action]}"
|
@@ -1,14 +1,18 @@
|
|
1
1
|
module ActionController
|
2
2
|
module Instrumentation
|
3
|
-
alias
|
3
|
+
alias orig_process_action process_action
|
4
4
|
def process_action(*args)
|
5
5
|
raw_payload = {
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
controller: self.class.name,
|
7
|
+
action: action_name,
|
8
|
+
params: request.filtered_parameters,
|
9
|
+
format: request.format.try(:ref),
|
10
|
+
method: request.method,
|
11
|
+
path: begin
|
12
|
+
request.fullpath
|
13
|
+
rescue StandardError
|
14
|
+
'unknown'
|
15
|
+
end
|
12
16
|
}
|
13
17
|
|
14
18
|
LogStasher.add_default_fields_to_payload(raw_payload, request)
|
@@ -16,14 +20,14 @@ module ActionController
|
|
16
20
|
LogStasher.clear_request_context
|
17
21
|
LogStasher.add_default_fields_to_request_context(request)
|
18
22
|
|
19
|
-
ActiveSupport::Notifications.instrument(
|
23
|
+
ActiveSupport::Notifications.instrument('start_processing.action_controller', raw_payload.dup)
|
20
24
|
|
21
|
-
ActiveSupport::Notifications.instrument(
|
22
|
-
if
|
25
|
+
ActiveSupport::Notifications.instrument('process_action.action_controller', raw_payload) do |payload|
|
26
|
+
if respond_to?(:logstasher_add_custom_fields_to_request_context)
|
23
27
|
logstasher_add_custom_fields_to_request_context(LogStasher.request_context)
|
24
28
|
end
|
25
29
|
|
26
|
-
if
|
30
|
+
if respond_to?(:logstasher_add_custom_fields_to_payload)
|
27
31
|
before_keys = raw_payload.keys.clone
|
28
32
|
logstasher_add_custom_fields_to_payload(raw_payload)
|
29
33
|
after_keys = raw_payload.keys
|
@@ -45,6 +49,6 @@ module ActionController
|
|
45
49
|
result
|
46
50
|
end
|
47
51
|
end
|
48
|
-
alias
|
52
|
+
alias logstasher_process_action process_action
|
49
53
|
end
|
50
54
|
end
|
data/lib/logstasher/railtie.rb
CHANGED
@@ -17,12 +17,12 @@ module LogStasher
|
|
17
17
|
|
18
18
|
# Try loading the config/logstasher.yml if present
|
19
19
|
env = Rails.env.to_sym || :development
|
20
|
-
config_file = File.expand_path
|
20
|
+
config_file = File.expand_path './config/logstasher.yml'
|
21
21
|
|
22
22
|
# Load and ERB templating of YAML files
|
23
|
-
LOGSTASHER = File.
|
23
|
+
LOGSTASHER = File.exist?(config_file) ? YAML.load(ERB.new(File.read(config_file)).result).symbolize_keys : nil
|
24
24
|
|
25
|
-
initializer :logstasher, :
|
25
|
+
initializer :logstasher, before: :load_config_initializers do |app|
|
26
26
|
if LOGSTASHER.present?
|
27
27
|
# process common configs
|
28
28
|
LogStasher.process_config(app.config.logstasher, LOGSTASHER)
|
@@ -30,7 +30,8 @@ module LogStasher
|
|
30
30
|
LogStasher.process_config(app.config.logstasher, LOGSTASHER[env].symbolize_keys) if LOGSTASHER.key? env
|
31
31
|
end
|
32
32
|
|
33
|
-
app.config.action_dispatch.rack_cache[:verbose] = false if app
|
33
|
+
app.config.action_dispatch.rack_cache[:verbose] = false if rack_cache_hashlike?(app)
|
34
|
+
|
34
35
|
LogStasher.setup_before(app.config.logstasher) if app.config.logstasher.enabled
|
35
36
|
end
|
36
37
|
|
@@ -39,6 +40,10 @@ module LogStasher
|
|
39
40
|
LogStasher.setup(config.logstasher) if config.logstasher.enabled
|
40
41
|
end
|
41
42
|
end
|
43
|
+
|
44
|
+
def rack_cache_hashlike?(app)
|
45
|
+
app.config.action_dispatch.rack_cache && app.config.action_dispatch.rack_cache.respond_to?(:[]=)
|
46
|
+
end
|
42
47
|
end
|
43
48
|
|
44
49
|
def default_source
|
@@ -74,6 +79,8 @@ module LogStasher
|
|
74
79
|
config.backtrace = yml_config[:backtrace] if yml_config.key? :backtrace
|
75
80
|
config.logger_path = yml_config[:logger_path] if yml_config.key? :logger_path
|
76
81
|
config.log_level = yml_config[:log_level] if yml_config.key? :log_level
|
77
|
-
|
82
|
+
if yml_config.key? :log_controller_parameters
|
83
|
+
config.log_controller_parameters = yml_config[:log_controller_parameters]
|
84
|
+
end
|
78
85
|
end
|
79
86
|
end
|
data/lib/logstasher/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstasher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shadab Ahmed
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '5.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '5.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: request_store
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,34 +38,6 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: activesupport
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '4.0'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '4.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rspec
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '2.14'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '2.14'
|
69
41
|
- !ruby/object:Gem::Dependency
|
70
42
|
name: bundler
|
71
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,28 +58,28 @@ dependencies:
|
|
86
58
|
requirements:
|
87
59
|
- - ">="
|
88
60
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
61
|
+
version: '5.2'
|
90
62
|
type: :development
|
91
63
|
prerelease: false
|
92
64
|
version_requirements: !ruby/object:Gem::Requirement
|
93
65
|
requirements:
|
94
66
|
- - ">="
|
95
67
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
68
|
+
version: '5.2'
|
97
69
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
70
|
+
name: rspec
|
99
71
|
requirement: !ruby/object:Gem::Requirement
|
100
72
|
requirements:
|
101
73
|
- - ">="
|
102
74
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
75
|
+
version: '2.14'
|
104
76
|
type: :development
|
105
77
|
prerelease: false
|
106
78
|
version_requirements: !ruby/object:Gem::Requirement
|
107
79
|
requirements:
|
108
80
|
- - ">="
|
109
81
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
82
|
+
version: '2.14'
|
111
83
|
description: Awesome rails logs
|
112
84
|
email:
|
113
85
|
- shadab.ansari@gmail.com
|
@@ -123,6 +95,7 @@ files:
|
|
123
95
|
- lib/logstasher/active_support/mailer_log_subscriber.rb
|
124
96
|
- lib/logstasher/custom_fields.rb
|
125
97
|
- lib/logstasher/device/redis.rb
|
98
|
+
- lib/logstasher/event.rb
|
126
99
|
- lib/logstasher/rails_ext/action_controller/base.rb
|
127
100
|
- lib/logstasher/rails_ext/action_controller/metal/instrumentation.rb
|
128
101
|
- lib/logstasher/rails_ext/rack/logger.rb
|
@@ -132,7 +105,7 @@ homepage: https://github.com/shadabahmed/logstasher
|
|
132
105
|
licenses:
|
133
106
|
- MIT
|
134
107
|
metadata: {}
|
135
|
-
post_install_message:
|
108
|
+
post_install_message:
|
136
109
|
rdoc_options: []
|
137
110
|
require_paths:
|
138
111
|
- lib
|
@@ -147,9 +120,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
120
|
- !ruby/object:Gem::Version
|
148
121
|
version: '0'
|
149
122
|
requirements: []
|
150
|
-
|
151
|
-
|
152
|
-
signing_key:
|
123
|
+
rubygems_version: 3.0.3
|
124
|
+
signing_key:
|
153
125
|
specification_version: 4
|
154
126
|
summary: Awesome rails logs
|
155
127
|
test_files: []
|