appsignal 3.4.0 → 3.4.1

Sign up to get free protection for your applications and to get access to all the features.
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 +37 -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 +2 -0
  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 +105 -102
  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 +72 -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
@@ -11,39 +11,40 @@ module Appsignal
11
11
  include Appsignal::Utils::DeprecationMessage
12
12
 
13
13
  DEFAULT_CONFIG = {
14
- :ca_file_path => File.expand_path(File.join("../../../resources/cacert.pem"), __FILE__),
15
- :debug => false,
16
- :dns_servers => [],
17
- :enable_allocation_tracking => true,
18
- :enable_host_metrics => true,
19
- :enable_minutely_probes => true,
20
- :enable_statsd => true,
21
- :enable_nginx_metrics => false,
22
- :enable_gvl_global_timer => true,
23
- :enable_gvl_waiting_threads => true,
24
- :endpoint => "https://push.appsignal.com",
25
- :files_world_accessible => true,
26
- :filter_parameters => [],
27
- :filter_session_data => [],
28
- :ignore_actions => [],
29
- :ignore_errors => [],
30
- :ignore_namespaces => [],
31
- :instrument_http_rb => true,
32
- :instrument_net_http => true,
33
- :instrument_redis => true,
34
- :instrument_sequel => true,
35
- :log => "file",
36
- :logging_endpoint => "https://appsignal-endpoint.net",
37
- :request_headers => %w[
14
+ :ca_file_path => File.expand_path(File.join("../../../resources/cacert.pem"), __FILE__),
15
+ :debug => false,
16
+ :dns_servers => [],
17
+ :enable_allocation_tracking => true,
18
+ :enable_host_metrics => true,
19
+ :enable_minutely_probes => true,
20
+ :enable_statsd => true,
21
+ :enable_nginx_metrics => false,
22
+ :enable_gvl_global_timer => true,
23
+ :enable_gvl_waiting_threads => true,
24
+ :enable_rails_error_reporter => true,
25
+ :endpoint => "https://push.appsignal.com",
26
+ :files_world_accessible => true,
27
+ :filter_parameters => [],
28
+ :filter_session_data => [],
29
+ :ignore_actions => [],
30
+ :ignore_errors => [],
31
+ :ignore_namespaces => [],
32
+ :instrument_http_rb => true,
33
+ :instrument_net_http => true,
34
+ :instrument_redis => true,
35
+ :instrument_sequel => true,
36
+ :log => "file",
37
+ :logging_endpoint => "https://appsignal-endpoint.net",
38
+ :request_headers => %w[
38
39
  HTTP_ACCEPT HTTP_ACCEPT_CHARSET HTTP_ACCEPT_ENCODING
39
40
  HTTP_ACCEPT_LANGUAGE HTTP_CACHE_CONTROL HTTP_CONNECTION
40
41
  CONTENT_LENGTH PATH_INFO HTTP_RANGE
41
42
  REQUEST_METHOD REQUEST_URI SERVER_NAME SERVER_PORT
42
43
  SERVER_PROTOCOL
43
44
  ],
44
- :send_environment_metadata => true,
45
- :send_params => true,
46
- :transaction_debug_mode => false
45
+ :send_environment_metadata => true,
46
+ :send_params => true,
47
+ :transaction_debug_mode => false
47
48
  }.freeze
48
49
 
49
50
  # @api private
@@ -62,46 +63,47 @@ module Appsignal
62
63
  }.freeze
63
64
 
