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,26 +1,22 @@
|
|
1
1
|
module ScoutApm
|
2
2
|
module Instruments
|
3
3
|
class InfluxDB
|
4
|
-
attr_reader :
|
4
|
+
attr_reader :logger
|
5
5
|
|
6
|
-
def
|
7
|
-
@
|
6
|
+
def initalize(logger=ScoutApm::Agent.instance.logger)
|
7
|
+
@logger = logger
|
8
8
|
@installed = false
|
9
9
|
end
|
10
10
|
|
11
|
-
def logger
|
12
|
-
context.logger
|
13
|
-
end
|
14
|
-
|
15
11
|
def installed?
|
16
12
|
@installed
|
17
13
|
end
|
18
14
|
|
19
15
|
def install
|
20
|
-
|
21
|
-
@installed = true
|
16
|
+
@installed = true
|
22
17
|
|
23
|
-
|
18
|
+
if defined?(::InfluxDB)
|
19
|
+
ScoutApm::Agent.instance.logger.debug "Instrumenting InfluxDB"
|
24
20
|
|
25
21
|
::InfluxDB::Client.class_eval do
|
26
22
|
include ScoutApm::Tracer
|
@@ -1,36 +1,32 @@
|
|
1
1
|
# Inserts a new middleware between each actual middleware in the application,
|
2
2
|
# so as to trace the time for each one.
|
3
3
|
#
|
4
|
-
# Currently disabled
|
5
|
-
#
|
6
|
-
#
|
4
|
+
# Currently disabled due to the overhead of this approach (~10-15ms per request
|
5
|
+
# in practice). Instead, middleware as a whole are instrumented via the
|
6
|
+
# MiddlewareSummary class.
|
7
7
|
#
|
8
|
-
#
|
8
|
+
# There will likely be a configuration flag to turn this on in favor of the
|
9
|
+
# summary tracing in a future version of the agent, but this is not yet
|
10
|
+
# implemented.
|
9
11
|
module ScoutApm
|
10
12
|
module Instruments
|
11
13
|
class MiddlewareDetailed
|
12
|
-
|
13
|
-
|
14
|
-
def initialize(context)
|
15
|
-
@context = context
|
14
|
+
def initalize(logger=ScoutApm::Agent.instance.logger)
|
15
|
+
@logger = logger
|
16
16
|
@installed = false
|
17
17
|
end
|
18
18
|
|
19
|
-
def logger
|
20
|
-
context.logger
|
21
|
-
end
|
22
|
-
|
23
19
|
def installed?
|
24
20
|
@installed
|
25
21
|
end
|
26
22
|
|
27
23
|
def install
|
28
|
-
|
29
|
-
@installed = true
|
24
|
+
@installed = true
|
30
25
|
|
26
|
+
if defined?(ActionDispatch) && defined?(ActionDispatch::MiddlewareStack) && defined?(ActionDispatch::MiddlewareStack::Middleware)
|
31
27
|
ActionDispatch::MiddlewareStack::Middleware.class_eval do
|
32
28
|
def build(app)
|
33
|
-
ScoutApm::Agent.instance.
|
29
|
+
ScoutApm::Agent.instance.logger.info("Building Middleware #{klass.name}")
|
34
30
|
new_mw = klass.new(app, *args, &block)
|
35
31
|
MiddlewareWrapper.new(new_mw, klass.name)
|
36
32
|
end
|
@@ -6,26 +6,20 @@
|
|
6
6
|
module ScoutApm
|
7
7
|
module Instruments
|
8
8
|
class MiddlewareSummary
|
9
|
-
|
10
|
-
|
11
|
-
def initialize(context)
|
12
|
-
@context = context
|
9
|
+
def initalize(logger=ScoutApm::Agent.instance.logger)
|
10
|
+
@logger = logger
|
13
11
|
@installed = false
|
14
12
|
end
|
15
13
|
|
16
|
-
def logger
|
17
|
-
context.logger
|
18
|
-
end
|
19
|
-
|
20
14
|
def installed?
|
21
15
|
@installed
|
22
16
|
end
|
23
17
|
|
24
18
|
def install
|
25
|
-
|
26
|
-
@installed = true
|
19
|
+
@installed = true
|
27
20
|
|
28
|
-
|
21
|
+
if defined?(ActionDispatch) && defined?(ActionDispatch::MiddlewareStack)
|
22
|
+
ScoutApm::Agent.instance.logger.info("Instrumenting Middleware")
|
29
23
|
ActionDispatch::MiddlewareStack.class_eval do
|
30
24
|
def build_with_scout_instruments(app = nil, &block)
|
31
25
|
mw_stack = build_without_scout_instruments(app) { block.call if block }
|
@@ -1,17 +1,13 @@
|
|
1
1
|
module ScoutApm
|
2
2
|
module Instruments
|
3
3
|
class Mongoid
|
4
|
-
attr_reader :
|
4
|
+
attr_reader :logger
|
5
5
|
|
6
|
-
def
|
7
|
-
@
|
6
|
+
def initalize(logger=ScoutApm::Agent.instance.logger)
|
7
|
+
@logger = logger
|
8
8
|
@installed = false
|
9
9
|
end
|
10
10
|
|
11
|
-
def logger
|
12
|
-
context.logger
|
13
|
-
end
|
14
|
-
|
15
11
|
def installed?
|
16
12
|
@installed
|
17
13
|
end
|
@@ -21,8 +17,7 @@ module ScoutApm
|
|
21
17
|
|
22
18
|
# Mongoid versions that use Moped should instrument Moped.
|
23
19
|
if defined?(::Mongoid) and !defined?(::Moped)
|
24
|
-
logger.info "Instrumenting Mongoid 2.x"
|
25
|
-
@installed = true
|
20
|
+
ScoutApm::Agent.instance.logger.info "Instrumenting Mongoid 2.x"
|
26
21
|
|
27
22
|
### OLD (2.x) mongoids
|
28
23
|
if defined?(::Mongoid::Collection)
|
@@ -37,8 +32,8 @@ module ScoutApm
|
|
37
32
|
### See moped instrument for Moped driven deploys
|
38
33
|
|
39
34
|
### 5.x Mongoid
|
40
|
-
if
|
41
|
-
logger.info "Instrumenting Mongoid 5.x
|
35
|
+
if mongoid_v5? && defined?(::Mongoid::Contextual::Mongo)
|
36
|
+
ScoutApm::Agent.instance.logger.info "Instrumenting Mongoid 5.x"
|
42
37
|
# All the public methods from Mongoid::Contextual::Mongo.
|
43
38
|
# TODO: Geo and MapReduce support (?). They are in other Contextual::* classes
|
44
39
|
methods = [
|
@@ -54,23 +49,12 @@ module ScoutApm
|
|
54
49
|
if ::Mongoid::Contextual::Mongo.method_defined?(method)
|
55
50
|
with_scout_instruments = %Q[
|
56
51
|
def #{method}_with_scout_instruments(*args, &block)
|
52
|
+
|
57
53
|
req = ScoutApm::RequestManager.lookup
|
58
54
|
*db, collection = view.collection.namespace.split(".")
|
59
55
|
|
60
56
|
name = collection + "/#{method}"
|
61
|
-
|
62
|
-
# Between Mongo gem version 2.1 and 2.3, this method name was
|
63
|
-
# changed. Accomodate both. If for some reason neither is
|
64
|
-
# there, try to continue with an empty "filter" hash.
|
65
|
-
raw_filter = if view.respond_to?(:selector)
|
66
|
-
view.selector
|
67
|
-
elsif view.respond_to?(:filter)
|
68
|
-
view.filter
|
69
|
-
else
|
70
|
-
{}
|
71
|
-
end
|
72
|
-
|
73
|
-
filter = ScoutApm::Instruments::Mongoid.anonymize_filter(raw_filter)
|
57
|
+
filter = ScoutApm::Instruments::Mongoid.anonymize_filter(view.filter)
|
74
58
|
|
75
59
|
layer = ScoutApm::Layer.new("MongoDB", name)
|
76
60
|
layer.desc = filter.inspect
|
@@ -102,21 +86,6 @@ module ScoutApm
|
|
102
86
|
end
|
103
87
|
end
|
104
88
|
|
105
|
-
def mongoid_v6?
|
106
|
-
if defined?(::Mongoid::VERSION)
|
107
|
-
::Mongoid::VERSION =~ /\A6/
|
108
|
-
else
|
109
|
-
false
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def mongoid_v7?
|
114
|
-
if defined?(::Mongoid::VERSION)
|
115
|
-
::Mongoid::VERSION =~ /\A7/
|
116
|
-
else
|
117
|
-
false
|
118
|
-
end
|
119
|
-
end
|
120
89
|
|
121
90
|
# Example of what a filter looks like: => {"founded"=>{"$gte"=>"1980-1-1"}, "name"=>{"$in"=>["Tool", "Deftones", "Melvins"]}}
|
122
91
|
# Approach: find every leaf-node, clear it. inspect the whole thing when done.
|
@@ -1,27 +1,22 @@
|
|
1
1
|
module ScoutApm
|
2
2
|
module Instruments
|
3
3
|
class Moped
|
4
|
-
attr_reader :
|
4
|
+
attr_reader :logger
|
5
5
|
|
6
|
-
def
|
7
|
-
@
|
6
|
+
def initalize(logger=ScoutApm::Agent.instance.logger)
|
7
|
+
@logger = logger
|
8
8
|
@installed = false
|
9
9
|
end
|
10
10
|
|
11
|
-
def logger
|
12
|
-
context.logger
|
13
|
-
end
|
14
|
-
|
15
11
|
def installed?
|
16
12
|
@installed
|
17
13
|
end
|
18
14
|
|
19
15
|
def install
|
20
|
-
|
21
|
-
@installed = true
|
22
|
-
|
23
|
-
logger.info "Instrumenting Moped"
|
16
|
+
@installed = true
|
24
17
|
|
18
|
+
if defined?(::Moped)
|
19
|
+
ScoutApm::Agent.instance.logger.info "Instrumenting Moped"
|
25
20
|
::Moped::Node.class_eval do
|
26
21
|
include ScoutApm::Tracer
|
27
22
|
|
@@ -1,51 +1,33 @@
|
|
1
1
|
module ScoutApm
|
2
2
|
module Instruments
|
3
3
|
class NetHttp
|
4
|
-
attr_reader :
|
4
|
+
attr_reader :logger
|
5
5
|
|
6
|
-
def
|
7
|
-
@
|
6
|
+
def initalize(logger=ScoutApm::Agent.instance.logger)
|
7
|
+
@logger = logger
|
8
8
|
@installed = false
|
9
9
|
end
|
10
10
|
|
11
|
-
def logger
|
12
|
-
context.logger
|
13
|
-
end
|
14
|
-
|
15
11
|
def installed?
|
16
12
|
@installed
|
17
13
|
end
|
18
14
|
|
19
15
|
def install
|
20
|
-
|
21
|
-
@installed = true
|
16
|
+
@installed = true
|
22
17
|
|
23
|
-
|
18
|
+
if defined?(::Net) && defined?(::Net::HTTP)
|
19
|
+
ScoutApm::Agent.instance.logger.info "Instrumenting Net::HTTP"
|
24
20
|
|
25
21
|
::Net::HTTP.class_eval do
|
26
22
|
include ScoutApm::Tracer
|
27
23
|
|
28
|
-
def request_with_scout_instruments(*args
|
29
|
-
|
24
|
+
def request_with_scout_instruments(*args,&block)
|
25
|
+
url = (@address + args.first.path.split('?').first)[0..99]
|
26
|
+
self.class.instrument("HTTP", "request", :desc => url) do
|
30
27
|
request_without_scout_instruments(*args, &block)
|
31
28
|
end
|
32
29
|
end
|
33
30
|
|
34
|
-
def request_scout_description(req)
|
35
|
-
path = req.path
|
36
|
-
path = path.path if path.respond_to?(:path)
|
37
|
-
|
38
|
-
# Protect against a nil address value
|
39
|
-
if @address.nil?
|
40
|
-
return "No Address Found"
|
41
|
-
end
|
42
|
-
|
43
|
-
max_length = ScoutApm::Agent.instance.context.config.value('instrument_http_url_length')
|
44
|
-
(@address + path.split('?').first)[0..(max_length - 1)]
|
45
|
-
rescue
|
46
|
-
""
|
47
|
-
end
|
48
|
-
|
49
31
|
alias request_without_scout_instruments request
|
50
32
|
alias request request_with_scout_instruments
|
51
33
|
end
|
@@ -1,55 +1,36 @@
|
|
1
1
|
module ScoutApm
|
2
2
|
module Instruments
|
3
|
-
|
4
|
-
class HistogramReport
|
5
|
-
attr_reader :name
|
6
|
-
attr_reader :histogram
|
7
|
-
|
8
|
-
def initialize(name, histogram)
|
9
|
-
@name = name
|
10
|
-
@histogram = histogram
|
11
|
-
end
|
12
|
-
|
13
|
-
def combine!(other)
|
14
|
-
raise "Mismatched Histogram Names" unless name == other.name
|
15
|
-
histogram.combine!(other.histogram)
|
16
|
-
self
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
3
|
class PercentileSampler
|
21
|
-
|
22
|
-
@context = context
|
23
|
-
end
|
4
|
+
attr_reader :logger
|
24
5
|
|
25
|
-
|
26
|
-
@context.request_histograms_by_time
|
27
|
-
end
|
6
|
+
attr_reader :percentiles
|
28
7
|
|
29
|
-
def logger
|
30
|
-
@
|
8
|
+
def initialize(logger, percentiles)
|
9
|
+
@logger = logger
|
10
|
+
@percentiles = Array(percentiles)
|
31
11
|
end
|
32
12
|
|
33
13
|
def human_name
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
histogram.each_name do |name|
|
49
|
-
result << HistogramReport.new(name, histogram.raw(name))
|
14
|
+
"Percentiles"
|
15
|
+
end
|
16
|
+
|
17
|
+
# Gets the 95th%ile for the time requested
|
18
|
+
def metrics(time)
|
19
|
+
ms = {}
|
20
|
+
histos = ScoutApm::Agent.instance.request_histograms_by_time[time]
|
21
|
+
histos.each_name do |name|
|
22
|
+
percentiles.each do |percentile|
|
23
|
+
meta = MetricMeta.new("Percentile/#{percentile}/#{name}")
|
24
|
+
stat = MetricStats.new
|
25
|
+
stat.update!(histos.quantile(name, percentile))
|
26
|
+
ms[meta] = stat
|
27
|
+
end
|
50
28
|
end
|
51
29
|
|
52
|
-
|
30
|
+
# Wipe the histograms we just collected data on
|
31
|
+
ScoutApm::Agent.instance.request_histograms_by_time.delete(time)
|
32
|
+
|
33
|
+
ms
|
53
34
|
end
|
54
35
|
end
|
55
36
|
end
|
@@ -2,14 +2,14 @@ module ScoutApm
|
|
2
2
|
module Instruments
|
3
3
|
module Process
|
4
4
|
class ProcessCpu
|
5
|
+
attr_reader :logger
|
5
6
|
attr_reader :num_processors
|
6
7
|
attr_accessor :last_run, :last_utime, :last_stime
|
7
|
-
attr_reader :context
|
8
8
|
|
9
|
-
def initialize(context)
|
10
|
-
@context = context
|
11
9
|
|
12
|
-
|
10
|
+
def initialize(num_processors, logger)
|
11
|
+
@num_processors = [num_processors, 1].compact.max
|
12
|
+
@logger = logger
|
13
13
|
|
14
14
|
t = ::Process.times
|
15
15
|
@last_run = Time.now
|
@@ -29,17 +29,16 @@ module ScoutApm
|
|
29
29
|
"Process CPU"
|
30
30
|
end
|
31
31
|
|
32
|
-
def metrics(
|
32
|
+
def metrics(_time)
|
33
33
|
result = run
|
34
34
|
if result
|
35
35
|
meta = MetricMeta.new("#{metric_type}/#{metric_name}")
|
36
36
|
stat = MetricStats.new(false)
|
37
37
|
stat.update!(result)
|
38
|
-
|
38
|
+
{ meta => stat }
|
39
39
|
else
|
40
40
|
{}
|
41
41
|
end
|
42
|
-
|
43
42
|
end
|
44
43
|
|
45
44
|
# TODO: Figure out a good default instead of nil
|
@@ -98,10 +97,6 @@ module ScoutApm
|
|
98
97
|
self.last_utime = utime
|
99
98
|
self.last_stime = stime
|
100
99
|
end
|
101
|
-
|
102
|
-
def logger
|
103
|
-
context.logger
|
104
|
-
end
|
105
100
|
end
|
106
101
|
end
|
107
102
|
end
|
@@ -2,24 +2,23 @@ module ScoutApm
|
|
2
2
|
module Instruments
|
3
3
|
module Process
|
4
4
|
class ProcessMemory
|
5
|
-
|
6
|
-
|
7
|
-
# though...more of a utility.
|
8
|
-
def rss_to_mb(rss)
|
9
|
-
|
10
|
-
rss.to_f / 1024 / kilobyte_adjust
|
5
|
+
attr_reader :logger
|
6
|
+
|
7
|
+
# Account for Darwin returning maxrss in bytes and Linux in KB. Used by the slow converters. Doesn't feel like this should go here though...more of a utility.
|
8
|
+
def self.rss_to_mb(rss)
|
9
|
+
rss.to_f/1024/(ScoutApm::Agent.instance.environment.os == 'darwin' ? 1024 : 1)
|
11
10
|
end
|
12
11
|
|
13
|
-
def rss
|
12
|
+
def self.rss
|
14
13
|
::Process.rusage.maxrss
|
15
14
|
end
|
16
15
|
|
17
|
-
def rss_in_mb
|
16
|
+
def self.rss_in_mb
|
18
17
|
rss_to_mb(rss)
|
19
18
|
end
|
20
19
|
|
21
|
-
def initialize(
|
22
|
-
@
|
20
|
+
def initialize(logger)
|
21
|
+
@logger = logger
|
23
22
|
end
|
24
23
|
|
25
24
|
def metric_type
|
@@ -34,24 +33,20 @@ module ScoutApm
|
|
34
33
|
"Process Memory"
|
35
34
|
end
|
36
35
|
|
37
|
-
def metrics(
|
36
|
+
def metrics(_time)
|
38
37
|
result = run
|
39
38
|
if result
|
40
39
|
meta = MetricMeta.new("#{metric_type}/#{metric_name}")
|
41
40
|
stat = MetricStats.new(false)
|
42
41
|
stat.update!(result)
|
43
|
-
|
42
|
+
{ meta => stat }
|
44
43
|
else
|
45
44
|
{}
|
46
45
|
end
|
47
46
|
end
|
48
47
|
|
49
48
|
def run
|
50
|
-
rss_in_mb.tap { |res| logger.debug "#{human_name}: #{res.inspect}" }
|
51
|
-
end
|
52
|
-
|
53
|
-
def logger
|
54
|
-
@context.logger
|
49
|
+
self.class.rss_in_mb.tap { |res| logger.debug "#{human_name}: #{res.inspect}" }
|
55
50
|
end
|
56
51
|
end
|
57
52
|
end
|
@@ -1,25 +1,19 @@
|
|
1
1
|
module ScoutApm
|
2
2
|
module Instruments
|
3
3
|
class RailsRouter
|
4
|
-
|
5
|
-
|
6
|
-
def initialize(context)
|
7
|
-
@context = context
|
4
|
+
def initalize(logger=ScoutApm::Agent.instance.logger)
|
5
|
+
@logger = logger
|
8
6
|
@installed = false
|
9
7
|
end
|
10
8
|
|
11
|
-
def logger
|
12
|
-
context.logger
|
13
|
-
end
|
14
|
-
|
15
9
|
def installed?
|
16
10
|
@installed
|
17
11
|
end
|
18
12
|
|
19
13
|
def install
|
20
|
-
|
21
|
-
@installed = true
|
14
|
+
@installed = true
|
22
15
|
|
16
|
+
if defined?(ActionDispatch) && defined?(ActionDispatch::Routing) && defined?(ActionDispatch::Routing::RouteSet)
|
23
17
|
ActionDispatch::Routing::RouteSet.class_eval do
|
24
18
|
def call_with_scout_instruments(*args)
|
25
19
|
req = ScoutApm::RequestManager.lookup
|
@@ -32,8 +26,8 @@ module ScoutApm
|
|
32
26
|
end
|
33
27
|
end
|
34
28
|
|
35
|
-
|
36
|
-
|
29
|
+
alias call_without_scout_instruments call
|
30
|
+
alias call call_with_scout_instruments
|
37
31
|
end
|
38
32
|
end
|
39
33
|
end
|
@@ -1,26 +1,22 @@
|
|
1
1
|
module ScoutApm
|
2
2
|
module Instruments
|
3
3
|
class Redis
|
4
|
-
attr_reader :
|
4
|
+
attr_reader :logger
|
5
5
|
|
6
|
-
def
|
7
|
-
@
|
6
|
+
def initalize(logger=ScoutApm::Agent.instance.logger)
|
7
|
+
@logger = logger
|
8
8
|
@installed = false
|
9
9
|
end
|
10
10
|
|
11
|
-
def logger
|
12
|
-
context.logger
|
13
|
-
end
|
14
|
-
|
15
11
|
def installed?
|
16
12
|
@installed
|
17
13
|
end
|
18
14
|
|
19
15
|
def install
|
20
|
-
|
21
|
-
@installed = true
|
16
|
+
@installed = true
|
22
17
|
|
23
|
-
|
18
|
+
if defined?(::Redis) && defined?(::Redis::Client)
|
19
|
+
ScoutApm::Agent.instance.logger.info "Instrumenting Redis"
|
24
20
|
|
25
21
|
::Redis::Client.class_eval do
|
26
22
|
include ScoutApm::Tracer
|
@@ -1,10 +1,9 @@
|
|
1
|
-
# XXX: Is this file used?
|
2
1
|
module ScoutApm
|
3
2
|
module Instruments
|
4
3
|
class Sinatra
|
5
4
|
attr_reader :logger
|
6
5
|
|
7
|
-
def initalize(logger=ScoutApm::Agent.instance.
|
6
|
+
def initalize(logger=ScoutApm::Agent.instance.logger)
|
8
7
|
@logger = logger
|
9
8
|
@installed = false
|
10
9
|
end
|
@@ -14,10 +13,10 @@ module ScoutApm
|
|
14
13
|
end
|
15
14
|
|
16
15
|
def install
|
17
|
-
|
18
|
-
@installed = true
|
16
|
+
@installed = true
|
19
17
|
|
20
|
-
|
18
|
+
if defined?(::Sinatra) && defined?(::Sinatra::Base) && ::Sinatra::Base.private_method_defined?(:dispatch!)
|
19
|
+
ScoutApm::Agent.instance.logger.info "Instrumenting Sinatra"
|
21
20
|
::Sinatra::Base.class_eval do
|
22
21
|
include ScoutApm::Tracer
|
23
22
|
include ScoutApm::Instruments::SinatraInstruments
|
data/lib/scout_apm/job_record.rb
CHANGED
@@ -32,10 +32,8 @@ module ScoutApm
|
|
32
32
|
|
33
33
|
# Modifies self and returns self, after merging in `other`.
|
34
34
|
def combine!(other)
|
35
|
-
|
36
|
-
|
37
|
-
return self
|
38
|
-
end
|
35
|
+
same_job = queue_name == other.queue_name && job_name == other.job_name
|
36
|
+
raise "Mismatched Merge of Background Job" unless same_job
|
39
37
|
|
40
38
|
@errors += other.errors
|
41
39
|
@metric_set = metric_set.combine!(other.metric_set)
|