appsignal 3.4.0 → 3.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +63 -21
- data/.rubocop_todo.yml +68 -54
- data/.semaphore/semaphore.yml +11 -11
- data/CHANGELOG.md +37 -0
- data/Rakefile +15 -99
- data/appsignal.gemspec +3 -4
- data/bin/appsignal +4 -2
- data/build_matrix.yml +4 -4
- data/ext/._appsignal-agent +0 -0
- data/ext/Rakefile +22 -21
- data/ext/agent.rb +2 -0
- data/ext/base.rb +14 -17
- data/ext/extconf.rb +4 -1
- data/lib/appsignal/auth_check.rb +3 -3
- data/lib/appsignal/capistrano.rb +1 -1
- data/lib/appsignal/cli/demo.rb +5 -2
- data/lib/appsignal/cli/diagnose/paths.rb +4 -1
- data/lib/appsignal/cli/diagnose/utils.rb +7 -3
- data/lib/appsignal/cli/diagnose.rb +7 -5
- data/lib/appsignal/cli/helpers.rb +1 -4
- data/lib/appsignal/cli/install.rb +4 -10
- data/lib/appsignal/cli.rb +3 -2
- data/lib/appsignal/config.rb +105 -102
- data/lib/appsignal/demo.rb +2 -1
- data/lib/appsignal/environment.rb +2 -0
- data/lib/appsignal/event_formatter/action_view/render_formatter.rb +2 -1
- data/lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter.rb +13 -13
- data/lib/appsignal/event_formatter.rb +5 -4
- data/lib/appsignal/extension/jruby.rb +11 -9
- data/lib/appsignal/extension.rb +1 -1
- data/lib/appsignal/helpers/instrumentation.rb +50 -35
- data/lib/appsignal/hooks/action_cable.rb +6 -4
- data/lib/appsignal/hooks/action_mailer.rb +2 -0
- data/lib/appsignal/hooks/active_job.rb +11 -10
- data/lib/appsignal/hooks/active_support_notifications.rb +3 -4
- data/lib/appsignal/hooks/data_mapper.rb +1 -1
- data/lib/appsignal/hooks/gvl.rb +3 -0
- data/lib/appsignal/hooks/http.rb +1 -1
- data/lib/appsignal/hooks/mri.rb +2 -0
- data/lib/appsignal/hooks/net_http.rb +1 -1
- data/lib/appsignal/hooks/que.rb +1 -1
- data/lib/appsignal/hooks/rake.rb +1 -1
- data/lib/appsignal/hooks/redis.rb +1 -1
- data/lib/appsignal/hooks/resque.rb +1 -1
- data/lib/appsignal/hooks/shoryuken.rb +2 -4
- data/lib/appsignal/hooks/sidekiq.rb +1 -1
- data/lib/appsignal/hooks/unicorn.rb +2 -2
- data/lib/appsignal/hooks/webmachine.rb +1 -1
- data/lib/appsignal/hooks.rb +2 -2
- data/lib/appsignal/integrations/active_support_notifications.rb +1 -1
- data/lib/appsignal/integrations/capistrano/appsignal.cap +6 -3
- data/lib/appsignal/integrations/capistrano/capistrano_2_tasks.rb +5 -4
- data/lib/appsignal/integrations/delayed_job_plugin.rb +3 -5
- data/lib/appsignal/integrations/grape.rb +1 -1
- data/lib/appsignal/integrations/hanami.rb +1 -1
- data/lib/appsignal/integrations/object.rb +2 -3
- data/lib/appsignal/integrations/padrino.rb +2 -4
- data/lib/appsignal/integrations/que.rb +6 -6
- data/lib/appsignal/integrations/railtie.rb +72 -0
- data/lib/appsignal/integrations/sidekiq.rb +9 -11
- data/lib/appsignal/integrations/sinatra.rb +1 -3
- data/lib/appsignal/integrations/webmachine.rb +4 -6
- data/lib/appsignal/logger.rb +31 -6
- data/lib/appsignal/marker.rb +4 -5
- data/lib/appsignal/minutely.rb +7 -7
- data/lib/appsignal/probes/gvl.rb +9 -4
- data/lib/appsignal/probes/helpers.rb +4 -6
- data/lib/appsignal/probes/mri.rb +7 -5
- data/lib/appsignal/probes/sidekiq.rb +3 -0
- data/lib/appsignal/probes.rb +2 -0
- data/lib/appsignal/rack/generic_instrumentation.rb +1 -5
- data/lib/appsignal/rack/sinatra_instrumentation.rb +3 -5
- data/lib/appsignal/rack/streaming_listener.rb +11 -13
- data/lib/appsignal/span.rb +5 -5
- data/lib/appsignal/system.rb +10 -11
- data/lib/appsignal/transaction.rb +49 -25
- data/lib/appsignal/transmitter.rb +4 -2
- data/lib/appsignal/utils/deprecation_message.rb +2 -0
- data/lib/appsignal/utils/hash_sanitizer.rb +1 -1
- data/lib/appsignal/utils/integration_logger.rb +5 -3
- data/lib/appsignal/utils/json.rb +1 -1
- data/lib/appsignal/utils/query_params_sanitizer.rb +1 -1
- data/lib/appsignal/version.rb +1 -1
- data/lib/appsignal.rb +5 -4
- data/lib/puma/plugin/appsignal.rb +16 -18
- data/script/lint_git +1 -1
- data/spec/lib/appsignal/capistrano2_spec.rb +6 -3
- data/spec/lib/appsignal/capistrano3_spec.rb +6 -3
- data/spec/lib/appsignal/cli/diagnose/utils_spec.rb +1 -3
- data/spec/lib/appsignal/cli/diagnose_spec.rb +33 -30
- data/spec/lib/appsignal/cli/install_spec.rb +5 -6
- data/spec/lib/appsignal/cli_spec.rb +1 -1
- data/spec/lib/appsignal/config_spec.rb +43 -37
- data/spec/lib/appsignal/event_formatter/action_view/render_formatter_spec.rb +11 -5
- data/spec/lib/appsignal/event_formatter/elastic_search/search_formatter_spec.rb +4 -4
- data/spec/lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter_spec.rb +1 -4
- data/spec/lib/appsignal/event_formatter_spec.rb +11 -9
- data/spec/lib/appsignal/hooks/action_cable_spec.rb +5 -2
- data/spec/lib/appsignal/hooks/action_mailer_spec.rb +2 -1
- data/spec/lib/appsignal/hooks/active_support_notifications/instrument_shared_examples.rb +1 -1
- data/spec/lib/appsignal/hooks/active_support_notifications/start_finish_shared_examples.rb +1 -1
- data/spec/lib/appsignal/hooks/activejob_spec.rb +21 -12
- data/spec/lib/appsignal/hooks/data_mapper_spec.rb +1 -0
- data/spec/lib/appsignal/hooks/delayed_job_spec.rb +12 -12
- data/spec/lib/appsignal/hooks/excon_spec.rb +2 -2
- data/spec/lib/appsignal/hooks/mongo_ruby_driver_spec.rb +3 -1
- data/spec/lib/appsignal/hooks/shoryuken_spec.rb +4 -2
- data/spec/lib/appsignal/hooks/sidekiq_spec.rb +2 -1
- data/spec/lib/appsignal/hooks_spec.rb +5 -4
- data/spec/lib/appsignal/integrations/grape_spec.rb +8 -4
- data/spec/lib/appsignal/integrations/hanami_spec.rb +16 -8
- data/spec/lib/appsignal/integrations/mongo_ruby_driver_spec.rb +2 -4
- data/spec/lib/appsignal/integrations/object_spec.rb +6 -1
- data/spec/lib/appsignal/integrations/padrino_spec.rb +4 -2
- data/spec/lib/appsignal/integrations/railtie_spec.rb +213 -6
- data/spec/lib/appsignal/integrations/sidekiq_spec.rb +54 -41
- data/spec/lib/appsignal/logger_spec.rb +20 -4
- data/spec/lib/appsignal/marker_spec.rb +2 -2
- data/spec/lib/appsignal/minutely_spec.rb +3 -3
- data/spec/lib/appsignal/probes/gvl_spec.rb +60 -12
- data/spec/lib/appsignal/probes/mri_spec.rb +7 -4
- data/spec/lib/appsignal/rack/generic_instrumentation_spec.rb +2 -1
- data/spec/lib/appsignal/rack/rails_instrumentation_spec.rb +2 -1
- data/spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb +10 -5
- data/spec/lib/appsignal/rack/streaming_listener_spec.rb +7 -5
- data/spec/lib/appsignal/transaction_spec.rb +20 -13
- data/spec/lib/appsignal/utils/data_spec.rb +10 -1
- data/spec/lib/appsignal/utils/hash_sanitizer_spec.rb +11 -11
- data/spec/lib/appsignal/utils/json_spec.rb +4 -2
- data/spec/lib/appsignal_spec.rb +49 -35
- data/spec/lib/puma/appsignal_spec.rb +9 -11
- data/spec/spec_helper.rb +14 -2
- data/spec/support/fixtures/projects/valid/config/appsignal.yml +1 -1
- data/spec/support/helpers/config_helpers.rb +2 -1
- data/spec/support/helpers/dependency_helper.rb +1 -9
- data/spec/support/helpers/std_streams_helper.rb +1 -3
- data/spec/support/helpers/wait_for_helper.rb +2 -3
- data/spec/support/mocks/appsignal_mock.rb +1 -1
- data/spec/support/mocks/fake_gvl_tools.rb +2 -10
- data/spec/support/testing.rb +4 -3
- metadata +9 -135
@@ -4,11 +4,11 @@ require "json"
|
|
4
4
|
|
5
5
|
module Appsignal
|
6
6
|
class Transaction
|
7
|
-
HTTP_REQUEST = "http_request"
|
8
|
-
BACKGROUND_JOB = "background_job"
|
9
|
-
ACTION_CABLE = "action_cable"
|
10
|
-
FRONTEND = "frontend"
|
11
|
-
BLANK = ""
|
7
|
+
HTTP_REQUEST = "http_request"
|
8
|
+
BACKGROUND_JOB = "background_job"
|
9
|
+
ACTION_CABLE = "action_cable"
|
10
|
+
FRONTEND = "frontend"
|
11
|
+
BLANK = ""
|
12
12
|
ALLOWED_TAG_KEY_TYPES = [Symbol, String].freeze
|
13
13
|
ALLOWED_TAG_VALUE_TYPES = [Symbol, String, Integer].freeze
|
14
14
|
BREADCRUMB_LIMIT = 20
|
@@ -16,19 +16,21 @@ module Appsignal
|
|
16
16
|
class << self
|
17
17
|
def create(id, namespace, request, options = {})
|
18
18
|
# Allow middleware to force a new transaction
|
19
|
-
if options.include?(:force) && options[:force]
|
20
|
-
Thread.current[:appsignal_transaction] = nil
|
21
|
-
end
|
19
|
+
Thread.current[:appsignal_transaction] = nil if options.include?(:force) && options[:force]
|
22
20
|
|
23
21
|
# Check if we already have a running transaction
|
24
22
|
if Thread.current[:appsignal_transaction].nil?
|
25
23
|
# If not, start a new transaction
|
26
|
-
Thread.current[:appsignal_transaction] =
|
24
|
+
Thread.current[:appsignal_transaction] =
|
25
|
+
Appsignal::Transaction.new(id, namespace, request, options)
|
27
26
|
else
|
28
27
|
# Otherwise, log the issue about trying to start another transaction
|
29
|
-
Appsignal.logger.warn_once_then_debug
|
30
|
-
|
31
|
-
"
|
28
|
+
Appsignal.logger.warn_once_then_debug(
|
29
|
+
:transaction_id,
|
30
|
+
"Trying to start new transaction with id " \
|
31
|
+
"'#{id}', but a transaction with id '#{current.transaction_id}' " \
|
32
|
+
"is already running. Using transaction '#{current.transaction_id}'."
|
33
|
+
)
|
32
34
|
|
33
35
|
# And return the current transaction instead
|
34
36
|
current
|
@@ -56,7 +58,9 @@ module Appsignal
|
|
56
58
|
def complete_current!
|
57
59
|
current.complete
|
58
60
|
rescue => e
|
59
|
-
Appsignal.logger.error(
|
61
|
+
Appsignal.logger.error(
|
62
|
+
"Failed to complete transaction ##{current.transaction_id}. #{e.message}"
|
63
|
+
)
|
60
64
|
ensure
|
61
65
|
clear_current_transaction!
|
62
66
|
end
|
@@ -68,7 +72,8 @@ module Appsignal
|
|
68
72
|
end
|
69
73
|
end
|
70
74
|
|
71
|
-
attr_reader :ext, :transaction_id, :action, :namespace, :request, :paused, :tags, :options,
|
75
|
+
attr_reader :ext, :transaction_id, :action, :namespace, :request, :paused, :tags, :options,
|
76
|
+
:discarded, :breadcrumbs
|
72
77
|
|
73
78
|
# @!attribute params
|
74
79
|
# Attribute for parameters of the transaction.
|
@@ -146,6 +151,7 @@ module Appsignal
|
|
146
151
|
|
147
152
|
def params
|
148
153
|
return @params if defined?(@params)
|
154
|
+
|
149
155
|
request_params
|
150
156
|
end
|
151
157
|
|
@@ -202,6 +208,7 @@ module Appsignal
|
|
202
208
|
# @since 2.2.0
|
203
209
|
def set_action(action)
|
204
210
|
return unless action
|
211
|
+
|
205
212
|
@action = action
|
206
213
|
@ext.set_action(action)
|
207
214
|
end
|
@@ -222,6 +229,7 @@ module Appsignal
|
|
222
229
|
# @since 2.2.0
|
223
230
|
def set_action_if_nil(action)
|
224
231
|
return if @action
|
232
|
+
|
225
233
|
set_action(action)
|
226
234
|
end
|
227
235
|
|
@@ -242,12 +250,14 @@ module Appsignal
|
|
242
250
|
# @since 2.2.0
|
243
251
|
def set_namespace(namespace)
|
244
252
|
return unless namespace
|
253
|
+
|
245
254
|
@namespace = namespace
|
246
255
|
@ext.set_namespace(namespace)
|
247
256
|
end
|
248
257
|
|
249
258
|
def set_http_or_background_action(from = request.params)
|
250
259
|
return unless from
|
260
|
+
|
251
261
|
group_and_action = [
|
252
262
|
from[:controller] || from[:class],
|
253
263
|
from[:action] || from[:method]
|
@@ -267,6 +277,7 @@ module Appsignal
|
|
267
277
|
# @return [void]
|
268
278
|
def set_queue_start(start)
|
269
279
|
return unless start
|
280
|
+
|
270
281
|
@ext.set_queue_start(start)
|
271
282
|
rescue RangeError
|
272
283
|
Appsignal.logger.warn("Queue start value #{start} is too big")
|
@@ -297,11 +308,13 @@ module Appsignal
|
|
297
308
|
|
298
309
|
def set_metadata(key, value)
|
299
310
|
return unless key && value
|
311
|
+
|
300
312
|
@ext.set_metadata(key, value)
|
301
313
|
end
|
302
314
|
|
303
315
|
def set_sample_data(key, data)
|
304
316
|
return unless key && data && (data.is_a?(Array) || data.is_a?(Hash))
|
317
|
+
|
305
318
|
@ext.set_sample_data(
|
306
319
|
key.to_s,
|
307
320
|
Appsignal::Utils::Data.generate(data)
|
@@ -309,20 +322,24 @@ module Appsignal
|
|
309
322
|
rescue RuntimeError => e
|
310
323
|
begin
|
311
324
|
inspected_data = data.inspect
|
312
|
-
Appsignal.logger.error(
|
325
|
+
Appsignal.logger.error(
|
326
|
+
"Error generating data (#{e.class}: #{e.message}) for '#{inspected_data}'"
|
327
|
+
)
|
313
328
|
rescue => e
|
314
|
-
Appsignal.logger.error(
|
329
|
+
Appsignal.logger.error(
|
330
|
+
"Error generating data (#{e.class}: #{e.message}). Can't inspect data."
|
331
|
+
)
|
315
332
|
end
|
316
333
|
end
|
317
334
|
|
318
335
|
def sample_data
|
319
336
|
{
|
320
|
-
:params
|
321
|
-
:environment
|
337
|
+
:params => sanitized_params,
|
338
|
+
:environment => sanitized_environment,
|
322
339
|
:session_data => sanitized_session_data,
|
323
|
-
:metadata
|
324
|
-
:tags
|
325
|
-
:breadcrumbs
|
340
|
+
:metadata => metadata,
|
341
|
+
:tags => sanitized_tags,
|
342
|
+
:breadcrumbs => breadcrumbs
|
326
343
|
}.each do |key, data|
|
327
344
|
set_sample_data(key, data)
|
328
345
|
end
|
@@ -348,11 +365,13 @@ module Appsignal
|
|
348
365
|
|
349
366
|
def start_event
|
350
367
|
return if paused?
|
368
|
+
|
351
369
|
@ext.start_event(0)
|
352
370
|
end
|
353
371
|
|
354
372
|
def finish_event(name, title, body, body_format = Appsignal::EventFormatter::DEFAULT)
|
355
373
|
return if paused?
|
374
|
+
|
356
375
|
@ext.finish_event(
|
357
376
|
name,
|
358
377
|
title || BLANK,
|
@@ -364,6 +383,7 @@ module Appsignal
|
|
364
383
|
|
365
384
|
def record_event(name, title, body, duration, body_format = Appsignal::EventFormatter::DEFAULT)
|
366
385
|
return if paused?
|
386
|
+
|
367
387
|
@ext.record_event(
|
368
388
|
name,
|
369
389
|
title || BLANK,
|
@@ -410,6 +430,7 @@ module Appsignal
|
|
410
430
|
def background_queue_start
|
411
431
|
env = environment
|
412
432
|
return unless env
|
433
|
+
|
413
434
|
queue_start = env[:queue_start]
|
414
435
|
return unless queue_start
|
415
436
|
|
@@ -424,9 +445,11 @@ module Appsignal
|
|
424
445
|
def http_queue_start
|
425
446
|
env = environment
|
426
447
|
return unless env
|
427
|
-
|
448
|
+
|
449
|
+
env_var = env["HTTP_X_QUEUE_START"] || env["HTTP_X_REQUEST_START"]
|
428
450
|
return unless env_var
|
429
|
-
|
451
|
+
|
452
|
+
cleaned_value = env_var.tr("^0-9", "")
|
430
453
|
return if cleaned_value.empty?
|
431
454
|
|
432
455
|
value = cleaned_value.to_i
|
@@ -489,7 +512,8 @@ module Appsignal
|
|
489
512
|
# @return [Hash<String, Object>]
|
490
513
|
def sanitized_session_data
|
491
514
|
return if !Appsignal.config[:send_session_data] ||
|
492
|
-
|
515
|
+
!request.respond_to?(:session)
|
516
|
+
|
493
517
|
session = request.session
|
494
518
|
return unless session
|
495
519
|
|
@@ -555,7 +579,7 @@ module Appsignal
|
|
555
579
|
# transaction, so that it's still safe to call methods on it if there is no
|
556
580
|
# current transaction.
|
557
581
|
class NilTransaction
|
558
|
-
def method_missing(
|
582
|
+
def method_missing(_method, *args, &block)
|
559
583
|
end
|
560
584
|
|
561
585
|
# Instrument should still yield
|
@@ -9,7 +9,7 @@ require "json"
|
|
9
9
|
module Appsignal
|
10
10
|
# @api private
|
11
11
|
class Transmitter
|
12
|
-
CONTENT_TYPE = "application/json; charset=UTF-8"
|
12
|
+
CONTENT_TYPE = "application/json; charset=UTF-8"
|
13
13
|
|
14
14
|
HTTP_ERRORS = [
|
15
15
|
EOFError,
|
@@ -84,7 +84,7 @@ module Appsignal
|
|
84
84
|
if ca_file && File.exist?(ca_file) && File.readable?(ca_file)
|
85
85
|
http.ca_file = ca_file
|
86
86
|
else
|
87
|
-
config.logger.warn "Ignoring non-existing or unreadable "\
|
87
|
+
config.logger.warn "Ignoring non-existing or unreadable " \
|
88
88
|
"`ca_file_path`: #{ca_file}"
|
89
89
|
end
|
90
90
|
end
|
@@ -97,11 +97,13 @@ module Appsignal
|
|
97
97
|
|
98
98
|
def proxy_addr
|
99
99
|
return unless config[:http_proxy]
|
100
|
+
|
100
101
|
proxy_uri.host
|
101
102
|
end
|
102
103
|
|
103
104
|
def proxy_port
|
104
105
|
return unless config[:http_proxy]
|
106
|
+
|
105
107
|
proxy_uri.port
|
106
108
|
end
|
107
109
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Appsignal
|
2
4
|
module Utils
|
3
5
|
# Subclass of logger with method to only log a warning once
|
@@ -8,10 +10,10 @@ module Appsignal
|
|
8
10
|
end
|
9
11
|
|
10
12
|
def warn_once_then_debug(key, message)
|
11
|
-
if
|
12
|
-
warn message
|
13
|
-
else
|
13
|
+
if seen_keys.add?(key).nil?
|
14
14
|
debug message
|
15
|
+
else
|
16
|
+
warn message
|
15
17
|
end
|
16
18
|
end
|
17
19
|
end
|
data/lib/appsignal/utils/json.rb
CHANGED
data/lib/appsignal/version.rb
CHANGED
data/lib/appsignal.rb
CHANGED
@@ -99,13 +99,13 @@ module Appsignal
|
|
99
99
|
|
100
100
|
@config ||= Config.new(
|
101
101
|
Dir.pwd,
|
102
|
-
ENV["APPSIGNAL_APP_ENV"] || ENV["RAILS_ENV"] || ENV
|
102
|
+
ENV["APPSIGNAL_APP_ENV"] || ENV["RAILS_ENV"] || ENV.fetch("RACK_ENV", nil)
|
103
103
|
)
|
104
104
|
|
105
105
|
if config.valid?
|
106
106
|
logger.level = config.log_level
|
107
107
|
if config.active?
|
108
|
-
logger.info "Starting AppSignal #{Appsignal::VERSION} "\
|
108
|
+
logger.info "Starting AppSignal #{Appsignal::VERSION} " \
|
109
109
|
"(#{$PROGRAM_NAME}, Ruby #{RUBY_VERSION}, #{RUBY_PLATFORM})"
|
110
110
|
config.write_to_environment
|
111
111
|
Appsignal::Extension.start
|
@@ -152,6 +152,7 @@ module Appsignal
|
|
152
152
|
|
153
153
|
def forked
|
154
154
|
return unless active?
|
155
|
+
|
155
156
|
Appsignal.start_logger
|
156
157
|
logger.debug("Forked process, resubscribing and restarting extension")
|
157
158
|
Appsignal::Extension.start
|
@@ -186,7 +187,7 @@ module Appsignal
|
|
186
187
|
def log_formatter(prefix = nil)
|
187
188
|
pre = "#{prefix}: " if prefix
|
188
189
|
proc do |severity, datetime, _progname, msg|
|
189
|
-
"[#{datetime.strftime("%Y-%m-%dT%H:%M:%S")} (process) "\
|
190
|
+
"[#{datetime.strftime("%Y-%m-%dT%H:%M:%S")} (process) " \
|
190
191
|
"##{Process.pid}][#{severity}] #{pre}#{msg}\n"
|
191
192
|
end
|
192
193
|
end
|
@@ -249,7 +250,7 @@ module Appsignal
|
|
249
250
|
# @return [Boolean]
|
250
251
|
# @since 0.2.7
|
251
252
|
def active?
|
252
|
-
config
|
253
|
+
config&.active? && extension_loaded?
|
253
254
|
end
|
254
255
|
|
255
256
|
private
|
@@ -17,23 +17,21 @@ Puma::Plugin.create do # rubocop:disable Metrics/BlockLength
|
|
17
17
|
plugin = AppsignalPumaPlugin.new
|
18
18
|
|
19
19
|
loop do
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
log_debug "AppSignal: No Puma stats to report."
|
33
|
-
end
|
34
|
-
rescue StandardError => error
|
35
|
-
log_error "Error while processing metrics.", error
|
20
|
+
# Implement similar behavior to minutely probes.
|
21
|
+
# Initial sleep to wait until the app is fully initalized.
|
22
|
+
# Then loop every 60 seconds and collect the Puma stats as AppSignal
|
23
|
+
# metrics.
|
24
|
+
sleep sleep_time
|
25
|
+
|
26
|
+
log_debug "AppSignal: Collecting Puma stats."
|
27
|
+
stats = fetch_puma_stats
|
28
|
+
if stats
|
29
|
+
plugin.call(stats)
|
30
|
+
else
|
31
|
+
log_debug "AppSignal: No Puma stats to report."
|
36
32
|
end
|
33
|
+
rescue StandardError => error
|
34
|
+
log_error "Error while processing metrics.", error
|
37
35
|
end
|
38
36
|
end
|
39
37
|
end
|
@@ -119,7 +117,7 @@ class AppsignalPumaPlugin
|
|
119
117
|
def fetch_hostname
|
120
118
|
# Configure hostname as reported for the Puma metrics with the
|
121
119
|
# APPSIGNAL_HOSTNAME environment variable.
|
122
|
-
env_hostname = ENV
|
120
|
+
env_hostname = ENV.fetch("APPSIGNAL_HOSTNAME", nil)
|
123
121
|
return env_hostname if env_hostname
|
124
122
|
|
125
123
|
# Auto detect hostname as fallback. May be inaccurate.
|
@@ -162,7 +160,7 @@ class AppsignalPumaPlugin
|
|
162
160
|
socket = UDPSocket.new
|
163
161
|
socket.send(data, 0, host, port)
|
164
162
|
ensure
|
165
|
-
socket
|
163
|
+
socket&.close
|
166
164
|
end
|
167
165
|
end
|
168
166
|
end
|
data/script/lint_git
CHANGED
@@ -148,7 +148,8 @@ if DependencyHelper.capistrano2_present?
|
|
148
148
|
run
|
149
149
|
|
150
150
|
expect(output).to include \
|
151
|
-
"Notifying AppSignal of deploy with: revision: 503ce0923ed177a3ce000005,
|
151
|
+
"Notifying AppSignal of deploy with: revision: 503ce0923ed177a3ce000005," \
|
152
|
+
" user: batman",
|
152
153
|
"AppSignal has been notified of this deploy!"
|
153
154
|
end
|
154
155
|
|
@@ -175,7 +176,8 @@ if DependencyHelper.capistrano2_present?
|
|
175
176
|
|
176
177
|
it "transmits the overriden deploy user" do
|
177
178
|
expect(output).to include \
|
178
|
-
"Notifying AppSignal of deploy with: revision: 503ce0923ed177a3ce000005,
|
179
|
+
"Notifying AppSignal of deploy with: revision: 503ce0923ed177a3ce000005," \
|
180
|
+
" user: robin",
|
179
181
|
"AppSignal has been notified of this deploy!"
|
180
182
|
end
|
181
183
|
end
|
@@ -188,7 +190,8 @@ if DependencyHelper.capistrano2_present?
|
|
188
190
|
|
189
191
|
it "does not transmit marker" do
|
190
192
|
expect(output).to include \
|
191
|
-
"Notifying AppSignal of deploy with: revision: 503ce0923ed177a3ce000005,
|
193
|
+
"Notifying AppSignal of deploy with: revision: 503ce0923ed177a3ce000005," \
|
194
|
+
" user: batman",
|
192
195
|
"Something went wrong while trying to notify AppSignal:"
|
193
196
|
expect(output).to_not include "AppSignal has been notified of this deploy!"
|
194
197
|
end
|
@@ -160,7 +160,8 @@ if DependencyHelper.capistrano3_present?
|
|
160
160
|
run
|
161
161
|
|
162
162
|
expect(output).to include \
|
163
|
-
"Notifying AppSignal of deploy with: revision: 503ce0923ed177a3ce000005,
|
163
|
+
"Notifying AppSignal of deploy with: revision: 503ce0923ed177a3ce000005, " \
|
164
|
+
"user: batman",
|
164
165
|
"AppSignal has been notified of this deploy!"
|
165
166
|
end
|
166
167
|
|
@@ -187,7 +188,8 @@ if DependencyHelper.capistrano3_present?
|
|
187
188
|
|
188
189
|
it "transmits the overriden deploy user" do
|
189
190
|
expect(output).to include \
|
190
|
-
"Notifying AppSignal of deploy with: revision: 503ce0923ed177a3ce000005,
|
191
|
+
"Notifying AppSignal of deploy with: revision: 503ce0923ed177a3ce000005, " \
|
192
|
+
"user: robin",
|
191
193
|
"AppSignal has been notified of this deploy!"
|
192
194
|
end
|
193
195
|
end
|
@@ -213,7 +215,8 @@ if DependencyHelper.capistrano3_present?
|
|
213
215
|
|
214
216
|
it "does not transmit marker" do
|
215
217
|
expect(output).to include \
|
216
|
-
"Notifying AppSignal of deploy with: revision: 503ce0923ed177a3ce000005,
|
218
|
+
"Notifying AppSignal of deploy with: revision: 503ce0923ed177a3ce000005, " \
|
219
|
+
"user: batman",
|
217
220
|
"Something went wrong while trying to notify AppSignal:"
|
218
221
|
expect(output).to_not include "AppSignal has been notified of this deploy!"
|
219
222
|
end
|
@@ -46,9 +46,7 @@ describe Appsignal::CLI::Diagnose::Utils do
|
|
46
46
|
let(:bytes_to_read) { 100 }
|
47
47
|
subject { described_class.read_file_content(path, bytes_to_read) }
|
48
48
|
before do
|
49
|
-
File.
|
50
|
-
f.write file_contents
|
51
|
-
end
|
49
|
+
File.write(path, file_contents)
|
52
50
|
end
|
53
51
|
|
54
52
|
context "when file is bigger than read size" do
|
@@ -2,7 +2,8 @@ require "bundler/cli"
|
|
2
2
|
require "bundler/cli/common"
|
3
3
|
require "appsignal/cli"
|
4
4
|
|
5
|
-
describe Appsignal::CLI::Diagnose, :api_stub => true, :send_report => :yes_cli_input,
|
5
|
+
describe Appsignal::CLI::Diagnose, :api_stub => true, :send_report => :yes_cli_input,
|
6
|
+
:color => false do
|
6
7
|
include CLIHelpers
|
7
8
|
|
8
9
|
class DiagnosticsReportEndpoint
|
@@ -268,7 +269,7 @@ describe Appsignal::CLI::Diagnose, :api_stub => true, :send_report => :yes_cli_i
|
|
268
269
|
},
|
269
270
|
"build" => {
|
270
271
|
"time" => kind_of(String),
|
271
|
-
"package_path" => File.expand_path("
|
272
|
+
"package_path" => File.expand_path("../../../..", __dir__),
|
272
273
|
"architecture" => Appsignal::System.agent_architecture,
|
273
274
|
"target" => Appsignal::System.agent_platform,
|
274
275
|
"musl_override" => false,
|
@@ -319,7 +320,7 @@ describe Appsignal::CLI::Diagnose, :api_stub => true, :send_report => :yes_cli_i
|
|
319
320
|
before do
|
320
321
|
allow(File).to receive(:read).and_call_original
|
321
322
|
expect(File).to receive(:read)
|
322
|
-
.with(File.expand_path("
|
323
|
+
.with(File.expand_path("../../../../ext/install.report", __dir__))
|
323
324
|
.and_return(
|
324
325
|
JSON.generate(
|
325
326
|
"result" => {
|
@@ -359,7 +360,7 @@ describe Appsignal::CLI::Diagnose, :api_stub => true, :send_report => :yes_cli_i
|
|
359
360
|
before do
|
360
361
|
allow(File).to receive(:read).and_call_original
|
361
362
|
expect(File).to receive(:read)
|
362
|
-
.with(File.expand_path("
|
363
|
+
.with(File.expand_path("../../../../ext/install.report", __dir__))
|
363
364
|
.and_raise(error)
|
364
365
|
end
|
365
366
|
|
@@ -389,7 +390,7 @@ describe Appsignal::CLI::Diagnose, :api_stub => true, :send_report => :yes_cli_i
|
|
389
390
|
before do
|
390
391
|
allow(File).to receive(:read).and_call_original
|
391
392
|
expect(File).to receive(:read)
|
392
|
-
.with(File.expand_path("
|
393
|
+
.with(File.expand_path("../../../../ext/install.report", __dir__))
|
393
394
|
.and_return(raw_report)
|
394
395
|
end
|
395
396
|
|
@@ -839,7 +840,7 @@ describe Appsignal::CLI::Diagnose, :api_stub => true, :send_report => :yes_cli_i
|
|
839
840
|
let(:options) { { :environment => "development" } }
|
840
841
|
before do
|
841
842
|
ENV["APPSIGNAL_APP_ENV"] = "production"
|
842
|
-
config.instance_variable_set(:@env, ENV
|
843
|
+
config.instance_variable_set(:@env, ENV.fetch("APPSIGNAL_APP_ENV", nil))
|
843
844
|
stub_api_request(config, "auth").to_return(:status => 200)
|
844
845
|
capture_diagnatics_report_request
|
845
846
|
run
|
@@ -847,10 +848,10 @@ describe Appsignal::CLI::Diagnose, :api_stub => true, :send_report => :yes_cli_i
|
|
847
848
|
|
848
849
|
it "outputs a list of sources with their values" do
|
849
850
|
expect(output).to include(
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
851
|
+
" environment: \"production\"\n" \
|
852
|
+
" Sources:\n" \
|
853
|
+
" initial: \"development\"\n" \
|
854
|
+
" env: \"production\"\n"
|
854
855
|
)
|
855
856
|
end
|
856
857
|
end
|
@@ -882,7 +883,7 @@ describe Appsignal::CLI::Diagnose, :api_stub => true, :send_report => :yes_cli_i
|
|
882
883
|
context "when the source is multiple sources" do
|
883
884
|
before do
|
884
885
|
ENV["APPSIGNAL_APP_NAME"] = "MyApp"
|
885
|
-
config[:name] = ENV
|
886
|
+
config[:name] = ENV.fetch("APPSIGNAL_APP_NAME", nil)
|
886
887
|
stub_api_request(config, "auth").to_return(:status => 200)
|
887
888
|
capture_diagnatics_report_request
|
888
889
|
run
|
@@ -891,20 +892,20 @@ describe Appsignal::CLI::Diagnose, :api_stub => true, :send_report => :yes_cli_i
|
|
891
892
|
if DependencyHelper.rails_present?
|
892
893
|
it "outputs a list of sources with their values" do
|
893
894
|
expect(output).to include(
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
895
|
+
" name: \"MyApp\"\n" \
|
896
|
+
" Sources:\n" \
|
897
|
+
" initial: \"MyApp\"\n" \
|
898
|
+
" file: \"TestApp\"\n" \
|
899
|
+
" env: \"MyApp\"\n"
|
899
900
|
)
|
900
901
|
end
|
901
902
|
else
|
902
903
|
it "outputs a list of sources with their values" do
|
903
904
|
expect(output).to include(
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
905
|
+
" name: \"MyApp\"\n" \
|
906
|
+
" Sources:\n" \
|
907
|
+
" file: \"TestApp\"\n" \
|
908
|
+
" env: \"MyApp\"\n"
|
908
909
|
)
|
909
910
|
end
|
910
911
|
end
|
@@ -928,7 +929,9 @@ describe Appsignal::CLI::Diagnose, :api_stub => true, :send_report => :yes_cli_i
|
|
928
929
|
"sources" => {
|
929
930
|
"default" => hash_with_string_keys(Appsignal::Config::DEFAULT_CONFIG),
|
930
931
|
"system" => {},
|
931
|
-
"initial" => hash_with_string_keys(
|
932
|
+
"initial" => hash_with_string_keys(
|
933
|
+
config.initial_config.merge(additional_initial_config)
|
934
|
+
),
|
932
935
|
"file" => hash_with_string_keys(config.file_config),
|
933
936
|
"env" => {},
|
934
937
|
"override" => { "send_session_data" => true }
|
@@ -1047,18 +1050,16 @@ describe Appsignal::CLI::Diagnose, :api_stub => true, :send_report => :yes_cli_i
|
|
1047
1050
|
it "outputs failure with status code" do
|
1048
1051
|
expect(output).to include "Validation",
|
1049
1052
|
"Validating Push API key: Failed to validate: status 500\n" +
|
1050
|
-
|
1053
|
+
%("Could not confirm authorization: 500")
|
1051
1054
|
end
|
1052
1055
|
|
1053
1056
|
context "with color", :color => true do
|
1054
1057
|
it "outputs error in color" do
|
1055
1058
|
expect(output).to include "Validation",
|
1056
|
-
"Validating Push API key:
|
1057
|
-
|
1058
|
-
"Failed to validate: status 500\n" +
|
1059
|
-
%("Could not confirm authorization: 500"),
|
1059
|
+
"Validating Push API key: #{colorize(
|
1060
|
+
%(Failed to validate: status 500\n"Could not confirm authorization: 500"),
|
1060
1061
|
:red
|
1061
|
-
)
|
1062
|
+
)}"
|
1062
1063
|
end
|
1063
1064
|
end
|
1064
1065
|
|
@@ -1280,7 +1281,7 @@ describe Appsignal::CLI::Diagnose, :api_stub => true, :send_report => :yes_cli_i
|
|
1280
1281
|
it "outputs ownership" do
|
1281
1282
|
expect(output).to include \
|
1282
1283
|
%(Root path\n Path: "#{root_path}"\n Writable?: true\n ) \
|
1283
|
-
"Ownership?: true (file: #{process_user}:#{Process.uid}, "\
|
1284
|
+
"Ownership?: true (file: #{process_user}:#{Process.uid}, " \
|
1284
1285
|
"process: #{process_user}:#{Process.uid})"
|
1285
1286
|
end
|
1286
1287
|
|
@@ -1414,7 +1415,9 @@ describe Appsignal::CLI::Diagnose, :api_stub => true, :send_report => :yes_cli_i
|
|
1414
1415
|
let(:filename) { "appsignal.log" }
|
1415
1416
|
before do
|
1416
1417
|
ENV["APPSIGNAL_LOG"] = "stdout"
|
1417
|
-
expect_any_instance_of(Appsignal::Config).to receive(:log_file_path)
|
1418
|
+
expect_any_instance_of(Appsignal::Config).to receive(:log_file_path)
|
1419
|
+
.at_least(:once)
|
1420
|
+
.and_return(file_path)
|
1418
1421
|
end
|
1419
1422
|
end
|
1420
1423
|
|
@@ -1442,6 +1445,6 @@ describe Appsignal::CLI::Diagnose, :api_stub => true, :send_report => :yes_cli_i
|
|
1442
1445
|
end
|
1443
1446
|
|
1444
1447
|
def hash_with_string_keys(hash)
|
1445
|
-
|
1448
|
+
hash.transform_keys(&:to_s)
|
1446
1449
|
end
|
1447
1450
|
end
|