64
65
  ENV_TO_KEY_MAPPING = {
65
- "APPSIGNAL_ACTIVE" => :active,
66
- "APPSIGNAL_APP_NAME" => :name,
67
- "APPSIGNAL_CA_FILE_PATH" => :ca_file_path,
68
- "APPSIGNAL_DEBUG" => :debug,
69
- "APPSIGNAL_DNS_SERVERS" => :dns_servers,
70
- "APPSIGNAL_ENABLE_ALLOCATION_TRACKING" => :enable_allocation_tracking,
71
- "APPSIGNAL_ENABLE_HOST_METRICS" => :enable_host_metrics,
72
- "APPSIGNAL_ENABLE_MINUTELY_PROBES" => :enable_minutely_probes,
73
- "APPSIGNAL_ENABLE_STATSD" => :enable_statsd,
74
- "APPSIGNAL_ENABLE_NGINX_METRICS" => :enable_nginx_metrics,
75
- "APPSIGNAL_ENABLE_GVL_GLOBAL_TIMER" => :enable_gvl_global_timer,
76
- "APPSIGNAL_ENABLE_GVL_WAITING_THREADS" => :enable_gvl_waiting_threads,
77
- "APPSIGNAL_FILES_WORLD_ACCESSIBLE" => :files_world_accessible,
78
- "APPSIGNAL_FILTER_PARAMETERS" => :filter_parameters,
79
- "APPSIGNAL_FILTER_SESSION_DATA" => :filter_session_data,
80
- "APPSIGNAL_HOSTNAME" => :hostname,
81
- "APPSIGNAL_HTTP_PROXY" => :http_proxy,
82
- "APPSIGNAL_IGNORE_ACTIONS" => :ignore_actions,
83
- "APPSIGNAL_IGNORE_ERRORS" => :ignore_errors,
84
- "APPSIGNAL_IGNORE_NAMESPACES" => :ignore_namespaces,
85
- "APPSIGNAL_INSTRUMENT_HTTP_RB" => :instrument_http_rb,
86
- "APPSIGNAL_INSTRUMENT_NET_HTTP" => :instrument_net_http,
87
- "APPSIGNAL_INSTRUMENT_REDIS" => :instrument_redis,
88
- "APPSIGNAL_INSTRUMENT_SEQUEL" => :instrument_sequel,
89
- "APPSIGNAL_LOG" => :log,
90
- "APPSIGNAL_LOG_LEVEL" => :log_level,
91
- "APPSIGNAL_LOG_PATH" => :log_path,
92
- "APPSIGNAL_LOGGING_ENDPOINT" => :logging_endpoint,
93
- "APPSIGNAL_PUSH_API_ENDPOINT" => :endpoint,
94
- "APPSIGNAL_PUSH_API_KEY" => :push_api_key,
95
- "APPSIGNAL_REQUEST_HEADERS" => :request_headers,
96
- "APPSIGNAL_RUNNING_IN_CONTAINER" => :running_in_container,
97
- "APPSIGNAL_SEND_ENVIRONMENT_METADATA" => :send_environment_metadata,
98
- "APPSIGNAL_SEND_PARAMS" => :send_params,
99
- "APPSIGNAL_SEND_SESSION_DATA" => :send_session_data,
100
- "APPSIGNAL_SKIP_SESSION_DATA" => :skip_session_data,
101
- "APPSIGNAL_TRANSACTION_DEBUG_MODE" => :transaction_debug_mode,
102
- "APPSIGNAL_WORKING_DIRECTORY_PATH" => :working_directory_path,
103
- "APPSIGNAL_WORKING_DIR_PATH" => :working_dir_path,
104
- "APP_REVISION" => :revision
66
+ "APPSIGNAL_ACTIVE" => :active,
67
+ "APPSIGNAL_APP_NAME" => :name,
68
+ "APPSIGNAL_CA_FILE_PATH" => :ca_file_path,
69
+ "APPSIGNAL_DEBUG" => :debug,
70
+ "APPSIGNAL_DNS_SERVERS" => :dns_servers,
71
+ "APPSIGNAL_ENABLE_ALLOCATION_TRACKING" => :enable_allocation_tracking,
72
+ "APPSIGNAL_ENABLE_HOST_METRICS" => :enable_host_metrics,
73
+ "APPSIGNAL_ENABLE_MINUTELY_PROBES" => :enable_minutely_probes,
74
+ "APPSIGNAL_ENABLE_STATSD" => :enable_statsd,
75
+ "APPSIGNAL_ENABLE_NGINX_METRICS" => :enable_nginx_metrics,
76
+ "APPSIGNAL_ENABLE_GVL_GLOBAL_TIMER" => :enable_gvl_global_timer,
77
+ "APPSIGNAL_ENABLE_GVL_WAITING_THREADS" => :enable_gvl_waiting_threads,
78
+ "APPSIGNAL_ENABLE_RAILS_ERROR_REPORTER" => :enable_rails_error_reporter,
79
+ "APPSIGNAL_FILES_WORLD_ACCESSIBLE" => :files_world_accessible,
80
+ "APPSIGNAL_FILTER_PARAMETERS" => :filter_parameters,
81
+ "APPSIGNAL_FILTER_SESSION_DATA" => :filter_session_data,
82
+ "APPSIGNAL_HOSTNAME" => :hostname,
83
+ "APPSIGNAL_HTTP_PROXY" => :http_proxy,
84
+ "APPSIGNAL_IGNORE_ACTIONS" => :ignore_actions,
85
+ "APPSIGNAL_IGNORE_ERRORS" => :ignore_errors,
86
+ "APPSIGNAL_IGNORE_NAMESPACES" => :ignore_namespaces,
87
+ "APPSIGNAL_INSTRUMENT_HTTP_RB" => :instrument_http_rb,
88
+ "APPSIGNAL_INSTRUMENT_NET_HTTP" => :instrument_net_http,
89
+ "APPSIGNAL_INSTRUMENT_REDIS" => :instrument_redis,
90
+ "APPSIGNAL_INSTRUMENT_SEQUEL" => :instrument_sequel,
91
+ "APPSIGNAL_LOG" => :log,
92
+ "APPSIGNAL_LOG_LEVEL" => :log_level,
93
+ "APPSIGNAL_LOG_PATH" => :log_path,
94
+ "APPSIGNAL_LOGGING_ENDPOINT" => :logging_endpoint,
95
+ "APPSIGNAL_PUSH_API_ENDPOINT" => :endpoint,
96
+ "APPSIGNAL_PUSH_API_KEY" => :push_api_key,
97
+ "APPSIGNAL_REQUEST_HEADERS" => :request_headers,
98
+ "APPSIGNAL_RUNNING_IN_CONTAINER" => :running_in_container,
99
+ "APPSIGNAL_SEND_ENVIRONMENT_METADATA" => :send_environment_metadata,
100
+ "APPSIGNAL_SEND_PARAMS" => :send_params,
101
+ "APPSIGNAL_SEND_SESSION_DATA" => :send_session_data,
102
+ "APPSIGNAL_SKIP_SESSION_DATA" => :skip_session_data,
103
+ "APPSIGNAL_TRANSACTION_DEBUG_MODE" => :transaction_debug_mode,
104
+ "APPSIGNAL_WORKING_DIRECTORY_PATH" => :working_directory_path,
105
+ "APPSIGNAL_WORKING_DIR_PATH" => :working_dir_path,
106
+ "APP_REVISION" => :revision
105
107
  }.freeze
