appsignal 3.4.0-java → 3.4.2-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +63 -21
  3. data/.rubocop_todo.yml +68 -54
  4. data/.semaphore/semaphore.yml +11 -11
  5. data/CHANGELOG.md +51 -0
  6. data/Rakefile +15 -99
  7. data/appsignal.gemspec +3 -4
  8. data/bin/appsignal +4 -2
  9. data/build_matrix.yml +4 -4
  10. data/ext/._appsignal-agent +0 -0
  11. data/ext/Rakefile +22 -21
  12. data/ext/agent.rb +29 -27
  13. data/ext/base.rb +14 -17
  14. data/ext/extconf.rb +4 -1
  15. data/lib/appsignal/auth_check.rb +3 -3
  16. data/lib/appsignal/capistrano.rb +1 -1
  17. data/lib/appsignal/cli/demo.rb +5 -2
  18. data/lib/appsignal/cli/diagnose/paths.rb +4 -1
  19. data/lib/appsignal/cli/diagnose/utils.rb +7 -3
  20. data/lib/appsignal/cli/diagnose.rb +7 -5
  21. data/lib/appsignal/cli/helpers.rb +1 -4
  22. data/lib/appsignal/cli/install.rb +4 -10
  23. data/lib/appsignal/cli.rb +3 -2
  24. data/lib/appsignal/config.rb +106 -103
  25. data/lib/appsignal/demo.rb +2 -1
  26. data/lib/appsignal/environment.rb +2 -0
  27. data/lib/appsignal/event_formatter/action_view/render_formatter.rb +2 -1
  28. data/lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter.rb +13 -13
  29. data/lib/appsignal/event_formatter.rb +5 -4
  30. data/lib/appsignal/extension/jruby.rb +11 -9
  31. data/lib/appsignal/extension.rb +1 -1
  32. data/lib/appsignal/helpers/instrumentation.rb +50 -35
  33. data/lib/appsignal/hooks/action_cable.rb +6 -4
  34. data/lib/appsignal/hooks/action_mailer.rb +2 -0
  35. data/lib/appsignal/hooks/active_job.rb +11 -10
  36. data/lib/appsignal/hooks/active_support_notifications.rb +3 -4
  37. data/lib/appsignal/hooks/data_mapper.rb +1 -1
  38. data/lib/appsignal/hooks/gvl.rb +3 -0
  39. data/lib/appsignal/hooks/http.rb +1 -1
  40. data/lib/appsignal/hooks/mri.rb +2 -0
  41. data/lib/appsignal/hooks/net_http.rb +1 -1
  42. data/lib/appsignal/hooks/que.rb +1 -1
  43. data/lib/appsignal/hooks/rake.rb +1 -1
  44. data/lib/appsignal/hooks/redis.rb +1 -1
  45. data/lib/appsignal/hooks/resque.rb +1 -1
  46. data/lib/appsignal/hooks/shoryuken.rb +2 -4
  47. data/lib/appsignal/hooks/sidekiq.rb +1 -1
  48. data/lib/appsignal/hooks/unicorn.rb +2 -2
  49. data/lib/appsignal/hooks/webmachine.rb +1 -1
  50. data/lib/appsignal/hooks.rb +2 -2
  51. data/lib/appsignal/integrations/active_support_notifications.rb +1 -1
  52. data/lib/appsignal/integrations/capistrano/appsignal.cap +6 -3
  53. data/lib/appsignal/integrations/capistrano/capistrano_2_tasks.rb +5 -4
  54. data/lib/appsignal/integrations/delayed_job_plugin.rb +3 -5
  55. data/lib/appsignal/integrations/grape.rb +1 -1
  56. data/lib/appsignal/integrations/hanami.rb +1 -1
  57. data/lib/appsignal/integrations/object.rb +2 -3
  58. data/lib/appsignal/integrations/padrino.rb +2 -4
  59. data/lib/appsignal/integrations/que.rb +6 -6
  60. data/lib/appsignal/integrations/railtie.rb +76 -0
  61. data/lib/appsignal/integrations/sidekiq.rb +9 -11
  62. data/lib/appsignal/integrations/sinatra.rb +1 -3
  63. data/lib/appsignal/integrations/webmachine.rb +4 -6
  64. data/lib/appsignal/logger.rb +31 -6
  65. data/lib/appsignal/marker.rb +4 -5
  66. data/lib/appsignal/minutely.rb +7 -7
  67. data/lib/appsignal/probes/gvl.rb +9 -4
  68. data/lib/appsignal/probes/helpers.rb +4 -6
  69. data/lib/appsignal/probes/mri.rb +7 -5
  70. data/lib/appsignal/probes/sidekiq.rb +3 -0
  71. data/lib/appsignal/probes.rb +2 -0
  72. data/lib/appsignal/rack/generic_instrumentation.rb +1 -5
  73. data/lib/appsignal/rack/sinatra_instrumentation.rb +3 -5
  74. data/lib/appsignal/rack/streaming_listener.rb +11 -13
  75. data/lib/appsignal/span.rb +5 -5
  76. data/lib/appsignal/system.rb +10 -11
  77. data/lib/appsignal/transaction.rb +49 -25
  78. data/lib/appsignal/transmitter.rb +4 -2
  79. data/lib/appsignal/utils/deprecation_message.rb +2 -0
  80. data/lib/appsignal/utils/hash_sanitizer.rb +1 -1
  81. data/lib/appsignal/utils/integration_logger.rb +5 -3
  82. data/lib/appsignal/utils/json.rb +1 -1
  83. data/lib/appsignal/utils/query_params_sanitizer.rb +1 -1
  84. data/lib/appsignal/version.rb +1 -1
  85. data/lib/appsignal.rb +5 -4
  86. data/lib/puma/plugin/appsignal.rb +16 -18
  87. data/script/lint_git +1 -1
  88. data/spec/lib/appsignal/capistrano2_spec.rb +6 -3
  89. data/spec/lib/appsignal/capistrano3_spec.rb +6 -3
  90. data/spec/lib/appsignal/cli/diagnose/utils_spec.rb +1 -3
  91. data/spec/lib/appsignal/cli/diagnose_spec.rb +33 -30
  92. data/spec/lib/appsignal/cli/install_spec.rb +5 -6
  93. data/spec/lib/appsignal/cli_spec.rb +1 -1
  94. data/spec/lib/appsignal/config_spec.rb +43 -37
  95. data/spec/lib/appsignal/event_formatter/action_view/render_formatter_spec.rb +11 -5
  96. data/spec/lib/appsignal/event_formatter/elastic_search/search_formatter_spec.rb +4 -4
  97. data/spec/lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter_spec.rb +1 -4
  98. data/spec/lib/appsignal/event_formatter_spec.rb +11 -9
  99. data/spec/lib/appsignal/hooks/action_cable_spec.rb +5 -2
  100. data/spec/lib/appsignal/hooks/action_mailer_spec.rb +2 -1
  101. data/spec/lib/appsignal/hooks/active_support_notifications/instrument_shared_examples.rb +1 -1
  102. data/spec/lib/appsignal/hooks/active_support_notifications/start_finish_shared_examples.rb +1 -1
  103. data/spec/lib/appsignal/hooks/activejob_spec.rb +21 -12
  104. data/spec/lib/appsignal/hooks/data_mapper_spec.rb +1 -0
  105. data/spec/lib/appsignal/hooks/delayed_job_spec.rb +12 -12
  106. data/spec/lib/appsignal/hooks/excon_spec.rb +2 -2
  107. data/spec/lib/appsignal/hooks/mongo_ruby_driver_spec.rb +3 -1
  108. data/spec/lib/appsignal/hooks/shoryuken_spec.rb +4 -2
  109. data/spec/lib/appsignal/hooks/sidekiq_spec.rb +2 -1
  110. data/spec/lib/appsignal/hooks_spec.rb +5 -4
  111. data/spec/lib/appsignal/integrations/grape_spec.rb +8 -4
  112. data/spec/lib/appsignal/integrations/hanami_spec.rb +16 -8
  113. data/spec/lib/appsignal/integrations/mongo_ruby_driver_spec.rb +2 -4
  114. data/spec/lib/appsignal/integrations/object_spec.rb +6 -1
  115. data/spec/lib/appsignal/integrations/padrino_spec.rb +4 -2
  116. data/spec/lib/appsignal/integrations/railtie_spec.rb +213 -6
  117. data/spec/lib/appsignal/integrations/sidekiq_spec.rb +54 -41
  118. data/spec/lib/appsignal/logger_spec.rb +20 -4
  119. data/spec/lib/appsignal/marker_spec.rb +2 -2
  120. data/spec/lib/appsignal/minutely_spec.rb +3 -3
  121. data/spec/lib/appsignal/probes/gvl_spec.rb +60 -12
  122. data/spec/lib/appsignal/probes/mri_spec.rb +7 -4
  123. data/spec/lib/appsignal/rack/generic_instrumentation_spec.rb +2 -1
  124. data/spec/lib/appsignal/rack/rails_instrumentation_spec.rb +2 -1
  125. data/spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb +10 -5
  126. data/spec/lib/appsignal/rack/streaming_listener_spec.rb +7 -5
  127. data/spec/lib/appsignal/transaction_spec.rb +20 -13
  128. data/spec/lib/appsignal/utils/data_spec.rb +10 -1
  129. data/spec/lib/appsignal/utils/hash_sanitizer_spec.rb +11 -11
  130. data/spec/lib/appsignal/utils/json_spec.rb +4 -2
  131. data/spec/lib/appsignal_spec.rb +49 -35
  132. data/spec/lib/puma/appsignal_spec.rb +9 -11
  133. data/spec/spec_helper.rb +14 -2
  134. data/spec/support/fixtures/projects/valid/config/appsignal.yml +1 -1
  135. data/spec/support/helpers/config_helpers.rb +2 -1
  136. data/spec/support/helpers/dependency_helper.rb +1 -9
  137. data/spec/support/helpers/std_streams_helper.rb +1 -3
  138. data/spec/support/helpers/wait_for_helper.rb +2 -3
  139. data/spec/support/mocks/appsignal_mock.rb +1 -1
  140. data/spec/support/mocks/fake_gvl_tools.rb +2 -10
  141. data/spec/support/testing.rb +4 -3
  142. metadata +9 -135
