scout_apm 2.4.17 → 2.4.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.markdown +5 -0
- data/lib/scout_apm.rb +2 -0
- data/lib/scout_apm/background_job_integrations/shoryuken.rb +124 -0
- data/lib/scout_apm/background_job_integrations/sneakers.rb +87 -0
- data/lib/scout_apm/environment.rb +2 -0
- data/lib/scout_apm/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad3c97e9c1dd1cad2376178ad19f534cf41e53d7
|
4
|
+
data.tar.gz: 8af7268cc654088d6bd1440c693e990e4d3d2c45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 620703274624cc21f1e4712b425a68abfde46fe80172e8e457f8b57ec95d6c53980dc9d1ad71b69defb610d43f6be4ad60652d30e08f15d9c1cd7761c60e4e93
|
7
|
+
data.tar.gz: 11aeff7c54b15e754c2ed425233a552a2065559b3f9d6c0402e7207e54db4cdfbe47aad9d32f8465c5cf378d5e45f543a2376591a22844b26869d607218694b9
|
data/CHANGELOG.markdown
CHANGED
data/lib/scout_apm.rb
CHANGED
@@ -58,6 +58,8 @@ require 'scout_apm/server_integrations/null'
|
|
58
58
|
require 'scout_apm/background_job_integrations/sidekiq'
|
59
59
|
require 'scout_apm/background_job_integrations/delayed_job'
|
60
60
|
require 'scout_apm/background_job_integrations/resque'
|
61
|
+
require 'scout_apm/background_job_integrations/shoryuken'
|
62
|
+
require 'scout_apm/background_job_integrations/sneakers'
|
61
63
|
|
62
64
|
require 'scout_apm/framework_integrations/rails_2'
|
63
65
|
require 'scout_apm/framework_integrations/rails_3_or_4'
|
@@ -0,0 +1,124 @@
|
|
1
|
+
module ScoutApm
|
2
|
+
module BackgroundJobIntegrations
|
3
|
+
class Shoryuken
|
4
|
+
attr_reader :logger
|
5
|
+
|
6
|
+
def name
|
7
|
+
:shoryuken
|
8
|
+
end
|
9
|
+
|
10
|
+
def present?
|
11
|
+
defined?(::Shoryuken) && File.basename($PROGRAM_NAME).start_with?('shoryuken')
|
12
|
+
end
|
13
|
+
|
14
|
+
def forking?
|
15
|
+
false
|
16
|
+
end
|
17
|
+
|
18
|
+
def install
|
19
|
+
install_tracer
|
20
|
+
add_middleware
|
21
|
+
install_processor
|
22
|
+
end
|
23
|
+
|
24
|
+
def install_tracer
|
25
|
+
# ScoutApm::Tracer is not available when this class is defined
|
26
|
+
ShoryukenMiddleware.class_eval do
|
27
|
+
include ScoutApm::Tracer
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def add_middleware
|
32
|
+
::Shoryuken.configure_server do |config|
|
33
|
+
config.server_middleware do |chain|
|
34
|
+
chain.add ShoryukenMiddleware
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def install_processor
|
40
|
+
require 'shoryuken/processor' # sidekiq v4 has not loaded this file by this point
|
41
|
+
|
42
|
+
::Shoryuken::Processor.class_eval do
|
43
|
+
def initialize_with_scout(*args)
|
44
|
+
agent = ::ScoutApm::Agent.instance
|
45
|
+
agent.start
|
46
|
+
initialize_without_scout(*args)
|
47
|
+
end
|
48
|
+
|
49
|
+
alias_method :initialize_without_scout, :initialize
|
50
|
+
alias_method :initialize, :initialize_with_scout
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# We insert this middleware into the Shoryuken stack, to capture each job,
|
56
|
+
# and time them.
|
57
|
+
class ShoryukenMiddleware
|
58
|
+
def call(worker_instance, queue, msg, body)
|
59
|
+
job_class =
|
60
|
+
begin
|
61
|
+
if worker_instance.class.to_s == ACTIVE_JOB_KLASS
|
62
|
+
body["job_class"]
|
63
|
+
else
|
64
|
+
worker_instance.class.to_s
|
65
|
+
end
|
66
|
+
rescue
|
67
|
+
UNKNOWN_CLASS_PLACEHOLDER
|
68
|
+
end
|
69
|
+
|
70
|
+
req = ScoutApm::RequestManager.lookup
|
71
|
+
req.annotate_request(:queue_latency => latency(msg))
|
72
|
+
|
73
|
+
begin
|
74
|
+
req.start_layer(ScoutApm::Layer.new('Queue', queue))
|
75
|
+
started_queue = true
|
76
|
+
req.start_layer(ScoutApm::Layer.new('Job', job_class))
|
77
|
+
started_job = true
|
78
|
+
|
79
|
+
yield
|
80
|
+
rescue Exception => e
|
81
|
+
req.error!
|
82
|
+
raise
|
83
|
+
ensure
|
84
|
+
req.stop_layer if started_job
|
85
|
+
req.stop_layer if started_queue
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
UNKNOWN_CLASS_PLACEHOLDER = 'UnknownJob'.freeze
|
90
|
+
ACTIVE_JOB_KLASS = 'ActiveJob::QueueAdapters::ShoryukenAdapter::JobWrapper'.freeze
|
91
|
+
|
92
|
+
def latency(msg, time = Time.now.to_f)
|
93
|
+
ms_since_epoch_str = msg.attributes.fetch('SentTimestamp', 0)
|
94
|
+
return 0 if ms_since_epoch_str.nil?
|
95
|
+
|
96
|
+
# Convert from ms to seconds as a float
|
97
|
+
created_at = ms_since_epoch_str.to_i / 1000.0
|
98
|
+
|
99
|
+
time - created_at
|
100
|
+
rescue => e
|
101
|
+
0
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# MSG: #<Shoryuken::Message:0x007fb742a96950 @client=#<Aws::SQS::Client>
|
108
|
+
# @data=#<struct Aws::SQS::Types::Message message_id="7a2ef0af-2bbd-4368-9c39-34cc89e4da15"
|
109
|
+
# receipt_handle="AQEB8YK4+TCyvCM3p0EanmhZiTbBCM6uMeyCn7zibNn+XZcMnjZp2Z8D8yoUs4mMX9vJqlQvaS8gRUGBYG7ciq+BthmEqDWfxbcJ8jN+Vp/PXIyyTgYL3vvlnHcQajDz3H7Bd30UmLu80sqeLSjXXNEiKolcIxdGuIsIdSM4aUEPXsecr5eH7o8pZHcDV+bGcLuE7VbvKRZT3A2HeezW7wWwkYve/wt6asS1bYB+VJurAORY0y26xgCooEMNbs5yqxcnSD/CiNT822hkmw0eHNpTHOjF9WLgxLbkpITnQl1lsfK5TsM/ukE1oB1F9nN5ZkCBVCDeFYJDBAo81VvVV9G16knxyCYzjnmpwhvHg2BqTA56iV6r9KZYbiwOaMPdH5ealKLRnWhFoLOEPNA4yjG1yw=="
|
110
|
+
# md5_of_body="8b3be018857a74f9e46b4c6ef3c3f515"
|
111
|
+
# body="Unique Person #7532"
|
112
|
+
# attributes={"SenderId"=>"AIDAJZXBVF26MLZPE6FOO"
|
113
|
+
# "ApproximateFirstReceiveTimestamp"=>"1534873932213"
|
114
|
+
# "ApproximateReceiveCount"=>"1"
|
115
|
+
# "SentTimestamp"=>"1534873927868"}
|
116
|
+
# md5_of_message_attributes="c70f52a6566cf42ec5e61e81877132dd"
|
117
|
+
# message_attributes={"shoryuken_class"=>#<struct Aws::SQS::Types::MessageAttributeValue string_value="DummyWorker"
|
118
|
+
# binary_value=nil
|
119
|
+
# string_list_values=[]
|
120
|
+
# binary_list_values=[]
|
121
|
+
# data_type="String">}>
|
122
|
+
# @queue_url="https://sqs.us-west-2.amazonaws.com/023109228371/shoryuken_test"
|
123
|
+
# @queue_name="shoryuken_test">
|
124
|
+
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module ScoutApm
|
2
|
+
module BackgroundJobIntegrations
|
3
|
+
class Sneakers
|
4
|
+
attr_reader :logger
|
5
|
+
|
6
|
+
def name
|
7
|
+
:sneakers
|
8
|
+
end
|
9
|
+
|
10
|
+
def present?
|
11
|
+
defined?(::Sneakers)
|
12
|
+
end
|
13
|
+
|
14
|
+
def forking?
|
15
|
+
false
|
16
|
+
end
|
17
|
+
|
18
|
+
def install
|
19
|
+
install_worker_override
|
20
|
+
end
|
21
|
+
|
22
|
+
def install_worker_override
|
23
|
+
::Sneakers::Worker.module_eval do
|
24
|
+
def initialize_with_scout(*args)
|
25
|
+
agent = ::ScoutApm::Agent.instance
|
26
|
+
agent.start
|
27
|
+
initialize_without_scout(*args)
|
28
|
+
end
|
29
|
+
|
30
|
+
alias_method :initialize_without_scout, :initialize
|
31
|
+
alias_method :initialize, :initialize_with_scout
|
32
|
+
|
33
|
+
def process_work_with_scout(*args)
|
34
|
+
delivery_info, _metadata, msg, _handler = args
|
35
|
+
|
36
|
+
queue = delivery_info[:routing_key] || UNKNOWN_QUEUE_PLACEHOLDER
|
37
|
+
|
38
|
+
job_class = begin
|
39
|
+
if self.class == ActiveJob::QueueAdapters::SneakersAdapter::JobWrapper
|
40
|
+
msg["job_class"] || UNKNOWN_CLASS_PLACEHOLDER
|
41
|
+
else
|
42
|
+
self.class.name
|
43
|
+
end
|
44
|
+
rescue => e
|
45
|
+
UNKNOWN_CLASS_PLACEHOLDER
|
46
|
+
end
|
47
|
+
|
48
|
+
req = ScoutApm::RequestManager.lookup
|
49
|
+
|
50
|
+
# RabbitMQ does not store a created-at timestamp
|
51
|
+
# req.annotate_request(:queue_latency => latency(msg))
|
52
|
+
|
53
|
+
begin
|
54
|
+
req.start_layer(ScoutApm::Layer.new('Queue', queue))
|
55
|
+
started_queue = true
|
56
|
+
req.start_layer(ScoutApm::Layer.new('Job', job_class))
|
57
|
+
started_job = true
|
58
|
+
|
59
|
+
process_work_without_scout(*args)
|
60
|
+
rescue Exception => e
|
61
|
+
req.error!
|
62
|
+
raise
|
63
|
+
ensure
|
64
|
+
req.stop_layer if started_job
|
65
|
+
req.stop_layer if started_queue
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
alias_method :process_work_without_scout, :process_work
|
70
|
+
alias_method :process_work, :process_work_with_scout
|
71
|
+
end
|
72
|
+
|
73
|
+
# msg = {
|
74
|
+
# "job_class":"DummyWorker",
|
75
|
+
# "job_id":"ea23ba1c-3022-4e05-870b-c3bcb1c4f328",
|
76
|
+
# "queue_name":"default",
|
77
|
+
# "arguments":["fjdkl"],
|
78
|
+
# "locale":"en"
|
79
|
+
# }
|
80
|
+
end
|
81
|
+
|
82
|
+
ACTIVE_JOB_KLASS = 'ActiveJob::QueueAdapters::SneakersAdapter::JobWrapper'.freeze
|
83
|
+
UNKNOWN_CLASS_PLACEHOLDER = 'UnknownJob'.freeze
|
84
|
+
UNKNOWN_QUEUE_PLACEHOLDER = 'default'.freeze
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -26,6 +26,8 @@ module ScoutApm
|
|
26
26
|
BACKGROUND_JOB_INTEGRATIONS = [
|
27
27
|
ScoutApm::BackgroundJobIntegrations::Resque.new,
|
28
28
|
ScoutApm::BackgroundJobIntegrations::Sidekiq.new,
|
29
|
+
ScoutApm::BackgroundJobIntegrations::Shoryuken.new,
|
30
|
+
ScoutApm::BackgroundJobIntegrations::Sneakers.new,
|
29
31
|
ScoutApm::BackgroundJobIntegrations::DelayedJob.new,
|
30
32
|
]
|
31
33
|
|
data/lib/scout_apm/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scout_apm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.
|
4
|
+
version: 2.4.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derek Haynes
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-09-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|
@@ -198,7 +198,9 @@ files:
|
|
198
198
|
- lib/scout_apm/attribute_arranger.rb
|
199
199
|
- lib/scout_apm/background_job_integrations/delayed_job.rb
|
200
200
|
- lib/scout_apm/background_job_integrations/resque.rb
|
201
|
+
- lib/scout_apm/background_job_integrations/shoryuken.rb
|
201
202
|
- lib/scout_apm/background_job_integrations/sidekiq.rb
|
203
|
+
- lib/scout_apm/background_job_integrations/sneakers.rb
|
202
204
|
- lib/scout_apm/background_recorder.rb
|
203
205
|
- lib/scout_apm/background_worker.rb
|
204
206
|
- lib/scout_apm/bucket_name_splitter.rb
|
@@ -390,7 +392,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
390
392
|
version: '0'
|
391
393
|
requirements: []
|
392
394
|
rubyforge_project: scout_apm
|
393
|
-
rubygems_version: 2.4.
|
395
|
+
rubygems_version: 2.4.5.2
|
394
396
|
signing_key:
|
395
397
|
specification_version: 4
|
396
398
|
summary: Ruby application performance monitoring
|