106
108
  # @api private
107
109
  ENV_STRING_KEYS = %w[
@@ -130,6 +132,7 @@ module Appsignal
130
132
  APPSIGNAL_ENABLE_NGINX_METRICS
131
133
  APPSIGNAL_ENABLE_GVL_GLOBAL_TIMER
132
134
  APPSIGNAL_ENABLE_GVL_WAITING_THREADS
135
+ APPSIGNAL_ENABLE_RAILS_ERROR_REPORTER
133
136
  APPSIGNAL_FILES_WORLD_ACCESSIBLE
134
137
  APPSIGNAL_INSTRUMENT_HTTP_RB
135
138
  APPSIGNAL_INSTRUMENT_NET_HTTP
@@ -218,16 +221,17 @@ module Appsignal
218
221
  # Configuration load order
219
222
  # @see https://docs.appsignal.com/ruby/instrumentation/integrating-appsignal.html
220
223
  # How to integrate AppSignal manually
221
- def initialize(root_path, env, initial_config = {}, logger = Appsignal.logger, config_file = nil)
222
- @root_path = root_path
223
- @config_file = config_file
224
- @logger = logger
225
- @valid = false
226
- @config_hash = Hash[DEFAULT_CONFIG]
224
+ def initialize(root_path, env, initial_config = {}, logger = Appsignal.logger,
225
+ config_file = nil)
226
+ @root_path = root_path
227
+ @config_file = config_file
228
+ @logger = logger
229
+ @valid = false
230
+ @config_hash = DEFAULT_CONFIG.dup
227
231
  env_loaded_from_initial = env.to_s
228
232
  @env =
229
- if ENV.key?("APPSIGNAL_APP_ENV".freeze)
230
- env_loaded_from_env = ENV["APPSIGNAL_APP_ENV".freeze]
233
+ if ENV.key?("APPSIGNAL_APP_ENV")
234
+ env_loaded_from_env = ENV["APPSIGNAL_APP_ENV"]
231
235
  else
232
236
  env_loaded_from_initial
233
237
  end
@@ -275,9 +279,7 @@ module Appsignal
275
279
  end
276
280
 
277
281
  def log_level
278
- if config_hash[:debug] || config_hash[:transaction_debug_mode]
279
- level = ::Logger::DEBUG
280
- end
282
+ level = ::Logger::DEBUG if config_hash[:debug] || config_hash[:transaction_debug_mode]
281
283
  option = config_hash[:log_level]
282
284
  if option
283
285
  log_level_option = LOG_LEVEL_MAP[option]
@@ -287,20 +289,18 @@ module Appsignal
287
289
  end
288
290
 
289
291
  def log_file_path
290
- path = config_hash[:log_path] || root_path && File.join(root_path, "log")
291
- if path && File.writable?(path)
292
- return File.join(File.realpath(path), "appsignal.log")
293
- end
292
+ path = config_hash[:log_path] || (root_path && File.join(root_path, "log"))
293
+ return File.join(File.realpath(path), "appsignal.log") if path && File.writable?(path)
294
294
 
295
295
  system_tmp_dir = self.class.system_tmp_dir
296
296
  if File.writable? system_tmp_dir
297
- $stdout.puts "appsignal: Unable to log to '#{path}'. Logging to "\
298
- "'#{system_tmp_dir}' instead. Please check the "\
297
+ $stdout.puts "appsignal: Unable to log to '#{path}'. Logging to " \
298
+ "'#{system_tmp_dir}' instead. Please check the " \
299
299
  "permissions for the application's (log) directory."
300
300
  File.join(system_tmp_dir, "appsignal.log")
301
301
  else
302
- $stdout.puts "appsignal: Unable to log to '#{path}' or the "\
303
- "'#{system_tmp_dir}' fallback. Please check the permissions "\
302
+ $stdout.puts "appsignal: Unable to log to '#{path}' or the " \
303
+ "'#{system_tmp_dir}' fallback. Please check the permissions " \
304
304
  "for the application's (log) directory."
305
305
  end
306
306
  end
@@ -315,7 +315,7 @@ module Appsignal
315
315
 
316
316
  def write_to_environment # rubocop:disable Metrics/AbcSize
317
317
  ENV["_APPSIGNAL_ACTIVE"] = active?.to_s
318
- ENV["_APPSIGNAL_AGENT_PATH"] = File.expand_path("../../../ext", __FILE__).to_s
318
+ ENV["_APPSIGNAL_AGENT_PATH"] = File.expand_path("../../ext", __dir__).to_s
319
319
  ENV["_APPSIGNAL_APP_NAME"] = config_hash[:name]
320
320
  ENV["_APPSIGNAL_APP_PATH"] = root_path.to_s
321
321
  ENV["_APPSIGNAL_CA_FILE_PATH"] = config_hash[:ca_file_path].to_s
@@ -344,9 +344,13 @@ module Appsignal
344
344
  ENV["_APPSIGNAL_RUNNING_IN_CONTAINER"] = config_hash[:running_in_container].to_s
345
345
  ENV["_APPSIGNAL_SEND_ENVIRONMENT_METADATA"] = config_hash[:send_environment_metadata].to_s
346
346
  ENV["_APPSIGNAL_TRANSACTION_DEBUG_MODE"] = config_hash[:transaction_debug_mode].to_s
347
- ENV["_APPSIGNAL_WORKING_DIRECTORY_PATH"] = config_hash[:working_directory_path] if config_hash[:working_directory_path]
348
- ENV["_APPSIGNAL_WORKING_DIR_PATH"] = config_hash[:working_dir_path] if config_hash[:working_dir_path]
349
- ENV["_APP_REVISION"] = config_hash[:revision].to_s
347
+ if config_hash[:working_directory_path]
348
+ ENV["_APPSIGNAL_WORKING_DIRECTORY_PATH"] = config_hash[:working_directory_path]
349
+ end
350
+ if config_hash[:working_dir_path]
351
+ ENV["_APPSIGNAL_WORKING_DIR_PATH"] = config_hash[:working_dir_path]
352
+ end
353
+ ENV["_APP_REVISION"] = config_hash[:revision].to_s
350
354
  end
351
355
 
352
356
  def validate
@@ -392,12 +396,10 @@ module Appsignal
392
396
  return if !config_file || !File.exist?(config_file)
393
397
 
394
398
  read_options = YAML::VERSION >= "4.0.0" ? { :aliases => true } : {}
395
- configurations = YAML.load(ERB.new(IO.read(config_file)).result, **read_options)
399
+ configurations = YAML.load(ERB.new(File.read(config_file)).result, **read_options)
396
400
  config_for_this_env = configurations[env]
397
401
  if config_for_this_env
398
- config_for_this_env.each_with_object({}) do |(key, value), hash|
399
- hash[key.to_sym] = value # convert keys to symbols
400
- end
402
+ config_for_this_env.transform_keys(&:to_sym)
401
403
  else
402
404
  logger.error "Not loading from config file: config for '#{env}' not found"
403
405
  nil
@@ -428,8 +430,8 @@ module Appsignal
428
430
 
429
431
  deprecation_message \
430
432
  "The `working_dir_path` option is deprecated, please use " \
431
- "`working_directory_path` instead and specify the " \
432
- "full path to the working directory",
433
+ "`working_directory_path` instead and specify the " \
434
+ "full path to the working directory",
433
435
  logger
434
436
  end
435
437
 
@@ -438,22 +440,25 @@ module Appsignal
438
440
 
439
441
  # Configuration with string type
440
442
  ENV_STRING_KEYS.each do |var|
441
- env_var = ENV[var]
443
+ env_var = ENV.fetch(var, nil)
442
444
  next unless env_var
445
+
443
446
  config[ENV_TO_KEY_MAPPING[var]] = env_var
444
447
  end
445
448
 
446
449
  # Configuration with boolean type
447
450
  ENV_BOOLEAN_KEYS.each do |var|
448
- env_var = ENV[var]
451
+ env_var = ENV.fetch(var, nil)
449
452
  next unless env_var
453
+
450
454
  config[ENV_TO_KEY_MAPPING[var]] = env_var.casecmp("true").zero?
451
455
  end
452
456
 
453
457
  # Configuration with array of strings type
454
458
  ENV_ARRAY_KEYS.each do |var|
455
- env_var = ENV[var]
459
+ env_var = ENV.fetch(var, nil)
456
460
  next unless env_var
461
+
457
462
  config[ENV_TO_KEY_MAPPING[var]] = env_var.split(",")
458
463
  end
459
464
 
@@ -487,9 +492,7 @@ module Appsignal
487
492
 
488
493
  def merge(new_config)
489
494
  new_config.each do |key, value|
490
- unless config_hash[key].nil?
491
- @logger.debug("Config key '#{key}' is being overwritten")
492
- end
495
+ @logger.debug("Config key '#{key}' is being overwritten") unless config_hash[key].nil?
493
496
  config_hash[key] = value
494
497
  end
495
498
  end
@@ -65,7 +65,8 @@ module Appsignal
65
65
  Appsignal::Transaction::HTTP_REQUEST,
66
66
  rack_request
67
67
  )