@@ -13,6 +13,10 @@ module Appsignal
13
13
  Appsignal::Integrations::Railtie.initialize_appsignal(app)
14
14
  end
15
15
 
16
+ console do
17
+ Appsignal::Minutely.stop
18
+ end
19
+
16
20
  def self.initialize_appsignal(app)
17
21
  # Load config
18
22
  Appsignal.config = Appsignal::Config.new(
@@ -31,6 +35,78 @@ module Appsignal
31
35
  )
32
36
 
33
37
  Appsignal.start
38
+
39
+ if Appsignal.config[:enable_rails_error_reporter] && Rails.respond_to?(:error) # rubocop:disable Style/GuardClause
40
+ Rails.error.subscribe(Appsignal::Integrations::RailsErrorReporterSubscriber)
41
+ end
42
+ end
43
+ end
44
+
45
+ # Report errors reported by the Rails error reporter.
46
+ #
47
+ # We only report that are not reraised by the error reporter, using
48
+ # `Rails.error.handle`.
49
+ # @api private
50
+ class RailsErrorReporterSubscriber
51
+ class << self
52
+ def report(error, handled:, severity:, context: {}, source: nil)
53
+ # Ignore not handled errors. They are reraised by the error reporter
54
+ # and are caught and recorded by our Rails middleware.
55
+ return unless handled
56
+
57
+ Appsignal.send_error(error) do |transaction|
58
+ namespace, action_name, tags = context_for(context.dup)
59
+ transaction.set_namespace(namespace) if namespace
60
+ transaction.set_action(action_name) if action_name
61
+
62
+ tags[:severity] = severity
63
+ tags[:source] = source.to_s if source
64
+ transaction.set_tags(tags)
65
+ end
66
+ end
67
+
68
+ private
69
+
70
+ def context_for(context)
71
+ tags = {}
72
+
73
+ appsignal_context = context.delete(:appsignal)
74
+ # Fetch the namespace and action name based on the Rails execution
75
+ # context.
76
+ controller = context.delete(:controller)
77
+ if controller
78
+ namespace = Appsignal::Transaction::HTTP_REQUEST
79
+ action_name = "#{controller.class.name}##{controller.action_name}"
80
+ end
81
+ # ActiveJob transaction naming relies on the current AppSignal
82
+ # transaction namespace and action name copying done after this.
83
+ context.delete(:job)
84
+
85
+ # Copy the transaction action name, namespace and other data from
86
+ # the currently active transaction, if not already set.
87
+ if Appsignal::Transaction.current?
88
+ current_transaction = Appsignal::Transaction.current
89
+ namespace = current_transaction.namespace
90
+
91
+ transaction_action = current_transaction.action
92
+ action_name = current_transaction.action if transaction_action
93
+
94
+ current_tags = current_transaction.tags
95
+ tags.merge!(current_tags) if current_tags
96
+ end
97
+
98
+ # Use the user override set in the context
99
+ if appsignal_context
100
+ context_namespace = appsignal_context[:namespace]
101
+ namespace = context_namespace if context_namespace
102
+
103
+ context_action_name = appsignal_context[:action]
104
+ action_name = context_action_name if context_action_name
105
+ end
106
+ tags.merge!(context)
107
+
108
+ [namespace, action_name, tags]
109
+ end
34
110
  end
