scout_apm 2.6.10 → 3.0.0.pre0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -2
- data/.rubocop.yml +3 -11
- data/CHANGELOG.markdown +4 -362
- data/Gemfile +1 -14
- data/README.markdown +7 -52
- data/Rakefile +1 -0
- data/ext/allocations/allocations.c +1 -7
- data/ext/allocations/extconf.rb +0 -1
- data/ext/rusage/rusage.c +0 -26
- data/ext/stacks/extconf.rb +37 -0
- data/ext/stacks/scout_atomics.h +86 -0
- data/ext/stacks/stacks.c +811 -0
- data/lib/scout_apm/agent/logging.rb +69 -0
- data/lib/scout_apm/agent/reporting.rb +126 -0
- data/lib/scout_apm/agent.rb +259 -138
- data/lib/scout_apm/app_server_load.rb +15 -41
- data/lib/scout_apm/attribute_arranger.rb +3 -14
- data/lib/scout_apm/background_job_integrations/delayed_job.rb +1 -70
- data/lib/scout_apm/background_job_integrations/sidekiq.rb +24 -31
- data/lib/scout_apm/background_worker.rb +12 -23
- data/lib/scout_apm/capacity.rb +57 -0
- data/lib/scout_apm/config.rb +37 -206
- data/lib/scout_apm/context.rb +4 -20
- data/lib/scout_apm/deploy_integrations/capistrano_2.cap +12 -0
- data/lib/scout_apm/deploy_integrations/capistrano_2.rb +83 -0
- data/lib/scout_apm/deploy_integrations/capistrano_3.cap +12 -0
- data/lib/scout_apm/deploy_integrations/capistrano_3.rb +88 -0
- data/lib/scout_apm/environment.rb +28 -42
- data/lib/scout_apm/fake_store.rb +0 -12
- data/lib/scout_apm/framework_integrations/rails_2.rb +1 -2
- data/lib/scout_apm/framework_integrations/rails_3_or_4.rb +6 -17
- data/lib/scout_apm/framework_integrations/sinatra.rb +1 -1
- data/lib/scout_apm/histogram.rb +3 -12
- data/lib/scout_apm/instant/assets/xmlhttp_instrumentation.html +2 -2
- data/lib/scout_apm/instant/middleware.rb +54 -202
- data/lib/scout_apm/instant_reporting.rb +7 -7
- data/lib/scout_apm/instruments/.DS_Store +0 -0
- data/lib/scout_apm/instruments/action_controller_rails_2.rb +9 -15
- data/lib/scout_apm/instruments/action_controller_rails_3_rails4.rb +76 -124
- data/lib/scout_apm/instruments/active_record.rb +29 -324
- data/lib/scout_apm/instruments/delayed_job.rb +57 -0
- data/lib/scout_apm/instruments/elasticsearch.rb +6 -10
- data/lib/scout_apm/instruments/grape.rb +9 -12
- data/lib/scout_apm/instruments/http_client.rb +7 -14
- data/lib/scout_apm/instruments/influxdb.rb +6 -10
- data/lib/scout_apm/instruments/middleware_detailed.rb +11 -15
- data/lib/scout_apm/instruments/middleware_summary.rb +5 -11
- data/lib/scout_apm/instruments/mongoid.rb +8 -39
- data/lib/scout_apm/instruments/moped.rb +6 -11
- data/lib/scout_apm/instruments/net_http.rb +9 -27
- data/lib/scout_apm/instruments/percentile_sampler.rb +23 -42
- data/lib/scout_apm/instruments/process/process_cpu.rb +6 -11
- data/lib/scout_apm/instruments/process/process_memory.rb +12 -17
- data/lib/scout_apm/instruments/rails_router.rb +6 -12
- data/lib/scout_apm/instruments/redis.rb +6 -10
- data/lib/scout_apm/instruments/sinatra.rb +4 -5
- data/lib/scout_apm/job_record.rb +2 -4
- data/lib/scout_apm/layaway.rb +34 -88
- data/lib/scout_apm/layaway_file.rb +3 -13
- data/lib/scout_apm/layer.rb +60 -25
- data/lib/scout_apm/layer_converters/allocation_metric_converter.rb +6 -7
- data/lib/scout_apm/layer_converters/converter_base.rb +14 -203
- data/lib/scout_apm/layer_converters/depth_first_walker.rb +10 -22
- data/lib/scout_apm/layer_converters/error_converter.rb +8 -8
- data/lib/scout_apm/layer_converters/job_converter.rb +50 -37
- data/lib/scout_apm/layer_converters/metric_converter.rb +19 -18
- data/lib/scout_apm/layer_converters/request_queue_time_converter.rb +13 -13
- data/lib/scout_apm/layer_converters/slow_job_converter.rb +116 -52
- data/lib/scout_apm/layer_converters/slow_request_converter.rb +120 -51
- data/lib/scout_apm/metric_meta.rb +5 -0
- data/lib/scout_apm/metric_set.rb +1 -9
- data/lib/scout_apm/metric_stats.rb +8 -7
- data/lib/scout_apm/middleware.rb +9 -7
- data/lib/scout_apm/reporter.rb +24 -71
- data/lib/scout_apm/request_histograms.rb +0 -12
- data/lib/scout_apm/request_manager.rb +7 -5
- data/lib/scout_apm/scored_item_set.rb +0 -7
- data/lib/scout_apm/serializers/app_server_load_serializer.rb +0 -4
- data/lib/scout_apm/serializers/deploy_serializer.rb +16 -0
- data/lib/scout_apm/serializers/directive_serializer.rb +0 -4
- data/lib/scout_apm/serializers/payload_serializer.rb +4 -11
- data/lib/scout_apm/serializers/payload_serializer_to_json.rb +16 -35
- data/lib/scout_apm/serializers/slow_jobs_serializer_to_json.rb +1 -2
- data/lib/scout_apm/server_integrations/passenger.rb +1 -1
- data/lib/scout_apm/server_integrations/puma.rb +2 -5
- data/lib/scout_apm/slow_job_policy.rb +13 -25
- data/lib/scout_apm/slow_job_record.rb +4 -13
- data/lib/scout_apm/slow_request_policy.rb +13 -25
- data/lib/scout_apm/slow_transaction.rb +5 -25
- data/lib/scout_apm/store.rb +32 -99
- data/lib/scout_apm/trace_compactor.rb +312 -0
- data/lib/scout_apm/tracer.rb +31 -35
- data/lib/scout_apm/tracked_request.rb +95 -262
- data/lib/scout_apm/utils/active_record_metric_name.rb +13 -88
- data/lib/scout_apm/utils/backtrace_parser.rb +4 -7
- data/lib/scout_apm/utils/fake_stacks.rb +87 -0
- data/lib/scout_apm/utils/installed_gems.rb +3 -7
- data/lib/scout_apm/utils/klass_helper.rb +2 -8
- data/lib/scout_apm/utils/null_logger.rb +13 -0
- data/lib/scout_apm/utils/sql_sanitizer.rb +5 -16
- data/lib/scout_apm/utils/sql_sanitizer_regex.rb +0 -7
- data/lib/scout_apm/utils/sql_sanitizer_regex_1_8_7.rb +0 -6
- data/lib/scout_apm/utils/unique_id.rb +0 -27
- data/lib/scout_apm/version.rb +2 -1
- data/lib/scout_apm.rb +25 -84
- data/scout_apm.gemspec +3 -17
- data/test/test_helper.rb +3 -57
- data/test/unit/agent_test.rb +54 -1
- data/test/unit/background_job_integrations/sidekiq_test.rb +3 -0
- data/test/unit/config_test.rb +12 -25
- data/test/unit/context_test.rb +4 -4
- data/test/unit/histogram_test.rb +4 -25
- data/test/unit/ignored_uris_test.rb +1 -1
- data/test/unit/instruments/active_record_instruments_test.rb +5 -0
- data/test/unit/layaway_test.rb +2 -62
- data/test/unit/serializers/payload_serializer_test.rb +15 -43
- data/test/unit/slow_request_policy_test.rb +6 -15
- data/test/unit/sql_sanitizer_test.rb +6 -53
- data/test/unit/store_test.rb +4 -73
- data/test/unit/utils/active_record_metric_name_test.rb +5 -59
- data/test/unit/utils/backtrace_parser_test.rb +1 -6
- data/tester.rb +53 -0
- metadata +28 -229
- data/.travis.yml +0 -26
- data/Guardfile +0 -43
- data/gems/README.md +0 -28
- data/gems/octoshark.gemfile +0 -4
- data/gems/rails3.gemfile +0 -5
- data/gems/rails4.gemfile +0 -4
- data/gems/rails5.gemfile +0 -4
- data/gems/rails6.gemfile +0 -4
- data/lib/scout_apm/agent/exit_handler.rb +0 -65
- data/lib/scout_apm/agent/preconditions.rb +0 -81
- data/lib/scout_apm/agent_context.rb +0 -261
- data/lib/scout_apm/auto_instrument/instruction_sequence.rb +0 -31
- data/lib/scout_apm/auto_instrument/layer.rb +0 -23
- data/lib/scout_apm/auto_instrument/parser.rb +0 -27
- data/lib/scout_apm/auto_instrument/rails.rb +0 -175
- data/lib/scout_apm/auto_instrument.rb +0 -5
- data/lib/scout_apm/background_job_integrations/legacy_sneakers.rb +0 -55
- data/lib/scout_apm/background_job_integrations/que.rb +0 -134
- data/lib/scout_apm/background_job_integrations/resque.rb +0 -88
- data/lib/scout_apm/background_job_integrations/shoryuken.rb +0 -124
- data/lib/scout_apm/background_job_integrations/sneakers.rb +0 -87
- data/lib/scout_apm/background_recorder.rb +0 -48
- data/lib/scout_apm/db_query_metric_set.rb +0 -97
- data/lib/scout_apm/db_query_metric_stats.rb +0 -102
- data/lib/scout_apm/debug.rb +0 -37
- data/lib/scout_apm/detailed_trace.rb +0 -217
- data/lib/scout_apm/error.rb +0 -27
- data/lib/scout_apm/error_service/error_buffer.rb +0 -39
- data/lib/scout_apm/error_service/error_record.rb +0 -211
- data/lib/scout_apm/error_service/ignored_exceptions.rb +0 -66
- data/lib/scout_apm/error_service/middleware.rb +0 -32
- data/lib/scout_apm/error_service/notifier.rb +0 -33
- data/lib/scout_apm/error_service/payload.rb +0 -47
- data/lib/scout_apm/error_service/periodic_work.rb +0 -17
- data/lib/scout_apm/error_service/railtie.rb +0 -11
- data/lib/scout_apm/error_service/sidekiq.rb +0 -80
- data/lib/scout_apm/error_service.rb +0 -32
- data/lib/scout_apm/extensions/config.rb +0 -87
- data/lib/scout_apm/extensions/transaction_callback_payload.rb +0 -74
- data/lib/scout_apm/git_revision.rb +0 -59
- data/lib/scout_apm/instrument_manager.rb +0 -88
- data/lib/scout_apm/instruments/action_view.rb +0 -141
- data/lib/scout_apm/instruments/http.rb +0 -48
- data/lib/scout_apm/instruments/memcached.rb +0 -43
- data/lib/scout_apm/instruments/resque.rb +0 -39
- data/lib/scout_apm/instruments/samplers.rb +0 -11
- data/lib/scout_apm/layer_children_set.rb +0 -86
- data/lib/scout_apm/layer_converters/database_converter.rb +0 -70
- data/lib/scout_apm/layer_converters/find_layer_by_type.rb +0 -38
- data/lib/scout_apm/layer_converters/histograms.rb +0 -15
- data/lib/scout_apm/layer_converters/trace_converter.rb +0 -184
- data/lib/scout_apm/limited_layer.rb +0 -126
- data/lib/scout_apm/logger.rb +0 -158
- data/lib/scout_apm/periodic_work.rb +0 -47
- data/lib/scout_apm/rack.rb +0 -26
- data/lib/scout_apm/remote/message.rb +0 -27
- data/lib/scout_apm/remote/recorder.rb +0 -57
- data/lib/scout_apm/remote/router.rb +0 -49
- data/lib/scout_apm/remote/server.rb +0 -60
- data/lib/scout_apm/reporting.rb +0 -143
- data/lib/scout_apm/serializers/db_query_serializer_to_json.rb +0 -15
- data/lib/scout_apm/serializers/histograms_serializer_to_json.rb +0 -21
- data/lib/scout_apm/synchronous_recorder.rb +0 -30
- data/lib/scout_apm/tasks/doctor.rb +0 -75
- data/lib/scout_apm/tasks/support.rb +0 -22
- data/lib/scout_apm/transaction.rb +0 -13
- data/lib/scout_apm/transaction_time_consumed.rb +0 -51
- data/lib/scout_apm/utils/gzip_helper.rb +0 -24
- data/lib/scout_apm/utils/marshal_logging.rb +0 -90
- data/lib/scout_apm/utils/numbers.rb +0 -14
- data/lib/scout_apm/utils/scm.rb +0 -14
- data/lib/tasks/doctor.rake +0 -11
- data/test/tmp/README.md +0 -17
- data/test/unit/agent_context_test.rb +0 -15
- data/test/unit/auto_instrument/assignments-instrumented.rb +0 -31
- data/test/unit/auto_instrument/assignments.rb +0 -31
- data/test/unit/auto_instrument/controller-ast.txt +0 -57
- data/test/unit/auto_instrument/controller-instrumented.rb +0 -49
- data/test/unit/auto_instrument/controller.rb +0 -49
- data/test/unit/auto_instrument/rescue_from-instrumented.rb +0 -13
- data/test/unit/auto_instrument/rescue_from.rb +0 -13
- data/test/unit/auto_instrument_test.rb +0 -54
- data/test/unit/db_query_metric_set_test.rb +0 -67
- data/test/unit/db_query_metric_stats_test.rb +0 -113
- data/test/unit/error_service/error_buffer_test.rb +0 -25
- data/test/unit/error_service/ignored_exceptions_test.rb +0 -49
- data/test/unit/extensions/periodic_callbacks_test.rb +0 -58
- data/test/unit/extensions/transaction_callbacks_test.rb +0 -58
- data/test/unit/fake_store_test.rb +0 -10
- data/test/unit/git_revision_test.rb +0 -15
- data/test/unit/instruments/active_record_test.rb +0 -40
- data/test/unit/instruments/net_http_test.rb +0 -27
- data/test/unit/instruments/percentile_sampler_test.rb +0 -133
- data/test/unit/layer_children_set_test.rb +0 -97
- data/test/unit/layer_converters/depth_first_walker_test.rb +0 -70
- data/test/unit/layer_converters/metric_converter_test.rb +0 -22
- data/test/unit/layer_converters/stubs.rb +0 -33
- data/test/unit/limited_layer_test.rb +0 -53
- data/test/unit/logger_test.rb +0 -69
- data/test/unit/remote/test_message.rb +0 -13
- data/test/unit/remote/test_router.rb +0 -33
- data/test/unit/remote/test_server.rb +0 -15
- data/test/unit/request_histograms_test.rb +0 -17
- data/test/unit/tracer_test.rb +0 -76
- data/test/unit/tracked_request_test.rb +0 -71
- data/test/unit/transaction_test.rb +0 -14
- data/test/unit/transaction_time_consumed_test.rb +0 -46
- data/test/unit/utils/numbers_test.rb +0 -15
- data/test/unit/utils/scm.rb +0 -17
@@ -1,175 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'scout_apm/auto_instrument/layer'
|
3
|
-
require 'scout_apm/auto_instrument/parser'
|
4
|
-
|
5
|
-
module ScoutApm
|
6
|
-
module AutoInstrument
|
7
|
-
module Rails
|
8
|
-
# A general pattern to match Rails controller files:
|
9
|
-
CONTROLLER_FILE = /\/app\/controllers\/*\/.*_controller.rb$/.freeze
|
10
|
-
|
11
|
-
# Some gems (Devise) provide controllers that match CONTROLLER_FILE pattern.
|
12
|
-
# Try a simple match to see if it's a Gemfile
|
13
|
-
GEM_FILE = /\/gems?\//.freeze
|
14
|
-
|
15
|
-
# Whether the given path is likely to be a Rails controller and not provided by a Gem.
|
16
|
-
def self.controller_path? path
|
17
|
-
CONTROLLER_FILE.match(path) && !GEM_FILE.match(path)
|
18
|
-
end
|
19
|
-
|
20
|
-
# Autoinstruments increases overhead when applied to many code expressions that perform little work.
|
21
|
-
# You can exclude files from autoinstruments via the `auto_instruments_ignore` option.
|
22
|
-
def self.ignore?(path)
|
23
|
-
res = false
|
24
|
-
ScoutApm::Agent.instance.context.config.value('auto_instruments_ignore').each do |ignored_file_name|
|
25
|
-
if path.include?(ignored_file_name)
|
26
|
-
res = true
|
27
|
-
break
|
28
|
-
end
|
29
|
-
end
|
30
|
-
res
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.rewrite(path, code = nil)
|
34
|
-
code ||= File.read(path)
|
35
|
-
|
36
|
-
ast = ::Parser::CurrentRuby.parse(code)
|
37
|
-
|
38
|
-
# pp ast
|
39
|
-
|
40
|
-
buffer = ::Parser::Source::Buffer.new(path)
|
41
|
-
buffer.source = code
|
42
|
-
|
43
|
-
rewriter = Rewriter.new
|
44
|
-
|
45
|
-
# Rewrite the AST, returns a String with the new form.
|
46
|
-
rewriter.rewrite(buffer, ast)
|
47
|
-
end
|
48
|
-
|
49
|
-
class Rewriter < ::Parser::TreeRewriter
|
50
|
-
def initialize
|
51
|
-
super
|
52
|
-
|
53
|
-
# Keeps track of the parent - child relationship between nodes:
|
54
|
-
@nesting = []
|
55
|
-
|
56
|
-
# The stack of method nodes (type :def):
|
57
|
-
@method = []
|
58
|
-
|
59
|
-
# The stack of class nodes:
|
60
|
-
@scope = []
|
61
|
-
|
62
|
-
@cache = Cache.new
|
63
|
-
end
|
64
|
-
|
65
|
-
def instrument(source, file_name, line)
|
66
|
-
# Don't log huge chunks of code... just the first line:
|
67
|
-
if lines = source.lines and lines.count > 1
|
68
|
-
source = lines.first.chomp + "..."
|
69
|
-
end
|
70
|
-
|
71
|
-
method_name = @method.last.children[0]
|
72
|
-
class_name = @scope.last.children[1]
|
73
|
-
bt = ["#{file_name}:#{line}:in `#{method_name}'"]
|
74
|
-
|
75
|
-
return [
|
76
|
-
"::ScoutApm::AutoInstrument("+ source.dump + ",#{bt}){",
|
77
|
-
"}"
|
78
|
-
]
|
79
|
-
end
|
80
|
-
|
81
|
-
# Look up 1 or more nodes to check if the parent exists and matches the given type.
|
82
|
-
# @param type [Symbol] the symbol type to match.
|
83
|
-
# @param up [Integer] how far up to look.
|
84
|
-
def parent_type?(type, up = 1)
|
85
|
-
parent = @nesting[@nesting.size - up - 1] and parent.type == type
|
86
|
-
end
|
87
|
-
|
88
|
-
def on_block(node)
|
89
|
-
# If we are not in a method, don't do any instrumentation:
|
90
|
-
return if @method.empty?
|
91
|
-
|
92
|
-
line = node.location.line || 'line?'
|
93
|
-
column = node.location.column || 'column?' # not used
|
94
|
-
method_name = node.children[0].children[1] || '*unknown*' # not used
|
95
|
-
file_name = @source_rewriter.source_buffer.name
|
96
|
-
|
97
|
-
wrap(node.location.expression, *instrument(node.location.expression.source, file_name, line))
|
98
|
-
end
|
99
|
-
|
100
|
-
def on_mlhs(node)
|
101
|
-
# Ignore / don't instrument multiple assignment (LHS).
|
102
|
-
return
|
103
|
-
end
|
104
|
-
|
105
|
-
def on_op_asgn(node)
|
106
|
-
process(node.children[2])
|
107
|
-
end
|
108
|
-
|
109
|
-
def on_or_asgn(node)
|
110
|
-
process(node.children[1])
|
111
|
-
end
|
112
|
-
|
113
|
-
def on_and_asgn(node)
|
114
|
-
process(node.children[1])
|
115
|
-
end
|
116
|
-
|
117
|
-
# Handle the method call AST node. If this method doesn't call `super`, no futher rewriting is applied to children.
|
118
|
-
def on_send(node)
|
119
|
-
# We aren't interested in top level function calls:
|
120
|
-
return if @method.empty?
|
121
|
-
|
122
|
-
if @cache.local_assignments?(node)
|
123
|
-
return super
|
124
|
-
end
|
125
|
-
|
126
|
-
# This ignores both initial block method invocation `*x*{}`, and subsequent nested invocations `x{*y*}`:
|
127
|
-
return if parent_type?(:block)
|
128
|
-
|
129
|
-
# Extract useful metadata for instrumentation:
|
130
|
-
line = node.location.line || 'line?'
|
131
|
-
column = node.location.column || 'column?' # not used
|
132
|
-
method_name = node.children[1] || '*unknown*' # not used
|
133
|
-
file_name = @source_rewriter.source_buffer.name
|
134
|
-
|
135
|
-
# Wrap the expression with instrumentation:
|
136
|
-
wrap(node.location.expression, *instrument(node.location.expression.source, file_name, line))
|
137
|
-
end
|
138
|
-
|
139
|
-
# def on_class(node)
|
140
|
-
# class_name = node.children[1]
|
141
|
-
#
|
142
|
-
# Kernel.const_get(class_name).ancestors.include? ActionController::Controller
|
143
|
-
#
|
144
|
-
# if class_name =~ /.../
|
145
|
-
# super # continue processing
|
146
|
-
# end
|
147
|
-
# end
|
148
|
-
|
149
|
-
# Invoked for every AST node as it is processed top to bottom.
|
150
|
-
def process(node)
|
151
|
-
# We are nesting inside this node:
|
152
|
-
@nesting.push(node)
|
153
|
-
|
154
|
-
if node and node.type == :def
|
155
|
-
# If the node is a method, push it on the method stack as well:
|
156
|
-
@method.push(node)
|
157
|
-
super
|
158
|
-
@method.pop
|
159
|
-
elsif node and node.type == :class
|
160
|
-
@scope.push(node.children[0])
|
161
|
-
super
|
162
|
-
@scope.pop
|
163
|
-
else
|
164
|
-
super
|
165
|
-
end
|
166
|
-
|
167
|
-
@nesting.pop
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
# Force any lazy loading to occur here, before we patch iseq_load. Otherwise you might end up in an infinite loop when rewriting code.
|
175
|
-
ScoutApm::AutoInstrument::Rails.rewrite('(preload)', '')
|
@@ -1,55 +0,0 @@
|
|
1
|
-
# This is different than other BackgroundJobIntegrations and must be prepended
|
2
|
-
# manually in each job.
|
3
|
-
#
|
4
|
-
# class MyWorker
|
5
|
-
# prepend ScoutApm::BackgroundJobIntegrations::LegacySneakers
|
6
|
-
#
|
7
|
-
# def work(msg)
|
8
|
-
# ...
|
9
|
-
# end
|
10
|
-
# end
|
11
|
-
module ScoutApm
|
12
|
-
module BackgroundJobIntegrations
|
13
|
-
module LegacySneakers
|
14
|
-
UNKNOWN_QUEUE_PLACEHOLDER = 'default'.freeze
|
15
|
-
|
16
|
-
def self.prepended(base)
|
17
|
-
ScoutApm::Agent.instance.logger.info("Prepended LegacySneakers in #{base}")
|
18
|
-
end
|
19
|
-
|
20
|
-
def initialize(*args)
|
21
|
-
super
|
22
|
-
|
23
|
-
# Save off the existing value to call the correct existing work
|
24
|
-
# function in the instrumentation. But then override Sneakers to always
|
25
|
-
# use the extra-argument version, which has data Scout needs
|
26
|
-
@call_work = respond_to?(:work)
|
27
|
-
end
|
28
|
-
|
29
|
-
def work_with_params(msg, delivery_info, metadata)
|
30
|
-
queue = delivery_info[:routing_key] || UNKNOWN_QUEUE_PLACEHOLDER
|
31
|
-
job_class = self.class.name
|
32
|
-
req = ScoutApm::RequestManager.lookup
|
33
|
-
|
34
|
-
begin
|
35
|
-
req.start_layer(ScoutApm::Layer.new('Queue', queue))
|
36
|
-
started_queue = true
|
37
|
-
req.start_layer(ScoutApm::Layer.new('Job', job_class))
|
38
|
-
started_job = true
|
39
|
-
|
40
|
-
if @call_work
|
41
|
-
work(msg)
|
42
|
-
else
|
43
|
-
super
|
44
|
-
end
|
45
|
-
rescue Exception
|
46
|
-
req.error!
|
47
|
-
raise
|
48
|
-
ensure
|
49
|
-
req.stop_layer if started_job
|
50
|
-
req.stop_layer if started_queue
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,134 +0,0 @@
|
|
1
|
-
module ScoutApm
|
2
|
-
module BackgroundJobIntegrations
|
3
|
-
class Que
|
4
|
-
|
5
|
-
UNKNOWN_CLASS_PLACEHOLDER = 'UnknownJob'.freeze
|
6
|
-
ACTIVE_JOB_KLASS = 'ActiveJob::QueueAdapters::QueAdapter::JobWrapper'.freeze
|
7
|
-
UNKNOWN_QUEUE_PLACEHOLDER = 'UnknownQueue'.freeze
|
8
|
-
|
9
|
-
attr_reader :logger
|
10
|
-
|
11
|
-
def name
|
12
|
-
:que
|
13
|
-
end
|
14
|
-
|
15
|
-
def present?
|
16
|
-
if defined?(::Que) && File.basename($PROGRAM_NAME).start_with?('que')
|
17
|
-
# 0.x releases used "Version" constant.
|
18
|
-
# 1.x releases used "VERSION" constant.
|
19
|
-
return defined?(::Que::Version)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def forking?
|
24
|
-
false
|
25
|
-
end
|
26
|
-
|
27
|
-
def install
|
28
|
-
install_tracer
|
29
|
-
install_worker
|
30
|
-
install_job
|
31
|
-
end
|
32
|
-
|
33
|
-
def install_tracer
|
34
|
-
::Que::Job.class_eval do
|
35
|
-
include ScoutApm::Tracer
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def install_worker
|
40
|
-
::Que::Worker.class_eval do
|
41
|
-
def initialize_with_scout(*args)
|
42
|
-
agent = ::ScoutApm::Agent.instance
|
43
|
-
agent.start
|
44
|
-
initialize_without_scout(*args)
|
45
|
-
end
|
46
|
-
|
47
|
-
alias_method :initialize_without_scout, :initialize
|
48
|
-
alias_method :initialize, :initialize_with_scout
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def install_job
|
53
|
-
::Que::Job.class_eval do
|
54
|
-
# attrs = {
|
55
|
-
# "queue"=>"",
|
56
|
-
# "priority"=>100,
|
57
|
-
# "run_at"=>2018-12-19 15:12:32 -0700,
|
58
|
-
# "job_id"=>4,
|
59
|
-
# "job_class"=>"ExampleJob",
|
60
|
-
# "args"=>[{"key"=>"value"}],
|
61
|
-
# "error_count"=>0
|
62
|
-
# }
|
63
|
-
#
|
64
|
-
# With ActiveJob, v0.14.3:
|
65
|
-
# attrs = {
|
66
|
-
# "queue"=>"",
|
67
|
-
# "priority"=>100,
|
68
|
-
# "run_at"=>2018-12-19 15:29:18 -0700,
|
69
|
-
# "job_id"=>6,
|
70
|
-
# "job_class"=>"ActiveJob::QueueAdapters::QueAdapter::JobWrapper",
|
71
|
-
# "args"=> [{
|
72
|
-
# "job_class"=>"ExampleJob",
|
73
|
-
# "job_id"=>"60798b45-4b55-436e-806d-693939266c97",
|
74
|
-
# "provider_job_id"=>nil,
|
75
|
-
# "queue_name"=>"default",
|
76
|
-
# "priority"=>nil,
|
77
|
-
# "arguments"=>[],
|
78
|
-
# "executions"=>0,
|
79
|
-
# "locale"=>"en"
|
80
|
-
# }],
|
81
|
-
# "error_count"=>0
|
82
|
-
# }
|
83
|
-
#
|
84
|
-
# With ActiveJob, v1.0:
|
85
|
-
# There are changes here to make Que more compatible with ActiveJob
|
86
|
-
# and this probably needs to be revisited.
|
87
|
-
|
88
|
-
def _run_with_scout(*args)
|
89
|
-
# default queue unless specifed is a blank string
|
90
|
-
queue = attrs['queue'] || UNKNOWN_QUEUE_PLACEHOLDER
|
91
|
-
|
92
|
-
job_class = begin
|
93
|
-
if self.class == ActiveJob::QueueAdapters::QueAdapter::JobWrapper
|
94
|
-
Array(attrs['args']).first['job_class'] || UNKNOWN_CLASS_PLACEHOLDER
|
95
|
-
else
|
96
|
-
self.class.name
|
97
|
-
end
|
98
|
-
rescue => e
|
99
|
-
UNKNOWN_CLASS_PLACEHOLDER
|
100
|
-
end
|
101
|
-
|
102
|
-
latency = begin
|
103
|
-
Time.now - attrs['run_at']
|
104
|
-
rescue
|
105
|
-
0
|
106
|
-
end
|
107
|
-
|
108
|
-
req = ScoutApm::RequestManager.lookup
|
109
|
-
req.annotate_request(:queue_latency => latency)
|
110
|
-
|
111
|
-
begin
|
112
|
-
req.start_layer(ScoutApm::Layer.new('Queue', queue))
|
113
|
-
started_queue = true
|
114
|
-
req.start_layer(ScoutApm::Layer.new('Job', job_class))
|
115
|
-
started_job = true
|
116
|
-
|
117
|
-
_run_without_scout(*args)
|
118
|
-
rescue Exception => e
|
119
|
-
req.error!
|
120
|
-
raise
|
121
|
-
ensure
|
122
|
-
req.stop_layer if started_job
|
123
|
-
req.stop_layer if started_queue
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
alias_method :_run_without_scout, :_run
|
128
|
-
alias_method :_run, :_run_with_scout
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
end
|
134
|
-
end
|
@@ -1,88 +0,0 @@
|
|
1
|
-
module ScoutApm
|
2
|
-
module BackgroundJobIntegrations
|
3
|
-
class Resque
|
4
|
-
def name
|
5
|
-
:resque
|
6
|
-
end
|
7
|
-
|
8
|
-
def present?
|
9
|
-
defined?(::Resque) &&
|
10
|
-
::Resque.respond_to?(:before_first_fork) &&
|
11
|
-
::Resque.respond_to?(:after_fork)
|
12
|
-
end
|
13
|
-
|
14
|
-
# Lies. This forks really aggressively, but we have to do handling
|
15
|
-
# of it manually here, rather than via any sort of automatic
|
16
|
-
# background worker starting
|
17
|
-
def forking?
|
18
|
-
false
|
19
|
-
end
|
20
|
-
|
21
|
-
def install
|
22
|
-
install_before_fork
|
23
|
-
install_after_fork
|
24
|
-
end
|
25
|
-
|
26
|
-
def install_before_fork
|
27
|
-
::Resque.before_first_fork do
|
28
|
-
begin
|
29
|
-
if ScoutApm::Agent.instance.context.config.value('start_resque_server_instrument')
|
30
|
-
ScoutApm::Agent.instance.start
|
31
|
-
ScoutApm::Agent.instance.context.start_remote_server!(bind, port)
|
32
|
-
else
|
33
|
-
logger.info("Not starting remote server due to 'start_resque_server_instrument' setting")
|
34
|
-
end
|
35
|
-
rescue Errno::EADDRINUSE
|
36
|
-
ScoutApm::Agent.instance.context.logger.warn "Error while Installing Resque Instruments, Port #{port} already in use. Set via the `remote_agent_port` configuration option"
|
37
|
-
rescue => e
|
38
|
-
ScoutApm::Agent.instance.context.logger.warn "Error while Installing Resque before_first_fork: #{e.inspect}"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def install_after_fork
|
44
|
-
::Resque.after_fork do
|
45
|
-
begin
|
46
|
-
ScoutApm::Agent.instance.context.become_remote_client!(bind, port)
|
47
|
-
inject_job_instrument
|
48
|
-
rescue => e
|
49
|
-
ScoutApm::Agent.instance.context.logger.warn "Error while Installing Resque after_fork: #{e.inspect}"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
# Insert ourselves into the point when resque turns a string "TestJob"
|
55
|
-
# into the class constant TestJob, and insert our instrumentation plugin
|
56
|
-
# into that constantized class
|
57
|
-
#
|
58
|
-
# This automates away any need for the user to insert our instrumentation into
|
59
|
-
# each of their jobs
|
60
|
-
def inject_job_instrument
|
61
|
-
::Resque::Job.class_eval do
|
62
|
-
def payload_class_with_scout_instruments
|
63
|
-
klass = payload_class_without_scout_instruments
|
64
|
-
klass.extend(ScoutApm::Instruments::Resque)
|
65
|
-
klass
|
66
|
-
end
|
67
|
-
alias_method :payload_class_without_scout_instruments, :payload_class
|
68
|
-
alias_method :payload_class, :payload_class_with_scout_instruments
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
private
|
73
|
-
|
74
|
-
def bind
|
75
|
-
config.value("remote_agent_host")
|
76
|
-
end
|
77
|
-
|
78
|
-
def port
|
79
|
-
config.value("remote_agent_port")
|
80
|
-
end
|
81
|
-
|
82
|
-
def config
|
83
|
-
@config || ScoutApm::Agent.instance.context.config
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
@@ -1,124 +0,0 @@
|
|
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
|
-
|
@@ -1,87 +0,0 @@
|
|
1
|
-
module ScoutApm
|
2
|
-
module BackgroundJobIntegrations
|
3
|
-
class Sneakers
|
4
|
-
def name
|
5
|
-
:sneakers
|
6
|
-
end
|
7
|
-
|
8
|
-
def present?
|
9
|
-
defined?(::Sneakers) && supported_version?
|
10
|
-
end
|
11
|
-
|
12
|
-
# Only support Sneakers 2.7 and up
|
13
|
-
def supported_version?
|
14
|
-
result = Gem::Version.new(::Sneakers::VERSION) > Gem::Version.new("2.7.0")
|
15
|
-
ScoutApm::Agent.instance.logger.info("Skipping Sneakers instrumentation. Only versions 2.7+ are supported. See docs or contact support@scoutapm.com for instrumentation of older versions.")
|
16
|
-
result
|
17
|
-
rescue
|
18
|
-
ScoutApm::Agent.instance.logger.info("Failed comparing Sneakers Version. Skipping")
|
19
|
-
false
|
20
|
-
end
|
21
|
-
|
22
|
-
def forking?
|
23
|
-
false
|
24
|
-
end
|
25
|
-
|
26
|
-
def install
|
27
|
-
install_worker_override
|
28
|
-
end
|
29
|
-
|
30
|
-
def install_worker_override
|
31
|
-
::Sneakers::Worker.module_eval do
|
32
|
-
def initialize_with_scout(*args)
|
33
|
-
agent = ::ScoutApm::Agent.instance
|
34
|
-
agent.start
|
35
|
-
initialize_without_scout(*args)
|
36
|
-
end
|
37
|
-
|
38
|
-
alias_method :initialize_without_scout, :initialize
|
39
|
-
alias_method :initialize, :initialize_with_scout
|
40
|
-
|
41
|
-
def process_work_with_scout(*args)
|
42
|
-
delivery_info, _metadata, msg, _handler = args
|
43
|
-
|
44
|
-
queue = delivery_info[:routing_key] || UNKNOWN_QUEUE_PLACEHOLDER
|
45
|
-
|
46
|
-
job_class = begin
|
47
|
-
if self.class == ActiveJob::QueueAdapters::SneakersAdapter::JobWrapper
|
48
|
-
msg["job_class"] || UNKNOWN_CLASS_PLACEHOLDER
|
49
|
-
else
|
50
|
-
self.class.name
|
51
|
-
end
|
52
|
-
rescue => e
|
53
|
-
UNKNOWN_CLASS_PLACEHOLDER
|
54
|
-
end
|
55
|
-
|
56
|
-
req = ScoutApm::RequestManager.lookup
|
57
|
-
|
58
|
-
# RabbitMQ does not store a created-at timestamp
|
59
|
-
# req.annotate_request(:queue_latency => latency(msg))
|
60
|
-
|
61
|
-
begin
|
62
|
-
req.start_layer(ScoutApm::Layer.new('Queue', queue))
|
63
|
-
started_queue = true
|
64
|
-
req.start_layer(ScoutApm::Layer.new('Job', job_class))
|
65
|
-
started_job = true
|
66
|
-
|
67
|
-
process_work_without_scout(*args)
|
68
|
-
rescue Exception => e
|
69
|
-
req.error!
|
70
|
-
raise
|
71
|
-
ensure
|
72
|
-
req.stop_layer if started_job
|
73
|
-
req.stop_layer if started_queue
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
alias_method :process_work_without_scout, :process_work
|
78
|
-
alias_method :process_work, :process_work_with_scout
|
79
|
-
end
|
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
|