68
- Appsignal.instrument "action_view.render", "Render hello.html.erb", "<h1>Hello world!</h1>" do
68
+ Appsignal.instrument "action_view.render", "Render hello.html.erb",
69
+ "<h1>Hello world!</h1>" do
69
70
  sleep 2
70
71
  end
71
72
  transaction.set_http_or_background_queue_start
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Appsignal
2
4
  # @api private
3
5
  class Environment
@@ -5,7 +5,7 @@ module Appsignal
5
5
  # @api private
6
6
  module ActionView
7
7
  class RenderFormatter
8
- BLANK = "".freeze
8
+ BLANK = ""
9
9
 
10
10
  attr_reader :root_path
11
11
 
@@ -15,6 +15,7 @@ module Appsignal
15
15
 
16
16
  def format(payload)
17
17
  return nil unless payload[:identifier]
18
+
18
19
  [payload[:identifier].sub(root_path, BLANK), nil]
19
20
  end
20
21
  end
@@ -7,7 +7,7 @@ module Appsignal
7
7
  class QueryFormatter
8
8
  ALLOWED = {
9
9
  "find" => {
10
- "find" => :allow,
10
+ "find" => :allow,
11
11
  "filter" => :sanitize_document
12
12
  },
13
13
  "count" => {
@@ -16,24 +16,24 @@ module Appsignal
16
16
  },
17
17
  "distinct" => {
18
18
  "distinct" => :allow,
19
- "key" => :allow,
20
- "query" => :sanitize_document
19
+ "key" => :allow,
20
+ "query" => :sanitize_document
21
21
  },
22
22
  "insert" => {
23
- "insert" => :allow,
23
+ "insert" => :allow,
24
24
  "documents" => :sanitize_document,
25
- "ordered" => :allow
25
+ "ordered" => :allow
26
26
  },
27
27
  "update" => {
28
- "update" => :allow,
28
+ "update" => :allow,
29
29
  "updates" => :sanitize_document,
30
30
  "ordered" => :allow
31
31
  },
32
32
  "findandmodify" => {
33
33
  "findandmodify" => :allow,
34
- "query" => :sanitize_document,
35
- "update" => :sanitize_document,
36
- "new" => :allow
34
+ "query" => :sanitize_document,
35
+ "update" => :sanitize_document,
36
+ "new" => :allow
37
37
  },
38
38
  "delete" => {
39
39
  "delete" => :allow,
@@ -41,10 +41,10 @@ module Appsignal
41
41
  "ordered" => :allow
42
42
  },
43
43
  "bulk" => {
44
- "q" => :sanitize_document,
45
- "u" => :sanitize_document,
46
- "limit" => :allow,
47
- "multi" => :allow,
44
+ "q" => :sanitize_document,
45
+ "u" => :sanitize_document,
46
+ "limit" => :allow,
47
+ "multi" => :allow,
48
48
  "upsert" => :allow
49
49
  }
50
50
  }.freeze