35
111
  end
36
112
  end
@@ -35,7 +35,7 @@ module Appsignal
35
35
  end
36
36
 
37
37
  # @api private
38
- class SidekiqMiddleware # rubocop:disable Metrics/ClassLength
38
+ class SidekiqMiddleware
39
39
  include Appsignal::Hooks::Helpers
40
40
 
41
41
  EXCLUDED_JOB_KEYS = %w[
@@ -43,7 +43,7 @@ module Appsignal
43
43
  error_message failed_at jid retried_at retry wrapped
44
44
  ].freeze
45
45
 
46
- def call(_worker, item, _queue)
46
+ def call(_worker, item, _queue, &block)
47
47
  job_status = nil
48
48
  transaction = Appsignal::Transaction.create(
49
49
  item["jid"],
@@ -52,23 +52,21 @@ module Appsignal
52
52
  :queue_start => item["enqueued_at"]
53
53
  )
54
54
  )
55
+ transaction.set_action_if_nil(formatted_action_name(item))
55
56
 
56
- Appsignal.instrument "perform_job.sidekiq" do
57
- yield
57
+ formatted_metadata(item).each do |key, value|
58
+ transaction.set_metadata key, value
58
59
  end
60
+
61
+ Appsignal.instrument "perform_job.sidekiq", &block
59
62
  rescue Exception => exception # rubocop:disable Lint/RescueException
