logstasher 2.0.2 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
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
@@ -36,7 +36,9 @@ module LogStasher
|
|
36
36
|
unsubscribe(:action_mailer, subscriber)
|
37
37
|
when 'ActiveRecord::LogSubscriber'
|
38
38
|
unsubscribe(:active_record, subscriber)
|
39
|
-
when 'ActiveJob::
|
39
|
+
when 'ActiveJob::LogSubscriber' # For Rails 6
|
40
|
+
unsubscribe(:active_job, subscriber)
|
41
|
+
when 'ActiveJob::Logging::LogSubscriber' # For Rails 5
|
40
42
|
unsubscribe(:active_job, subscriber)
|
41
43
|
end
|
42
44
|
end
|
@@ -1,92 +1,98 @@
|
|
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
|
-
|
8
|
-
module
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
7
|
+
module LogStasher
|
8
|
+
module ActiveJob
|
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
|
17
|
+
def enqueue(event)
|
18
|
+
process_event(event, 'enqueue')
|
19
|
+
end
|
20
|
+
|
21
|
+
def enqueue_at(event)
|
22
|
+
process_event(event, 'enqueue_at')
|
23
|
+
end
|
24
|
+
|
25
|
+
def perform(event)
|
26
|
+
process_event(event, 'perform')
|
27
|
+
|
28
|
+
# Revert the request id back, in the event that the inline adapter is being used or a
|
29
|
+
# perform_now was used.
|
30
|
+
LogStasher.request_context[:request_id] = Thread.current[:old_request_id]
|
31
|
+
Thread.current[:old_request_id] = nil
|
32
|
+
end
|
33
|
+
|
34
|
+
def perform_start(event)
|
35
|
+
# Use the job_id as the request id, so that any custom logging done for a job
|
36
|
+
# shares a request id, and has the job id in each log line.
|
37
|
+
#
|
38
|
+
# It's not being set when the job is enqueued, so enqueuing a job will have it's default
|
39
|
+
# request_id. In a lot of cases, it will be because of a web request.
|
40
|
+
#
|
41
|
+
# Hang onto the old request id, so we can revert after the job is done being performed.
|
42
|
+
Thread.current[:old_request_id] = LogStasher.request_context[:request_id]
|
43
|
+
LogStasher.request_context[:request_id] = event.payload[:job].job_id
|
44
|
+
|
45
|
+
process_event(event, 'perform_start')
|
46
|
+
end
|
47
|
+
|
48
|
+
def logger
|
49
|
+
LogStasher.logger
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def process_event(event, type)
|
55
|
+
data = extract_metadata(event)
|
56
|
+
data.merge! extract_exception(event)
|
57
|
+
data.merge! extract_scheduled_at(event) if type == 'enqueue_at'
|
58
|
+
data.merge! extract_duration(event) if type == 'perform'
|
59
|
+
data.merge! request_context
|
60
|
+
|
61
|
+
tags = ['job', type]
|
62
|
+
tags.push('exception') if data[:exception]
|
63
|
+
logger << LogStasher.build_logstash_event(data, tags).to_json + "\n"
|
64
|
+
end
|
65
|
+
|
66
|
+
def extract_metadata(event)
|
67
|
+
{
|
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])
|
72
|
+
}
|
73
|
+
end
|
74
|
+
|
75
|
+
def extract_duration(event)
|
76
|
+
{ duration: event.duration.to_f.round(2) }
|
77
|
+
end
|
78
|
+
|
79
|
+
def extract_exception(event)
|
80
|
+
event.payload.slice(:exception)
|
81
|
+
end
|
82
|
+
|
83
|
+
def extract_scheduled_at(event)
|
84
|
+
{ scheduled_at: scheduled_at(event) }
|
85
|
+
end
|
86
|
+
|
87
|
+
def request_context
|
88
|
+
LogStasher.request_context
|
89
|
+
end
|
90
|
+
|
91
|
+
# The default args_info makes a string. We need objects to turn into JSON.
|
92
|
+
def args_info(job)
|
93
|
+
job.arguments.map { |arg| arg.try(:to_global_id).try(:to_s) || arg }
|
89
94
|
end
|
90
95
|
end
|
91
96
|
end
|
92
97
|
end
|
98
|
+
|
@@ -10,6 +10,11 @@ module LogStasher
|
|
10
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
19
|
process_event(event, %w[mailer receive])
|
15
20
|
end
|
data/lib/logstasher/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstasher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shadab Ahmed
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '5.
|
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: '5.
|
26
|
+
version: '5.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: request_store
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: activerecord
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '5.0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '5.0'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: bundler
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,14 +58,14 @@ dependencies:
|
|
72
58
|
requirements:
|
73
59
|
- - ">="
|
74
60
|
- !ruby/object:Gem::Version
|
75
|
-
version: '5.
|
61
|
+
version: '5.2'
|
76
62
|
type: :development
|
77
63
|
prerelease: false
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
66
|
- - ">="
|
81
67
|
- !ruby/object:Gem::Version
|
82
|
-
version: '5.
|
68
|
+
version: '5.2'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
name: rspec
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|