@@ -27,8 +27,8 @@ module Appsignal
27
27
  def register(name, formatter = nil)
28
28
  if registered?(name, formatter)
29
29
  logger.warn(
30
- "Formatter for '#{name}' already registered, not registering "\
31
- "'#{formatter.name}'"
30
+ "Formatter for '#{name}' already registered, not registering " \
31
+ "'#{formatter.name}'"
32
32
  )
33
33
  return
34
34
  end
@@ -53,7 +53,7 @@ module Appsignal
53
53
 
54
54
  def format(name, payload)
55
55
  formatter = formatters[name]
56
- formatter.format(payload) unless formatter.nil?
56
+ formatter&.format(payload)
57
57
  end
58
58
 
59
59
  private
@@ -63,6 +63,7 @@ module Appsignal
63
63
  if !format_method || format_method.arity != 1
64
64
  raise "#{formatter} does not have a format(payload) method"
65
65
  end
66
+
66
67
  formatter_classes[name] = formatter
67
68
  formatters[name] = formatter.new
68
69
  rescue => ex
@@ -83,6 +84,6 @@ module Appsignal
83
84
  end
84
85
  end
85
86
 
86
- Dir.glob(File.expand_path("../event_formatter/**/*.rb", __FILE__)).each do |file|
87
+ Dir.glob(File.expand_path("event_formatter/**/*.rb", __dir__)).each do |file|
87
88
  require file