60
63
  job_status = :failed
61
64
  raise exception
62
65
  ensure
63
66
  if transaction
64
- transaction.set_action_if_nil(formatted_action_name(item))
65
-
66
67
  params = filtered_arguments(item)
67
68
  transaction.params = params if params
68
69
 
69
- formatted_metadata(item).each do |key, value|
70
- transaction.set_metadata key, value
71
- end
72
70
  transaction.set_http_or_background_queue_start
73
71
  Appsignal::Transaction.complete_current! unless exception
74
72
 
@@ -151,9 +149,9 @@ module Appsignal
151
149
  else
152
150
  # Sidekiq Enterprise argument encryption.
153
151
  # More information: https://github.com/mperham/sidekiq/wiki/Ent-Encryption
154
- if job["encrypt".freeze]
152
+ if job["encrypt"]
155
153
  # No point in showing 150+ bytes of random garbage
156
- args[-1] = "[encrypted data]".freeze
154
+ args[-1] = "[encrypted data]"
157
155
  end
158
156
  args
159
157
  end
@@ -14,6 +14,4 @@ Appsignal.config = Appsignal::Config.new(
14
14
  Appsignal.start_logger
15
15
  Appsignal.start
16
16
 
17
- if Appsignal.active?
18
- ::Sinatra::Base.use(Appsignal::Rack::SinatraBaseInstrumentation)
19
- end
17
+ ::Sinatra::Base.use(Appsignal::Rack::SinatraBaseInstrumentation) if Appsignal.active?
@@ -25,12 +25,10 @@ module Appsignal
25
25
 
26
26
  def handle_exceptions
27
27
  super do
28
- begin
29
- yield
30
- rescue Exception => e # rubocop:disable Lint/RescueException
31
- Appsignal.set_error(e)
32
- raise e
33
- end
28
+ yield
29
+ rescue Exception => e # rubocop:disable Lint/RescueException
30
+ Appsignal.set_error(e)
31
+ raise e
34
32
  end
35
33
  end
36
34
  end
@@ -2,7 +2,6 @@
2
2
 
3
3
  require "logger"
4
4
  require "set"
5
- require "thread"
6
5
 
7
6
  module Appsignal
8
7
  # Logger that flushes logs to the AppSignal logging service
@@ -25,6 +24,7 @@ module Appsignal
25
24
  # @return [void]
26
25
  def initialize(group, level: INFO, format: PLAINTEXT)
27
26
  raise TypeError, "group must be a string" unless group.is_a? String
27
+
28
28
  @group = group
29
29
  @level = level
30
30
  @format = format
@@ -37,6 +37,7 @@ module Appsignal
37
37
  def add(severity, message = nil, group = nil)
38
38
  severity ||= UNKNOWN
39
39
  return true if severity < level
40
+
40
41
  group = @group if group.nil?
41
42
  if message.nil?
42
43
  if block_given?
@@ -47,6 +48,7 @@ module Appsignal
47
48
  end
48
49
  end
49
50
  return if message.nil?
51
+
50
52
  message = formatter.call(severity, Time.now, group, message) if formatter
51
53
 
52
54
  Appsignal::Extension.log(
@@ -64,9 +66,11 @@ module Appsignal
64
66
  # @param attributes Attributes to tag the log with
65
67
  # @return [void]
66
68
  def debug(message = nil, attributes = {})
67
- return if DEBUG < level
69
+ return if level > DEBUG
70
+
68
71
  message = yield if message.nil? && block_given?
69
72
  return if message.nil?
73
+
70
74
  add_with_attributes(DEBUG, message, @group, attributes)
71
75
  end
72
76
 
@@ -75,9 +79,11 @@ module Appsignal
75
79
  # @param attributes Attributes to tag the log with
76
80
  # @return [void]
77
81
  def info(message = nil, attributes = {})
78
- return if INFO < level
82
+ return if level > INFO
83
+
79
84
  message = yield if message.nil? && block_given?
80
85
  return if message.nil?
86
+
81
87
  add_with_attributes(INFO, message, @group, attributes)
82
88
  end
83
89
 
@@ -86,9 +92,11 @@ module Appsignal
86
92
  # @param attributes Attributes to tag the log with
87
93
  # @return [void]
88
94
  def warn(message = nil, attributes = {})
89
- return if WARN < level
95
+ return if level > WARN
96
+
90
97
  message = yield if message.nil? && block_given?
91
98
  return if message.nil?
99
+
92
100
  add_with_attributes(WARN, message, @group, attributes)
93
101
  end
94
102
 
@@ -97,9 +105,11 @@ module Appsignal
97
105
  # @param attributes Attributes to tag the log with
98
106
  # @return [void]
99
107
  def error(message = nil, attributes = {})
100
- return if ERROR < level
108
+ return if level > ERROR
109
+
101
110
  message = yield if message.nil? && block_given?
102
111
  return if message.nil?
112
+
103
113
  add_with_attributes(ERROR, message, @group, attributes)
104
114
  end
105
115
 
@@ -108,12 +118,27 @@ module Appsignal
108
118
  # @param attributes Attributes to tag the log with
109
119
  # @return [void]
110
120
  def fatal(message = nil, attributes = {})
111
- return if FATAL < level
121
+ return if level > FATAL
122
+
112
123
  message = yield if message.nil? && block_given?
113
124
  return if message.nil?
125
+
114
126
  add_with_attributes(FATAL, message, @group, attributes)
115
127
  end
116
128
 
129
+ # When using ActiveSupport::TaggedLogging without the broadcast feature,
130
+ # the passed logger is required to respond to the `silence` method.
131
+ # In our case it behaves as the broadcast feature of the Rails logger, but
132
+ # we don't have to check if the parent logger has the `silence` method defined
133
+ # as our logger directly inherits from Ruby base logger.
134
+ #
135
+ # Links:
136
+ # https://github.com/rails/rails/blob/e11ebc04cfbe41c06cdfb70ee5a9fdbbd98bb263/activesupport/lib/active_support/logger.rb#L60-L76
137
+ # https://github.com/rails/rails/blob/main/activesupport/e11ebc04cfbe41c06cdfb70ee5a9fdbbd98bb263/active_support/logger_silence.rb
138
+ def silence(_severity = ERROR, &block)
139
+ block.call
140
+ end
141
+
117
142
  private
118
143
 
119
144
  def add_with_attributes(severity, message, group, attributes)
@@ -24,7 +24,7 @@ module Appsignal
24
24
  class Marker
25
25
  # Path used on the AppSignal Push API
26
26
  # https://push.appsignal.com/1/markers
27
- ACTION = "markers".freeze
27
+ ACTION = "markers"
28
28
 
29
29
  attr_reader :marker_data, :config
30
30
 
@@ -49,13 +49,12 @@ module Appsignal
49
49
  # @return [void]
50
50
  def transmit
51
51
  transmitter = Transmitter.new(ACTION, config)
52
- puts "Notifying AppSignal of deploy with: "\
52
+ puts "Notifying AppSignal of deploy with: " \
53
53
  "revision: #{marker_data[:revision]}, user: #{marker_data[:user]}"
54
54
 
55
55
  response = transmitter.transmit(marker_data)
56
- unless response.code == "200"
57
- raise "#{response.code} at #{transmitter.uri}"
58
- end
56
+ raise "#{response.code} at #{transmitter.uri}" unless response.code == "200"
57
+
59
58
  puts "AppSignal has been notified of this deploy!"
60
59
  rescue => e
61
60
  puts "Something went wrong while trying to notify AppSignal: #{e}"
@@ -135,13 +135,11 @@ module Appsignal
135
135
  logger = Appsignal.logger
136
136
  logger.debug("Gathering minutely metrics with #{probe_instances.count} probes")
137
137
  probe_instances.each do |name, probe|
138
- begin
139
- logger.debug("Gathering minutely metrics with '#{name}' probe")
140
- probe.call
141
- rescue => ex
142
- logger.error "Error in minutely probe '#{name}': #{ex}"
143
- logger.debug ex.backtrace.join("\n")
144
- end
138
+ logger.debug("Gathering minutely metrics with '#{name}' probe")
139
+ probe.call
140
+ rescue => ex
141
+ logger.error "Error in minutely probe '#{name}': #{ex}"
142
+ logger.debug ex.backtrace.join("\n")
145
143
  end
146
144
  sleep wait_time
147
145
  end
@@ -164,6 +162,7 @@ module Appsignal
164
162
  def initial_wait_time
165
163
  remaining_seconds = 60 - Time.now.sec
166
164
  return remaining_seconds if remaining_seconds > 30
165
+
167
166
  remaining_seconds + 60
168
167
  end
169
168
 
@@ -195,6 +194,7 @@ module Appsignal
195
194
 
196
195
  def dependencies_present?(probe)
197
196
  return true unless probe.respond_to? :dependencies_present?
197
+
198
198
  probe.dependencies_present?
199
199
  end
200
200
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Appsignal
2
4
  module Probes
3
5
  class GvlProbe
@@ -5,7 +7,8 @@ module Appsignal
5
7
 
6
8
  # @api private
7
9
  def self.dependencies_present?
8
- defined?(::GVLTools) && gvltools_0_2_or_newer? && ruby_3_2_or_newer? && !Appsignal::System.jruby?
10
+ defined?(::GVLTools) && gvltools_0_2_or_newer? && ruby_3_2_or_newer? &&
11
+ !Appsignal::System.jruby?
9
12
  end
10
13
 
11
14
  # @api private
@@ -25,7 +28,7 @@ module Appsignal
25
28
  end
26
29
 
27
30
  def call
28
- probe_global_timer if @gvl_tools::GlobalTimer.enabled?
31
+ probe_global_timer
29
32
  probe_waiting_threads if @gvl_tools::WaitingThreads.enabled?
30
33
  end
31
34
 
@@ -34,8 +37,10 @@ module Appsignal
34
37
  def probe_global_timer
35
38
  monotonic_time_ns = @gvl_tools::GlobalTimer.monotonic_time
36
39
  gauge_delta :gvl_global_timer, monotonic_time_ns do |time_delta_ns|
37
- time_delta_ms = time_delta_ns / 1_000_000
38
- set_gauge_with_hostname("gvl_global_timer", time_delta_ms)
40
+ if time_delta_ns > 0
41
+ time_delta_ms = time_delta_ns / 1_000_000
42
+ set_gauge_with_hostname("gvl_global_timer", time_delta_ms)
43
+ end
39
44
  end
40
45
  end
41
46
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Appsignal
2
4
  module Probes
3
5
  module Helpers
@@ -42,13 +44,9 @@ module Appsignal
42
44
  return @hostname if defined?(@hostname)
43
45
 
44
46
  config = @appsignal.config
47
+ # Auto detect hostname as fallback. May be inaccurate.
45
48
  @hostname =
46
- if config[:hostname]
47
- config[:hostname]
48
- else
49
- # Auto detect hostname as fallback. May be inaccurate.
50
- Socket.gethostname
51
- end
49
+ config[:hostname] || Socket.gethostname
52
50
  Appsignal.logger.debug "Probe helper: Using hostname config " \
53
51
  "option '#{@hostname.inspect}' as hostname"
54
52
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Appsignal
2
4
  module Probes
3
5
  class MriProbe
@@ -37,9 +39,7 @@ module Appsignal
37
39
  end
38
40
 
39
41
  class_serial = stat[:class_serial]
40
- if class_serial
41
- set_gauge_with_hostname("ruby_vm", class_serial, :metric => :class_serial)
42
- end
42
+ set_gauge_with_hostname("ruby_vm", class_serial, :metric => :class_serial) if class_serial
43
43
 
44
44
  global_constant_state =
45
45
  stat[:constant_cache] ? stat[:constant_cache].values.sum : stat[:global_constant_state]
@@ -76,8 +76,10 @@ module Appsignal
76
76
  set_gauge_with_hostname("gc_count", major_gc_count, :metric => :major_gc_count)
77
77
  end
78
78
 
79
- set_gauge_with_hostname("heap_slots", gc_stats[:heap_live_slots] || gc_stats[:heap_live_slot], :metric => :heap_live)
80
- set_gauge_with_hostname("heap_slots", gc_stats[:heap_free_slots] || gc_stats[:heap_free_slot], :metric => :heap_free)
79
+ set_gauge_with_hostname("heap_slots",
80
+ gc_stats[:heap_live_slots] || gc_stats[:heap_live_slot], :metric => :heap_live)
81
+ set_gauge_with_hostname("heap_slots",
82
+ gc_stats[:heap_free_slots] || gc_stats[:heap_free_slot], :metric => :heap_free)
81
83
  end
82
84
  end
83
85
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Appsignal
2
4
  module Probes
3
5
  class SidekiqProbe
@@ -116,6 +118,7 @@ module Appsignal
116
118
 
117
119
  def hostname
118
120
  return @hostname if defined?(@hostname)
121
+
119
122
  if config.key?(:hostname)
120
123
  @hostname = config[:hostname]
121
124
  Appsignal.logger.debug "Sidekiq probe: Using hostname config " \
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Appsignal
2
4
  module Probes
3
5
  end
@@ -35,11 +35,7 @@ module Appsignal
35
35
  transaction.set_error(error)
36
36
  raise error
37
37
  ensure
38
- if env["appsignal.route"]
39
- transaction.set_action_if_nil(env["appsignal.route"])
40
- else
41
- transaction.set_action_if_nil("unknown")
42
- end
38
+ transaction.set_action_if_nil(env["appsignal.route"] || "unknown")
43
39
  transaction.set_metadata("path", request.path)
44
40
  transaction.set_metadata("method", request.request_method)
45
41
  transaction.set_http_or_background_queue_start
@@ -15,7 +15,7 @@ module Appsignal
15
15
  def initialize(app, options = {})
16
16
  @app = app
17
17
  @options = options
18
- Appsignal.logger.warn "Please remove Appsignal::Rack::SinatraInstrumentation "\
18
+ Appsignal.logger.warn "Please remove Appsignal::Rack::SinatraInstrumentation " \
19
19
  "from your Sinatra::Base class. This is no longer needed."
20
20
  end
21
21
 
@@ -47,9 +47,7 @@ module Appsignal
47
47
  end
48
48
 
49
49
  def call_with_appsignal_monitoring(env)
50
- if @options[:params_method]
51
- env[:params_method] = @options[:params_method]
52
- end
50
+ env[:params_method] = @options[:params_method] if @options[:params_method]
53
51
  request = @options.fetch(:request_class, Sinatra::Request).new(env)
54
52
  transaction = Appsignal::Transaction.create(
55
53
  SecureRandom.uuid,
@@ -82,7 +80,7 @@ module Appsignal
82
80
  return unless env["sinatra.route"]
83
81
 
84
82
  if env["SCRIPT_NAME"]
85
- method, route = env["sinatra.route"].split(" ")
83
+ method, route = env["sinatra.route"].split
86
84
  "#{method} #{env["SCRIPT_NAME"]}#{route}"
87
85
  else
88
86
  env["sinatra.route"]
@@ -31,17 +31,15 @@ module Appsignal
31
31
  # Instrument a `process_action`, to set params/action name
32
32
  status, headers, body =
33
33
  Appsignal.instrument("process_action.rack") do
34
- begin
35
- @app.call(env)
36
- rescue Exception => e # rubocop:disable Lint/RescueException
37
- transaction.set_error(e)
38
- raise e
39
- ensure
40
- transaction.set_action_if_nil(env["appsignal.action"])
41
- transaction.set_metadata("path", request.path)
42
- transaction.set_metadata("method", request.request_method)
43
- transaction.set_http_or_background_queue_start
44
- end
34
+ @app.call(env)
35
+ rescue Exception => e # rubocop:disable Lint/RescueException
36
+ transaction.set_error(e)
37
+ raise e
38
+ ensure
39
+ transaction.set_action_if_nil(env["appsignal.action"])
40
+ transaction.set_metadata("path", request.path)
41
+ transaction.set_metadata("method", request.request_method)
42
+ transaction.set_http_or_background_queue_start
45
43
  end
46
44
 
47
45
  # Wrap the result body with our StreamWrapper
@@ -56,8 +54,8 @@ module Appsignal
56
54
  @transaction = transaction
57
55
  end
58
56
 
59
- def each
60
- @stream.each { |c| yield(c) }
57
+ def each(&block)
58
+ @stream.each(&block)
61
59
  rescue Exception => e # rubocop:disable Lint/RescueException
62
60
  @transaction.set_error(e)
63
61
  raise e
@@ -1,11 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Appsignal
2
4
  class Span
3
5
  def initialize(namespace = nil, ext = nil)
4
- @ext = if ext
5
- ext
6
- else
7
- Appsignal::Extension::Span.root(namespace || "")
8
- end
6
+ @ext = ext || Appsignal::Extension::Span.root(namespace || "")
9
7
  end
10
8
 
11
9
  def child
@@ -34,6 +32,7 @@ module Appsignal
34
32
 
35
33
  def set_sample_data(key, data)
36
34
  return unless key && data && (data.is_a?(Array) || data.is_a?(Hash))
35
+
37
36
  @ext.set_sample_data(
38
37
  key.to_s,
39
38
  Appsignal::Utils::Data.generate(data)
@@ -62,6 +61,7 @@ module Appsignal
62
61
  def to_h
63
62
  json = @ext.to_json
64
63
  return unless json
64
+
65
65
  JSON.parse(json)
66
66
  end
67
67
 
@@ -7,14 +7,14 @@ module Appsignal
7
7
  #
8
8
  # @api private
9
9
  module System
10
- LINUX_TARGET = "linux".freeze
11
- LINUX_ARM_ARCHITECTURE = "aarch64".freeze
12
- MUSL_TARGET = "linux-musl".freeze
13
- FREEBSD_TARGET = "freebsd".freeze
14
- GEM_EXT_PATH = File.expand_path("../../../ext", __FILE__).freeze
10
+ LINUX_TARGET = "linux"
11
+ LINUX_ARM_ARCHITECTURE = "aarch64"
12
+ MUSL_TARGET = "linux-musl"
13
+ FREEBSD_TARGET = "freebsd"
14
+ GEM_EXT_PATH = File.expand_path("../../ext", __dir__).freeze
15
15
 
16
16
  def self.heroku?
17
- ENV.key? "DYNO".freeze
17
+ ENV.key? "DYNO"
18
18
  end
19
19
 
20
20
  # Detect agent and extension platform build
@@ -48,10 +48,9 @@ module Appsignal
48
48
  if local_os =~ /linux/
49
49
  ldd_output = ldd_version_output
50
50
  return MUSL_TARGET if ldd_output.include? "musl"
51
+
51
52
  ldd_version = extract_ldd_version(ldd_output)
52
- if ldd_version && versionify(ldd_version) < versionify("2.15")
53
- return MUSL_TARGET
54
- end
53
+ return MUSL_TARGET if ldd_version && versionify(ldd_version) < versionify("2.15")
55
54
  end
56
55
 
57
56
  local_os
@@ -77,14 +76,14 @@ module Appsignal
77
76
  #
78
77
  # @api private
79
78
  def self.force_musl_build?
80
- %w[true 1].include?(ENV["APPSIGNAL_BUILD_FOR_MUSL"])
79
+ %w[true 1].include?(ENV.fetch("APPSIGNAL_BUILD_FOR_MUSL", nil))
81
80
  end
82
81
 
83
82
  # Returns whether or not the linux ARM build was selected by the user.
84
83
  #
85
84
  # @api private
86
85
  def self.force_linux_arm_build?
87
- %w[true 1].include?(ENV["APPSIGNAL_BUILD_FOR_LINUX_ARM"])
86
+ %w[true 1].include?(ENV.fetch("APPSIGNAL_BUILD_FOR_LINUX_ARM", nil))
88
87
  end
89
88
 
90
89
  # @api private