scout_apm 2.1.32 → 2.2.0.pre0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/CHANGELOG.markdown +2 -161
- data/Rakefile +2 -2
- data/ext/allocations/allocations.c +0 -6
- data/ext/allocations/extconf.rb +0 -1
- data/ext/stacks/extconf.rb +33 -0
- data/ext/stacks/scout_atomics.h +86 -0
- data/ext/stacks/stacks.c +744 -0
- data/lib/scout_apm.rb +16 -24
- data/lib/scout_apm/agent.rb +38 -93
- data/lib/scout_apm/agent/logging.rb +1 -6
- data/lib/scout_apm/agent/reporting.rb +6 -8
- data/lib/scout_apm/app_server_load.rb +10 -21
- data/lib/scout_apm/attribute_arranger.rb +2 -0
- data/lib/scout_apm/background_job_integrations/delayed_job.rb +1 -71
- data/lib/scout_apm/background_job_integrations/sidekiq.rb +27 -66
- data/lib/scout_apm/background_worker.rb +15 -19
- data/lib/scout_apm/capacity.rb +57 -0
- data/lib/scout_apm/config.rb +29 -135
- data/lib/scout_apm/context.rb +5 -9
- 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 +15 -22
- data/lib/scout_apm/histogram.rb +2 -11
- data/lib/scout_apm/instant/assets/xmlhttp_instrumentation.html +2 -2
- data/lib/scout_apm/instant/middleware.rb +57 -198
- data/lib/scout_apm/instruments/action_controller_rails_2.rb +2 -1
- data/lib/scout_apm/instruments/action_controller_rails_3_rails4.rb +59 -90
- data/lib/scout_apm/instruments/active_record.rb +5 -7
- data/lib/scout_apm/instruments/delayed_job.rb +57 -0
- data/lib/scout_apm/instruments/grape.rb +3 -4
- data/lib/scout_apm/instruments/middleware_detailed.rb +6 -4
- data/lib/scout_apm/instruments/middleware_summary.rb +1 -39
- data/lib/scout_apm/instruments/mongoid.rb +3 -24
- data/lib/scout_apm/instruments/net_http.rb +2 -7
- data/lib/scout_apm/instruments/percentile_sampler.rb +19 -36
- data/lib/scout_apm/instruments/process/process_cpu.rb +2 -3
- data/lib/scout_apm/instruments/process/process_memory.rb +3 -3
- data/lib/scout_apm/layaway.rb +33 -76
- data/lib/scout_apm/layer.rb +59 -16
- data/lib/scout_apm/layer_converters/converter_base.rb +0 -199
- data/lib/scout_apm/layer_converters/job_converter.rb +1 -1
- data/lib/scout_apm/layer_converters/metric_converter.rb +1 -1
- data/lib/scout_apm/layer_converters/slow_job_converter.rb +90 -15
- data/lib/scout_apm/layer_converters/slow_request_converter.rb +101 -13
- data/lib/scout_apm/metric_set.rb +1 -9
- data/lib/scout_apm/metric_stats.rb +8 -8
- data/lib/scout_apm/reporter.rb +15 -51
- data/lib/scout_apm/request_histograms.rb +0 -4
- data/lib/scout_apm/request_manager.rb +1 -2
- data/lib/scout_apm/scored_item_set.rb +0 -7
- data/lib/scout_apm/serializers/deploy_serializer.rb +16 -0
- data/lib/scout_apm/serializers/payload_serializer.rb +3 -9
- data/lib/scout_apm/serializers/payload_serializer_to_json.rb +5 -2
- data/lib/scout_apm/serializers/slow_jobs_serializer_to_json.rb +1 -2
- data/lib/scout_apm/server_integrations/puma.rb +2 -5
- data/lib/scout_apm/slow_item_set.rb +80 -0
- data/lib/scout_apm/slow_job_record.rb +1 -6
- data/lib/scout_apm/slow_transaction.rb +2 -20
- data/lib/scout_apm/store.rb +12 -50
- data/lib/scout_apm/trace_compactor.rb +311 -0
- data/lib/scout_apm/tracked_request.rb +37 -128
- data/lib/scout_apm/utils/backtrace_parser.rb +5 -7
- data/lib/scout_apm/utils/fake_stacks.rb +83 -0
- data/lib/scout_apm/version.rb +1 -1
- data/scout_apm.gemspec +4 -6
- data/test/test_helper.rb +0 -56
- data/test/unit/config_test.rb +9 -60
- data/test/unit/histogram_test.rb +0 -14
- data/test/unit/layaway_test.rb +16 -31
- data/test/unit/serializers/payload_serializer_test.rb +105 -3
- data/test/unit/slow_item_set_test.rb +94 -0
- data/test/unit/slow_job_policy_test.rb +49 -0
- data/test/unit/slow_request_policy_test.rb +5 -4
- data/test/unit/utils/backtrace_parser_test.rb +0 -19
- data/tester.rb +53 -0
- metadata +29 -124
- data/.rubocop.yml +0 -8
- data/Guardfile +0 -42
- data/ext/rusage/README.md +0 -26
- data/ext/rusage/extconf.rb +0 -5
- data/ext/rusage/rusage.c +0 -52
- data/lib/scout_apm/background_job_integrations/resque.rb +0 -85
- data/lib/scout_apm/background_recorder.rb +0 -43
- data/lib/scout_apm/debug.rb +0 -37
- data/lib/scout_apm/git_revision.rb +0 -51
- data/lib/scout_apm/instruments/action_view.rb +0 -49
- data/lib/scout_apm/instruments/resque.rb +0 -40
- data/lib/scout_apm/layer_children_set.rb +0 -77
- data/lib/scout_apm/limited_layer.rb +0 -122
- data/lib/scout_apm/rack.rb +0 -26
- data/lib/scout_apm/remote/message.rb +0 -23
- 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 -58
- data/lib/scout_apm/serializers/histograms_serializer_to_json.rb +0 -21
- data/lib/scout_apm/synchronous_recorder.rb +0 -26
- data/lib/scout_apm/utils/gzip_helper.rb +0 -24
- data/lib/scout_apm/utils/numbers.rb +0 -14
- data/lib/scout_apm/utils/scm.rb +0 -14
- data/test/unit/background_job_integrations/sidekiq_test.rb +0 -104
- data/test/unit/context_test.rb +0 -30
- data/test/unit/git_revision_test.rb +0 -15
- data/test/unit/instruments/net_http_test.rb +0 -21
- data/test/unit/instruments/percentile_sampler_test.rb +0 -137
- data/test/unit/layer_children_set_test.rb +0 -88
- data/test/unit/limited_layer_test.rb +0 -53
- 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/store_test.rb +0 -89
- data/test/unit/test_tracked_request.rb +0 -87
- data/test/unit/utils/numbers_test.rb +0 -15
- data/test/unit/utils/scm.rb +0 -17
data/lib/scout_apm.rb
CHANGED
@@ -14,7 +14,7 @@ require 'socket'
|
|
14
14
|
require 'thread'
|
15
15
|
require 'time'
|
16
16
|
require 'yaml'
|
17
|
-
require '
|
17
|
+
require 'rbconfig'
|
18
18
|
|
19
19
|
#####################################
|
20
20
|
# Gem Requires
|
@@ -26,11 +26,8 @@ require 'rusage'
|
|
26
26
|
#####################################
|
27
27
|
require 'scout_apm/version'
|
28
28
|
|
29
|
-
require 'scout_apm/debug'
|
30
29
|
require 'scout_apm/tracked_request'
|
31
30
|
require 'scout_apm/layer'
|
32
|
-
require 'scout_apm/limited_layer'
|
33
|
-
require 'scout_apm/layer_children_set'
|
34
31
|
require 'scout_apm/request_manager'
|
35
32
|
require 'scout_apm/call_set'
|
36
33
|
|
@@ -54,7 +51,6 @@ require 'scout_apm/server_integrations/null'
|
|
54
51
|
|
55
52
|
require 'scout_apm/background_job_integrations/sidekiq'
|
56
53
|
require 'scout_apm/background_job_integrations/delayed_job'
|
57
|
-
require 'scout_apm/background_job_integrations/resque'
|
58
54
|
|
59
55
|
require 'scout_apm/framework_integrations/rails_2'
|
60
56
|
require 'scout_apm/framework_integrations/rails_3_or_4'
|
@@ -67,6 +63,9 @@ require 'scout_apm/platform_integrations/server'
|
|
67
63
|
|
68
64
|
require 'scout_apm/histogram'
|
69
65
|
|
66
|
+
require 'scout_apm/deploy_integrations/capistrano_3'
|
67
|
+
# require 'scout_apm/deploy_integrations/capistrano_2'
|
68
|
+
|
70
69
|
require 'scout_apm/instruments/net_http'
|
71
70
|
require 'scout_apm/instruments/http_client'
|
72
71
|
require 'scout_apm/instruments/moped'
|
@@ -74,20 +73,26 @@ require 'scout_apm/instruments/mongoid'
|
|
74
73
|
require 'scout_apm/instruments/redis'
|
75
74
|
require 'scout_apm/instruments/influxdb'
|
76
75
|
require 'scout_apm/instruments/elasticsearch'
|
76
|
+
require 'scout_apm/instruments/delayed_job'
|
77
77
|
require 'scout_apm/instruments/active_record'
|
78
78
|
require 'scout_apm/instruments/action_controller_rails_2'
|
79
79
|
require 'scout_apm/instruments/action_controller_rails_3_rails4'
|
80
80
|
require 'scout_apm/instruments/middleware_summary'
|
81
|
-
require 'scout_apm/instruments/middleware_detailed' #
|
81
|
+
# require 'scout_apm/instruments/middleware_detailed' # Currently disabled functionality, see the file for details.
|
82
82
|
require 'scout_apm/instruments/rails_router'
|
83
83
|
require 'scout_apm/instruments/grape'
|
84
84
|
require 'scout_apm/instruments/sinatra'
|
85
85
|
require 'scout_apm/instruments/process/process_cpu'
|
86
86
|
require 'scout_apm/instruments/process/process_memory'
|
87
87
|
require 'scout_apm/instruments/percentile_sampler'
|
88
|
-
require 'scout_apm/instruments/action_view'
|
89
88
|
require 'allocations'
|
90
89
|
|
90
|
+
begin
|
91
|
+
require 'stacks'
|
92
|
+
rescue LoadError
|
93
|
+
require 'scout_apm/utils/fake_stacks'
|
94
|
+
end
|
95
|
+
|
91
96
|
require 'scout_apm/app_server_load'
|
92
97
|
|
93
98
|
require 'scout_apm/ignored_uris.rb'
|
@@ -96,12 +101,9 @@ require 'scout_apm/utils/backtrace_parser'
|
|
96
101
|
require 'scout_apm/utils/installed_gems'
|
97
102
|
require 'scout_apm/utils/klass_helper'
|
98
103
|
require 'scout_apm/utils/null_logger'
|
99
|
-
require 'scout_apm/utils/scm'
|
100
104
|
require 'scout_apm/utils/sql_sanitizer'
|
101
105
|
require 'scout_apm/utils/time'
|
102
106
|
require 'scout_apm/utils/unique_id'
|
103
|
-
require 'scout_apm/utils/numbers'
|
104
|
-
require 'scout_apm/utils/gzip_helper'
|
105
107
|
|
106
108
|
require 'scout_apm/config'
|
107
109
|
require 'scout_apm/environment'
|
@@ -120,43 +122,35 @@ require 'scout_apm/fake_store'
|
|
120
122
|
require 'scout_apm/tracer'
|
121
123
|
require 'scout_apm/context'
|
122
124
|
require 'scout_apm/instant_reporting'
|
123
|
-
require 'scout_apm/
|
124
|
-
require 'scout_apm/synchronous_recorder'
|
125
|
+
require 'scout_apm/trace_compactor'
|
125
126
|
|
126
127
|
require 'scout_apm/metric_meta'
|
127
128
|
require 'scout_apm/metric_stats'
|
128
129
|
require 'scout_apm/slow_transaction'
|
129
130
|
require 'scout_apm/slow_job_record'
|
131
|
+
require 'scout_apm/slow_item_set'
|
130
132
|
require 'scout_apm/scored_item_set'
|
131
133
|
require 'scout_apm/slow_request_policy'
|
132
134
|
require 'scout_apm/slow_job_policy'
|
133
135
|
require 'scout_apm/job_record'
|
134
136
|
require 'scout_apm/request_histograms'
|
135
137
|
|
138
|
+
require 'scout_apm/capacity'
|
136
139
|
require 'scout_apm/attribute_arranger'
|
137
|
-
require 'scout_apm/git_revision'
|
138
140
|
|
139
141
|
require 'scout_apm/serializers/payload_serializer'
|
140
142
|
require 'scout_apm/serializers/payload_serializer_to_json'
|
141
143
|
require 'scout_apm/serializers/jobs_serializer_to_json'
|
142
144
|
require 'scout_apm/serializers/slow_jobs_serializer_to_json'
|
143
145
|
require 'scout_apm/serializers/metrics_to_json_serializer'
|
144
|
-
require 'scout_apm/serializers/histograms_serializer_to_json'
|
145
146
|
require 'scout_apm/serializers/directive_serializer'
|
146
147
|
require 'scout_apm/serializers/app_server_load_serializer'
|
148
|
+
require 'scout_apm/serializers/deploy_serializer'
|
147
149
|
|
148
150
|
require 'scout_apm/middleware'
|
149
151
|
|
150
152
|
require 'scout_apm/instant/middleware'
|
151
153
|
|
152
|
-
require 'scout_apm/rack'
|
153
|
-
|
154
|
-
require 'scout_apm/remote/server'
|
155
|
-
require 'scout_apm/remote/router'
|
156
|
-
require 'scout_apm/remote/message'
|
157
|
-
require 'scout_apm/remote/recorder'
|
158
|
-
require 'scout_apm/instruments/resque'
|
159
|
-
|
160
154
|
if defined?(Rails) && defined?(Rails::VERSION) && defined?(Rails::VERSION::MAJOR) && Rails::VERSION::MAJOR >= 3 && defined?(Rails::Railtie)
|
161
155
|
module ScoutApm
|
162
156
|
class Railtie < Rails::Railtie
|
@@ -172,8 +166,6 @@ if defined?(Rails) && defined?(Rails::VERSION) && defined?(Rails::VERSION::MAJOR
|
|
172
166
|
end
|
173
167
|
class Railtie < Rails::Railtie
|
174
168
|
initializer 'scout_apm.start' do |app|
|
175
|
-
# Install the middleware every time in development mode.
|
176
|
-
# The middleware is a noop if dev_trace is not enabled in config
|
177
169
|
if Rails.env.development?
|
178
170
|
app.middleware.use ScoutApm::Instant::Middleware
|
179
171
|
end
|
data/lib/scout_apm/agent.rb
CHANGED
@@ -10,9 +10,9 @@ module ScoutApm
|
|
10
10
|
|
11
11
|
# Accessors below are for associated classes
|
12
12
|
attr_accessor :store
|
13
|
-
attr_reader :recorder
|
14
13
|
attr_accessor :layaway
|
15
14
|
attr_accessor :config
|
15
|
+
attr_accessor :capacity
|
16
16
|
attr_accessor :logger
|
17
17
|
attr_accessor :log_file # path to the log file
|
18
18
|
attr_accessor :options # options passed to the agent when +#start+ is called.
|
@@ -42,9 +42,6 @@ module ScoutApm
|
|
42
42
|
@process_start_time = Time.now
|
43
43
|
@options ||= options
|
44
44
|
|
45
|
-
# until the agent is started, there's no recorder
|
46
|
-
@recorder = nil
|
47
|
-
|
48
45
|
# Start up without attempting to load a configuration file. We need to be
|
49
46
|
# able to lookup configuration options like "application_root" which would
|
50
47
|
# then in turn influence where the configuration file came from.
|
@@ -58,10 +55,10 @@ module ScoutApm
|
|
58
55
|
@request_histograms_by_time = Hash.new { |h, k| h[k] = ScoutApm::RequestHistograms.new }
|
59
56
|
|
60
57
|
@store = ScoutApm::Store.new
|
61
|
-
|
62
|
-
@layaway = ScoutApm::Layaway.new(config, environment)
|
58
|
+
@layaway = ScoutApm::Layaway.new
|
63
59
|
@metric_lookup = Hash.new
|
64
60
|
|
61
|
+
@capacity = ScoutApm::Capacity.new
|
65
62
|
@installed_instruments = []
|
66
63
|
end
|
67
64
|
|
@@ -89,11 +86,6 @@ module ScoutApm
|
|
89
86
|
return false unless force?
|
90
87
|
end
|
91
88
|
|
92
|
-
if environment.interactive?
|
93
|
-
logger.warn "Agent attempting to load in interactive mode. #{force? ? 'Forcing agent to start' : 'Not starting agent'}"
|
94
|
-
return false unless force?
|
95
|
-
end
|
96
|
-
|
97
89
|
if app_server_missing?(options) && background_job_missing?
|
98
90
|
if force?
|
99
91
|
logger.warn "Agent starting (forced)"
|
@@ -120,34 +112,26 @@ module ScoutApm
|
|
120
112
|
# It initializes the agent and starts the worker thread (if appropiate).
|
121
113
|
def start(options = {})
|
122
114
|
@options.merge!(options)
|
123
|
-
|
124
115
|
@config = ScoutApm::Config.with_file(@config.value("config_file"))
|
125
|
-
layaway.config = config
|
126
|
-
|
127
116
|
init_logger
|
128
117
|
logger.info "Attempting to start Scout Agent [#{ScoutApm::VERSION}] on [#{environment.hostname}]"
|
129
118
|
|
130
|
-
@recorder = create_recorder
|
131
|
-
|
132
|
-
@config.log_settings
|
133
|
-
|
134
119
|
@ignored_uris = ScoutApm::IgnoredUris.new(config.value('ignore'))
|
135
120
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
logger.info("No configuration file loaded, and no configuration found in ENV. " +
|
140
|
-
"For assistance configuring Scout, visit " +
|
141
|
-
"http://help.apm.scoutapp.com/#configuration-options")
|
121
|
+
if environment.deploy_integration
|
122
|
+
logger.info "Starting monitoring for [#{environment.deploy_integration.name}]]."
|
123
|
+
return environment.deploy_integration.install
|
142
124
|
end
|
143
125
|
|
126
|
+
load_instruments if should_load_instruments?(options)
|
127
|
+
|
144
128
|
return false unless preconditions_met?(options)
|
145
129
|
@started = true
|
146
130
|
logger.info "Starting monitoring for [#{environment.application_name}]. Framework [#{environment.framework}] App Server [#{environment.app_server}] Background Job Framework [#{environment.background_job_name}]."
|
147
131
|
|
148
132
|
[ ScoutApm::Instruments::Process::ProcessCpu.new(environment.processors, logger),
|
149
133
|
ScoutApm::Instruments::Process::ProcessMemory.new(logger),
|
150
|
-
ScoutApm::Instruments::PercentileSampler.new(logger,
|
134
|
+
ScoutApm::Instruments::PercentileSampler.new(logger, 95),
|
151
135
|
].each { |s| store.add_sampler(s) }
|
152
136
|
|
153
137
|
app_server_load_hook
|
@@ -215,21 +199,20 @@ module ScoutApm
|
|
215
199
|
# It does not attempt to actually report metrics.
|
216
200
|
def shutdown
|
217
201
|
logger.info "Shutting down ScoutApm"
|
218
|
-
|
219
202
|
return if !started?
|
220
203
|
|
221
|
-
return if @shutdown
|
222
|
-
@shutdown = true
|
223
|
-
|
224
204
|
if @background_worker
|
225
205
|
logger.info("Stopping background worker")
|
226
206
|
@background_worker.stop
|
227
207
|
store.write_to_layaway(layaway, :force)
|
228
|
-
if @background_worker_thread.alive?
|
229
|
-
@background_worker_thread.wakeup
|
230
|
-
@background_worker_thread.join
|
231
|
-
end
|
232
208
|
end
|
209
|
+
|
210
|
+
logger.debug "Joining background worker thread"
|
211
|
+
if @background_worker_thread
|
212
|
+
@background_worker_thread.wakeup
|
213
|
+
@background_worker_thread.join
|
214
|
+
end
|
215
|
+
ScoutApm::Instruments::Stacks.uninstall
|
233
216
|
end
|
234
217
|
|
235
218
|
def started?
|
@@ -248,10 +231,7 @@ module ScoutApm
|
|
248
231
|
end
|
249
232
|
|
250
233
|
def background_worker_running?
|
251
|
-
@background_worker_thread
|
252
|
-
@background_worker_thread.alive? &&
|
253
|
-
@background_worker &&
|
254
|
-
@background_worker.running?
|
234
|
+
!! @background_worker_thread
|
255
235
|
end
|
256
236
|
|
257
237
|
# Creates the worker thread. The worker thread is a loop that runs continuously. It sleeps for +Agent#period+ and when it wakes,
|
@@ -266,13 +246,15 @@ module ScoutApm
|
|
266
246
|
|
267
247
|
install_exit_handler
|
268
248
|
|
269
|
-
|
270
|
-
|
249
|
+
if ScoutApm::Agent.instance.config.value('profile')
|
250
|
+
# After we fork, setup the handlers here.
|
251
|
+
ScoutApm::Instruments::Stacks.install
|
252
|
+
ScoutApm::Instruments::Stacks.start
|
253
|
+
end
|
271
254
|
|
272
255
|
@background_worker = ScoutApm::BackgroundWorker.new
|
273
256
|
@background_worker_thread = Thread.new do
|
274
257
|
@background_worker.start {
|
275
|
-
ScoutApm::Debug.instance.call_periodic_hooks
|
276
258
|
ScoutApm::Agent.instance.process_metrics
|
277
259
|
clean_old_percentiles
|
278
260
|
}
|
@@ -296,21 +278,22 @@ module ScoutApm
|
|
296
278
|
|
297
279
|
# Loads the instrumention logic.
|
298
280
|
def load_instruments
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
281
|
+
if !background_job_missing?
|
282
|
+
case environment.background_job_name
|
283
|
+
when :delayed_job
|
284
|
+
install_instrument(ScoutApm::Instruments::DelayedJob)
|
285
|
+
end
|
286
|
+
else
|
287
|
+
case environment.framework
|
288
|
+
when :rails then install_instrument(ScoutApm::Instruments::ActionControllerRails2)
|
289
|
+
when :rails3_or_4 then
|
290
|
+
install_instrument(ScoutApm::Instruments::ActionControllerRails3Rails4)
|
309
291
|
install_instrument(ScoutApm::Instruments::MiddlewareSummary)
|
292
|
+
install_instrument(ScoutApm::Instruments::RailsRouter)
|
293
|
+
# when :sinatra then install_instrument(ScoutApm::Instruments::Sinatra)
|
310
294
|
end
|
311
295
|
end
|
312
296
|
|
313
|
-
install_instrument(ScoutApm::Instruments::ActionView)
|
314
297
|
install_instrument(ScoutApm::Instruments::ActiveRecord)
|
315
298
|
install_instrument(ScoutApm::Instruments::Moped)
|
316
299
|
install_instrument(ScoutApm::Instruments::Mongoid)
|
@@ -342,6 +325,10 @@ module ScoutApm
|
|
342
325
|
instance.install
|
343
326
|
end
|
344
327
|
|
328
|
+
def deploy_integration
|
329
|
+
environment.deploy_integration
|
330
|
+
end
|
331
|
+
|
345
332
|
def app_server_missing?(options = {})
|
346
333
|
!environment.app_server_integration(true).found? && !options[:skip_app_server_check]
|
347
334
|
end
|
@@ -349,47 +336,5 @@ module ScoutApm
|
|
349
336
|
def background_job_missing?(options = {})
|
350
337
|
environment.background_job_integration.nil? && !options[:skip_background_job_check]
|
351
338
|
end
|
352
|
-
|
353
|
-
def clear_recorder
|
354
|
-
@recorder = nil
|
355
|
-
end
|
356
|
-
|
357
|
-
def create_recorder
|
358
|
-
if @recorder
|
359
|
-
return @recorder
|
360
|
-
end
|
361
|
-
|
362
|
-
if config.value("async_recording")
|
363
|
-
logger.debug("Using asynchronous recording")
|
364
|
-
ScoutApm::BackgroundRecorder.new(logger).start
|
365
|
-
else
|
366
|
-
logger.debug("Using synchronous recording")
|
367
|
-
ScoutApm::SynchronousRecorder.new(logger).start
|
368
|
-
end
|
369
|
-
end
|
370
|
-
|
371
|
-
def start_remote_server(bind, port)
|
372
|
-
return if @remote_server && @remote_server.running?
|
373
|
-
|
374
|
-
logger.info("Starting Remote Agent Server")
|
375
|
-
|
376
|
-
# Start the listening web server only in parent process.
|
377
|
-
@remote_server = ScoutApm::Remote::Server.new(
|
378
|
-
bind,
|
379
|
-
port,
|
380
|
-
ScoutApm::Remote::Router.new(ScoutApm::SynchronousRecorder.new(logger), logger),
|
381
|
-
logger
|
382
|
-
)
|
383
|
-
|
384
|
-
@remote_server.start
|
385
|
-
end
|
386
|
-
|
387
|
-
# Execute this in the child process of a remote agent. The parent is
|
388
|
-
# expected to have its accepting webserver up and running
|
389
|
-
def use_remote_recorder(host, port)
|
390
|
-
logger.debug("Becoming Remote Agent (reporting to: #{host}:#{port})")
|
391
|
-
@recorder = ScoutApm::Remote::Recorder.new(host, port, logger)
|
392
|
-
@store = ScoutApm::FakeStore.new
|
393
|
-
end
|
394
339
|
end
|
395
340
|
end
|
@@ -24,7 +24,7 @@ module ScoutApm
|
|
24
24
|
report_to_server
|
25
25
|
end
|
26
26
|
|
27
|
-
# In a running app, one process will get
|
27
|
+
# In a running app, one process will get one period ready for delivery, the others will see 0.
|
28
28
|
def report_to_server
|
29
29
|
period_to_report = ScoutApm::StoreReportingPeriodTimestamp.minutes_ago(2)
|
30
30
|
|
@@ -58,7 +58,6 @@ module ScoutApm
|
|
58
58
|
slow_transactions = reporting_period.slow_transactions_payload
|
59
59
|
jobs = reporting_period.jobs
|
60
60
|
slow_jobs = reporting_period.slow_jobs_payload
|
61
|
-
histograms = reporting_period.histograms
|
62
61
|
|
63
62
|
metadata = {
|
64
63
|
:app_root => ScoutApm::Environment.instance.root.to_s,
|
@@ -69,10 +68,10 @@ module ScoutApm
|
|
69
68
|
:platform => "ruby",
|
70
69
|
}
|
71
70
|
|
72
|
-
log_deliver(metrics, slow_transactions, metadata, slow_jobs
|
71
|
+
log_deliver(metrics, slow_transactions, metadata, slow_jobs)
|
73
72
|
|
74
|
-
payload = ScoutApm::Serializers::PayloadSerializer.serialize(metadata, metrics, slow_transactions, jobs, slow_jobs
|
75
|
-
logger.debug("
|
73
|
+
payload = ScoutApm::Serializers::PayloadSerializer.serialize(metadata, metrics, slow_transactions, jobs, slow_jobs)
|
74
|
+
# logger.debug("Payload: #{payload}")
|
76
75
|
|
77
76
|
reporter.report(payload, headers)
|
78
77
|
rescue => e
|
@@ -81,7 +80,7 @@ module ScoutApm
|
|
81
80
|
logger.debug e.backtrace
|
82
81
|
end
|
83
82
|
|
84
|
-
def log_deliver(metrics, slow_transactions, metadata, jobs_traces
|
83
|
+
def log_deliver(metrics, slow_transactions, metadata, jobs_traces)
|
85
84
|
total_request_count = metrics.
|
86
85
|
select { |meta,stats| meta.metric_name =~ /\AController/ }.
|
87
86
|
inject(0) {|sum, (_, stat)| sum + stat.call_count }
|
@@ -98,10 +97,9 @@ module ScoutApm
|
|
98
97
|
metrics_clause = "#{metrics.length} Metrics for #{total_request_count} requests"
|
99
98
|
slow_trans_clause = "#{slow_transactions.length} Slow Transaction Traces"
|
100
99
|
job_clause = "#{jobs_traces.length} Job Traces"
|
101
|
-
histogram_clause = "#{histograms.length} Histograms"
|
102
100
|
|
103
101
|
logger.info "#{time_clause} Delivering #{metrics_clause} and #{slow_trans_clause} and #{job_clause}, #{process_log_str}."
|
104
|
-
logger.debug("
|
102
|
+
# logger.debug("Metrics: #{metrics.pretty_inspect}\nSlowTrans: #{slow_transactions.pretty_inspect}\nMetadata: #{metadata.inspect.pretty_inspect}")
|
105
103
|
end
|
106
104
|
|
107
105
|
# TODO: Move this into PayloadSerializer?
|
@@ -27,30 +27,19 @@ module ScoutApm
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def data
|
30
|
-
{ :server_time =>
|
31
|
-
:framework =>
|
32
|
-
:framework_version =>
|
33
|
-
:environment =>
|
34
|
-
:app_server =>
|
30
|
+
{ :server_time => Time.now,
|
31
|
+
:framework => ScoutApm::Environment.instance.framework_integration.human_name,
|
32
|
+
:framework_version => ScoutApm::Environment.instance.framework_integration.version,
|
33
|
+
:environment => ScoutApm::Environment.instance.framework_integration.env,
|
34
|
+
:app_server => ScoutApm::Environment.instance.app_server,
|
35
35
|
:ruby_version => RUBY_VERSION,
|
36
|
-
:hostname =>
|
37
|
-
:database_engine =>
|
38
|
-
:database_adapter =>
|
39
|
-
:application_name =>
|
36
|
+
:hostname => ScoutApm::Environment.instance.hostname,
|
37
|
+
:database_engine => ScoutApm::Environment.instance.database_engine, # Detected
|
38
|
+
:database_adapter => ScoutApm::Environment.instance.raw_database_adapter, # Raw
|
39
|
+
:application_name => ScoutApm::Environment.instance.application_name,
|
40
40
|
:libraries => ScoutApm::Utils::InstalledGems.new.run,
|
41
|
-
:paas =>
|
42
|
-
:git_sha => to_s_safe(ScoutApm::Environment.instance.git_revision.sha)
|
41
|
+
:paas => ScoutApm::Environment.instance.platform_integration.name
|
43
42
|
}
|
44
43
|
end
|
45
|
-
|
46
|
-
# Calls `.to_s` on the object passed in.
|
47
|
-
# Returns literal string 'to_s error' if the object does not respond to .to_s
|
48
|
-
def to_s_safe(obj)
|
49
|
-
if obj.respond_to?(:to_s)
|
50
|
-
obj.to_s
|
51
|
-
else
|
52
|
-
'to_s error'
|
53
|
-
end
|
54
|
-
end
|
55
44
|
end
|
56
45
|
end
|