88
89
  end
@@ -23,9 +23,7 @@ module Appsignal
23
23
  end
24
24
 
25
25
  def make_appsignal_string(ruby_string)
26
- unless ruby_string.is_a?(String)
27
- raise ArgumentError, "argument is not a string"
28
- end
26
+ raise ArgumentError, "argument is not a string" unless ruby_string.is_a?(String)
29
27
 
30
28
  AppsignalString.new.tap do |appsignal_string|
31
29
  appsignal_string[:len] = ruby_string.bytesize
@@ -102,16 +100,19 @@ module Appsignal
102
100
  [:pointer, :long],
103
101
  :void
104
102
  attach_function :appsignal_finish_event,
105
- [:pointer, :appsignal_string, :appsignal_string, :appsignal_string, :int64, :long],
103
+ [:pointer, :appsignal_string, :appsignal_string, :appsignal_string, :int64,
104
+ :long],
106
105
  :void
107
106
  attach_function :appsignal_finish_event_data,
108
107
  [:pointer, :appsignal_string, :appsignal_string, :pointer, :int64, :long],
109
108
  :void
110
109
  attach_function :appsignal_record_event,
111
- [:pointer, :appsignal_string, :appsignal_string, :appsignal_string, :int64, :long, :long],
110
+ [:pointer, :appsignal_string, :appsignal_string, :appsignal_string, :int64,
111
+ :long, :long],
112
112
  :void
113
113
  attach_function :appsignal_record_event_data,
114
- [:pointer, :appsignal_string, :appsignal_string, :pointer, :int64, :long, :long],
114
+ [:pointer, :appsignal_string, :appsignal_string, :pointer, :int64, :long,
115
+ :long],
115
116
  :void
116
117
  attach_function :appsignal_set_transaction_error,
117
118
  [:pointer, :appsignal_string, :appsignal_string, :pointer],
@@ -291,6 +292,7 @@ module Appsignal
291
292
  )
292
293
 
293
294
  return if !transaction || transaction.null?
295
+
294
296
  Transaction.new(transaction)
295
297
  end
296
298
 
@@ -333,7 +335,7 @@ module Appsignal
333
335
  appsignal_add_distribution_value(make_appsignal_string(key), value, tags.pointer)
334
336
  end
335
337
 
336
- class Transaction # rubocop:disable Metrics/ClassLength
338
+ class Transaction
337
339
  include StringHelpers
338
340
 
339
341
  attr_reader :pointer
@@ -447,7 +449,7 @@ module Appsignal
447
449
  Extension.appsignal_complete_transaction(pointer)
448
450
  end
449
451
 
450
- def to_json
452
+ def to_json # rubocop:disable Lint/ToJSON
451
453
  json = Extension.appsignal_transaction_to_json(pointer)
452
454
  make_ruby_string(json) if json[:len] > 0
453
455
  end
@@ -531,7 +533,7 @@ module Appsignal
531
533
  )
532
534
  end
533
535
 
534
- def to_json
536
+ def to_json # rubocop:disable Lint/ToJSON
535
537
  json = Extension.appsignal_span_to_json(pointer)
536
538
  make_ruby_string(json) if json[:len] > 0
537
539
  end
@@ -34,7 +34,7 @@ module Appsignal
34
34
  #
35
35
  # Disabled in testing so we can make sure that we don't miss a extension
36
36
  # function implementation.
37
- def method_missing(m, *args, &block)
37
+ def method_missing(_method, *args, &block)
38
38
  super if Appsignal.testing?
39
39
  end
40
40