appsignal 3.10.0 → 3.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/CHANGELOG.md +88 -0
  4. data/Gemfile +1 -0
  5. data/benchmark.rake +99 -42
  6. data/lib/appsignal/cli/demo.rb +0 -1
  7. data/lib/appsignal/config.rb +54 -98
  8. data/lib/appsignal/demo.rb +15 -20
  9. data/lib/appsignal/event_formatter/rom/sql_formatter.rb +1 -0
  10. data/lib/appsignal/event_formatter.rb +3 -2
  11. data/lib/appsignal/helpers/instrumentation.rb +331 -19
  12. data/lib/appsignal/hooks/action_cable.rb +21 -16
  13. data/lib/appsignal/hooks/active_job.rb +14 -8
  14. data/lib/appsignal/hooks/delayed_job.rb +1 -1
  15. data/lib/appsignal/hooks/shoryuken.rb +3 -63
  16. data/lib/appsignal/integrations/action_cable.rb +5 -7
  17. data/lib/appsignal/integrations/active_support_notifications.rb +1 -0
  18. data/lib/appsignal/integrations/capistrano/capistrano_2_tasks.rb +36 -35
  19. data/lib/appsignal/integrations/data_mapper.rb +1 -0
  20. data/lib/appsignal/integrations/delayed_job_plugin.rb +27 -33
  21. data/lib/appsignal/integrations/dry_monitor.rb +1 -0
  22. data/lib/appsignal/integrations/excon.rb +1 -0
  23. data/lib/appsignal/integrations/http.rb +1 -0
  24. data/lib/appsignal/integrations/net_http.rb +1 -0
  25. data/lib/appsignal/integrations/object.rb +6 -0
  26. data/lib/appsignal/integrations/que.rb +13 -20
  27. data/lib/appsignal/integrations/railtie.rb +1 -1
  28. data/lib/appsignal/integrations/rake.rb +1 -5
  29. data/lib/appsignal/integrations/redis.rb +1 -0
  30. data/lib/appsignal/integrations/redis_client.rb +1 -0
  31. data/lib/appsignal/integrations/resque.rb +2 -5
  32. data/lib/appsignal/integrations/shoryuken.rb +75 -0
  33. data/lib/appsignal/integrations/sidekiq.rb +7 -15
  34. data/lib/appsignal/integrations/unicorn.rb +1 -0
  35. data/lib/appsignal/integrations/webmachine.rb +2 -5
  36. data/lib/appsignal/logger.rb +7 -3
  37. data/lib/appsignal/probes/helpers.rb +1 -0
  38. data/lib/appsignal/probes/mri.rb +1 -0
  39. data/lib/appsignal/probes/sidekiq.rb +1 -0
  40. data/lib/appsignal/probes.rb +3 -0
  41. data/lib/appsignal/rack/abstract_middleware.rb +18 -12
  42. data/lib/appsignal/rack/event_handler.rb +39 -8
  43. data/lib/appsignal/rack/generic_instrumentation.rb +1 -0
  44. data/lib/appsignal/rack/grape_middleware.rb +2 -1
  45. data/lib/appsignal/rack/streaming_listener.rb +1 -0
  46. data/lib/appsignal/rack.rb +29 -0
  47. data/lib/appsignal/span.rb +1 -0
  48. data/lib/appsignal/transaction.rb +308 -101
  49. data/lib/appsignal/utils/data.rb +0 -1
  50. data/lib/appsignal/utils/hash_sanitizer.rb +0 -1
  51. data/lib/appsignal/utils/integration_logger.rb +0 -13
  52. data/lib/appsignal/utils/integration_memory_logger.rb +0 -13
  53. data/lib/appsignal/utils/json.rb +0 -1
  54. data/lib/appsignal/utils/query_params_sanitizer.rb +0 -1
  55. data/lib/appsignal/utils/stdout_and_logger_message.rb +0 -1
  56. data/lib/appsignal/utils.rb +6 -0
  57. data/lib/appsignal/version.rb +1 -1
  58. data/lib/appsignal.rb +6 -5
  59. data/spec/lib/appsignal/capistrano2_spec.rb +1 -1
  60. data/spec/lib/appsignal/config_spec.rb +138 -43
  61. data/spec/lib/appsignal/hooks/action_cable_spec.rb +43 -74
  62. data/spec/lib/appsignal/hooks/activejob_spec.rb +9 -0
  63. data/spec/lib/appsignal/hooks/delayed_job_spec.rb +2 -443
  64. data/spec/lib/appsignal/hooks/shoryuken_spec.rb +0 -171
  65. data/spec/lib/appsignal/integrations/delayed_job_plugin_spec.rb +459 -0
  66. data/spec/lib/appsignal/integrations/que_spec.rb +3 -4
  67. data/spec/lib/appsignal/integrations/shoryuken_spec.rb +167 -0
  68. data/spec/lib/appsignal/integrations/sidekiq_spec.rb +4 -4
  69. data/spec/lib/appsignal/integrations/webmachine_spec.rb +13 -1
  70. data/spec/lib/appsignal/rack/abstract_middleware_spec.rb +48 -3
  71. data/spec/lib/appsignal/rack/event_handler_spec.rb +81 -10
  72. data/spec/lib/appsignal/rack/rails_instrumentation_spec.rb +4 -2
  73. data/spec/lib/appsignal/rack_spec.rb +63 -0
  74. data/spec/lib/appsignal/transaction_spec.rb +1634 -1071
  75. data/spec/lib/appsignal/utils/integration_logger_spec.rb +12 -16
  76. data/spec/lib/appsignal/utils/integration_memory_logger_spec.rb +0 -10
  77. data/spec/lib/appsignal_spec.rb +323 -10
  78. data/spec/support/helpers/transaction_helpers.rb +44 -20
  79. data/spec/support/matchers/transaction.rb +15 -1
  80. data/spec/support/testing.rb +1 -1
  81. metadata +6 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a4767b1d66b7aa4d47b79e83265b1e2631b9733f730e392b109d9d563013c79
4
- data.tar.gz: 231bc55dfcd8084175fb505470b266937363de1e833852dd539d2970aad36d22
3
+ metadata.gz: 58edd9ab16d90269a61e7e485e51078b05b60b2192461408d415eafd8327fb04
4
+ data.tar.gz: 92520f55157b13bbe61a98cbcc61901c3c016854a436bd4ae01ad9563d92bf9a
5
5
  SHA512:
6
- metadata.gz: 3116383c605eb524838419ca4911ad2a06ef2b2289d1b88705107c51595edcc749270fa824bc79552c6e255524409630ab477fd9fd6ab72fabf3e7a9ebd6025a
7
- data.tar.gz: 471f59339ae58c4a45bcad29560e04397dd646efa7b9269167ed142c773c92018e2e34288d931c14c2a4ec3045f068f760e687179034464a8dda3001fb689244
6
+ metadata.gz: 502fd7ada9029f2ecacb0368e8bfe8128fa7792031f1c567f73c05e2381aa1fbc9f946bd7b574352e0114413c724cace05758854725130101122121200ceaaff
7
+ data.tar.gz: 1d90ec5300a657522de4ec3298b3db22a60aadecafda35ffe38ffed72b1ae1d311e590a502ef6d002e99897f2d453e1b0c1d3c9f8569eebd9aa3d90610fce77e
data/.rubocop.yml CHANGED
@@ -6,6 +6,7 @@ AllCops:
6
6
  Include:
7
7
  - "**/*.rb"
8
8
  - "**/*.cap"
9
+ - "**/*.rake"
9
10
  - "**/Gemfile"
10
11
  - "**/Rakefile"
11
12
  - "appsignal.gemspec"
@@ -13,7 +14,6 @@ AllCops:
13
14
  - "pkg/**/*"
14
15
  - "tmp/**/*"
15
16
  - "vendor/**/*"
16
- - "benchmark.rake"
17
17
  - "spec/integration/diagnose/**/*"
18
18
  DisplayCopNames: true
19
19
  UseCache: true
data/CHANGELOG.md CHANGED
@@ -1,5 +1,93 @@
1
1
  # AppSignal for Ruby gem Changelog
2
2
 
3
+ ## 3.11.0
4
+
5
+ _Published on 2024-07-15._
6
+
7
+ ### Added
8
+
9
+ - Add `Appsignal.monitor` and `Appsignal.monitor_and_stop` instrumentation helpers. These helpers are a replacement for the `Appsignal.monitor_transaction` and `Appsignal.monitor_single_transaction` helpers.
10
+
11
+ Use these new helpers to create an AppSignal transaction and track any exceptions that occur within the instrumented block. This new helper supports custom namespaces and has a simpler way to set an action name. Use this helper in combination with our other `Appsignal.set_*` helpers to add more metadata to the transaction.
12
+
13
+ ```ruby
14
+ # New helper
15
+ Appsignal.monitor(
16
+ :namespace => "my_namespace",
17
+ :action => "MyClass#my_method"
18
+ ) do
19
+ # Track an instrumentation event
20
+ Appsignal.instrument("my_event.my_group") do
21
+ # Some code
22
+ end
23
+ end
24
+
25
+ # Old helper
26
+ Appsignal.monitor_transaction(
27
+ "process_action.my_group",
28
+ :class_name => "MyClass",
29
+ :action_name => "my_method"
30
+ ) do
31
+ # Some code
32
+ end
33
+ ```
34
+
35
+ The `Appsignal.monitor_and_stop` helper can be used in the same scenarios as the `Appsignal.monitor_single_transaction` helper is used. One-off Ruby scripts that are not part of a long running process.
36
+
37
+ Read our [instrumentation documentation](https://docs.appsignal.com/ruby/instrumentation/background-jobs.html) for more information about using the`Appsignal.monitor` helper.
38
+
39
+ (minor [f38f0cff](https://github.com/appsignal/appsignal-ruby/commit/f38f0cff978c7e7244beae347a8355fff19b13f1))
40
+ - Add `Appsignal.set_session_data` helper. Set custom session data on the current transaction with the `Appsignal.set_session_data` helper. Note that this will overwrite any request session data that would be set automatically on the transaction. When this method is called multiple times, it will overwrite the previously set value.
41
+
42
+ ```ruby
43
+ Appsignal.set_session_data("data1" => "value1", "data2" => "value2")
44
+ ```
45
+
46
+ (patch [48c76635](https://github.com/appsignal/appsignal-ruby/commit/48c76635043a3777de79816bdb2154ad392c1b09))
47
+ - Add `Appsignal.set_headers` helper. Set custom request headers on the current transaction with the `Appsignal.set_headers` helper. Note that this will overwrite any request headers that would be set automatically on the transaction. When this method is called multiple times, it will overwrite the previously set value.
48
+
49
+ ```ruby
50
+ Appsignal.set_headers("PATH_INFO" => "/some-path", "HTTP_USER_AGENT" => "Firefox")
51
+ ```
52
+
53
+ (patch [7d82dffd](https://github.com/appsignal/appsignal-ruby/commit/7d82dffd75a6c7c9a8b6a8fac7e6bbb70104b63c))
54
+ - Report request headers for webmachine apps. (patch [fcfb7a0d](https://github.com/appsignal/appsignal-ruby/commit/fcfb7a0d2545a2144aa61efa61d445c0e11c7749))
55
+
56
+ ### Changed
57
+
58
+ - Allow tags to have boolean (true/false) values.
59
+
60
+ ```ruby
61
+ Appsignal.set_tags("my_tag_is_amazing" => true)
62
+ Appsignal.set_tags("my_tag_is_false" => false)
63
+ ```
64
+
65
+ (patch [1b8e86cb](https://github.com/appsignal/appsignal-ruby/commit/1b8e86cba3472ebec78680ca6a2ed8aa76938724))
66
+ - Optimize Sidekiq job arguments being recorded. Job arguments are only fetched and set when we sample the job transaction, which should decrease our overhead for all jobs we don't sample. (patch [3f957301](https://github.com/appsignal/appsignal-ruby/commit/3f95730145d6eef7eb13901853685e4d56d5495c))
67
+
68
+ ### Deprecated
69
+
70
+ - Deprecate Transaction sample helpers: `Transaction#set_sample_data` and `Transaction#sample_data`. Please use one of the other sample data helpers instead. See our [sample data guide](https://docs.appsignal.com/guides/custom-data/sample-data.html). (patch [2d2e0e43](https://github.com/appsignal/appsignal-ruby/commit/2d2e0e43c9125b4566e3265b6e6ae85e4910652b))
71
+ - Deprecate the `Appsignal::Transaction#set_http_or_background_queue_start` method. Use the `Appsignal::Transaction#set_queue_start` helper instead. (patch [d93e0370](https://github.com/appsignal/appsignal-ruby/commit/d93e0370ff4e37cf8d12652a6e5cca66651a5790))
72
+ - Deprecate the `Appsignal.without_instrumentation` helper. Use the `Appsignal.ignore_instrumentation_events` helper instead. (patch [7cc3c0e4](https://github.com/appsignal/appsignal-ruby/commit/7cc3c0e41615394deec348d5e0a40b7a6c1fc1d9))
73
+ - Deprecate the `Appsignal::Transaction::GenericRequest` class. Use the `Appsignal.set_*` helpers to set metadata on the Transaction instead. Read our [sample data guide](https://docs.appsignal.com/guides/custom-data/sample-data.html) for more information. (patch [1c69d3fd](https://github.com/appsignal/appsignal-ruby/commit/1c69d3fdf47959c240c4732f7e8551802a9eba63))
74
+ - Deprecate the 'ID', 'request', and 'options' arguments for the `Transaction.create` and `Transaction.new` methods. To add metadata to the transaction, use the `Appsignal.set_*` helpers. Read our [sample data guide](https://docs.appsignal.com/guides/custom-data/sample-data.html) for more information on how to set metadata on transactions.
75
+
76
+ ```ruby
77
+ # Before
78
+ Appsignal::Transaction.create(
79
+ SecureRandom.uuid,
80
+ "my_namespace",
81
+ Appsignal::Transaction::GenericRequest.new(env) # env is a request env Hash
82
+ )
83
+
84
+ # After
85
+ Appsignal::Transaction.create("my_namespace")
86
+ ```
87
+
88
+ (patch [2fc2c617](https://github.com/appsignal/appsignal-ruby/commit/2fc2c617321bc6a520205cae0cfa42fb3c8fc5d8))
89
+ - Deprecate the `Appsignal.monitor_transaction` and `Appsignal.monitor_single_transaction` helpers. See the entry about the replacement helpers `Appsignal.monitor` and `Appsignal.monitor_and_stop`. (patch [470d5813](https://github.com/appsignal/appsignal-ruby/commit/470d58132270115215093c9cffd16e52829ef4c4))
90
+
3
91
  ## 3.10.0
4
92
 
5
93
  _Published on 2024-07-08._
data/Gemfile CHANGED
@@ -4,6 +4,7 @@ source "https://rubygems.org"
4
4
 
5
5
  gemspec
6
6
 
7
+ gem "benchmark-ips"
7
8
  # Fix install issue for jruby on gem 3.1.8.
8
9
  # No java stub is published.
9
10
  gem "bigdecimal", "3.1.7" if RUBY_PLATFORM == "java"
data/benchmark.rake CHANGED
@@ -1,5 +1,12 @@
1
- require 'appsignal'
2
- require 'benchmark'
1
+ # frozen_string_literal: true
2
+
3
+ # Run using: rake --rakefile benchmark.rake [tasks]
4
+
5
+ $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), "lib"))
6
+
7
+ require "benchmark"
8
+ require "benchmark/ips"
9
+ require "appsignal"
3
10
 
4
11
  def process_rss
5
12
  `ps -o rss= -p #{Process.pid}`.to_i
@@ -7,35 +14,110 @@ end
7
14
 
8
15
  GC.disable
9
16
 
10
- task :default => :'benchmark:all'
17
+ task :default => :"benchmark:all"
11
18
 
12
19
  namespace :benchmark do
13
- task :all => [:run_inactive, :run_active]
20
+ task :all => [:memory_inactive, :memory_active, :ips]
14
21
 
15
- task :run_inactive do
16
- puts 'Running with appsignal off'
17
- ENV['APPSIGNAL_PUSH_API_KEY'] = nil
22
+ task :memory_inactive do
23
+ puts "Memory benchmark with AppSignal off"
24
+ ENV["APPSIGNAL_PUSH_API_KEY"] = nil
18
25
  run_benchmark
19
26
  end
20
27
 
21
- task :run_active do
22
- puts 'Running with appsignal on'
23
- ENV['APPSIGNAL_PUSH_API_KEY'] = 'something'
28
+ task :memory_active do
29
+ puts "Memory benchmark with AppSignal on"
30
+ ENV["APPSIGNAL_PUSH_API_KEY"] = "something"
24
31
  run_benchmark
25
32
  end
33
+
34
+ task :ips do
35
+ puts "Iterations per second benchmark"
36
+ start_agent
37
+ Benchmark.ips do |x|
38
+ x.config(
39
+ :time => 5,
40
+ :warmup => 2
41
+ )
42
+
43
+ x.report("monitor transaction inactive") do |times|
44
+ ENV["APPSIGNAL_PUSH_API_KEY"] = nil
45
+
46
+ monitor_transaction("transaction_#{times}")
47
+ end
48
+
49
+ x.report("monitor transaction active") do |times|
50
+ ENV["APPSIGNAL_PUSH_API_KEY"] = "something"
51
+
52
+ monitor_transaction("transaction_#{times}")
53
+ end
54
+
55
+ x.compare!
56
+ end
57
+ end
58
+ end
59
+
60
+ def start_agent
61
+ Appsignal.config = Appsignal::Config.new(
62
+ Dir.pwd,
63
+ "production",
64
+ :endpoint => "http://localhost:8080"
65
+ )
66
+ Appsignal.start
67
+ end
68
+
69
+ def monitor_transaction(transaction_id)
70
+ transaction = Appsignal::Transaction.create(
71
+ transaction_id,
72
+ Appsignal::Transaction::HTTP_REQUEST
73
+ )
74
+ transaction.set_action("HomeController#show")
75
+ transaction.set_params(:id => 1)
76
+
77
+ Appsignal.instrument("process_action.action_controller") do
78
+ Appsignal.instrument_sql(
79
+ "sql.active_record",
80
+ nil,
81
+ "SELECT `users`.* FROM `users` WHERE `users`.`id` = ?"
82
+ )
83
+ 10.times do
84
+ Appsignal.instrument_sql(
85
+ "sql.active_record",
86
+ nil,
87
+ "SELECT `todos`.* FROM `todos` WHERE `todos`.`id` = ?"
88
+ )
89
+ end
90
+
91
+ Appsignal.instrument(
92
+ "render_template.action_view",
93
+ "app/views/home/show.html.erb"
94
+ ) do
95
+ 5.times do
96
+ Appsignal.instrument(
97
+ "render_partial.action_view",
98
+ "app/views/home/_piece.html.erb"
99
+ ) do
100
+ 3.times do
101
+ Appsignal.instrument("cache.read")
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
107
+
108
+ Appsignal::Transaction.complete_current!
26
109
  end
27
110
 
28
111
  def run_benchmark
29
- no_transactions = (ENV['NO_TRANSACTIONS'] || 100_000).to_i
30
- no_threads = (ENV['NO_THREADS'] || 1).to_i
112
+ no_transactions = (ENV["NO_TRANSACTIONS"] || 100_000).to_i
113
+ no_threads = (ENV["NO_THREADS"] || 1).to_i
31
114
 
32
115
  total_objects = ObjectSpace.count_objects[:TOTAL]
33
116
  puts "Initializing, currently #{total_objects} objects"
34
117
  puts "RSS: #{process_rss}"
35
118
 
36
- Appsignal.config = Appsignal::Config.new(Dir.pwd, 'production', :endpoint => 'http://localhost:8080')
37
- Appsignal.start
38
- puts "Appsignal #{Appsignal.active? ? 'active' : 'not active'}"
119
+ start_agent
120
+ puts "Appsignal #{Appsignal.active? ? "active" : "not active"}"
39
121
 
40
122
  threads = []
41
123
  puts "Running #{no_transactions} normal transactions in #{no_threads} threads"
@@ -43,39 +125,14 @@ def run_benchmark
43
125
  no_threads.times do
44
126
  thread = Thread.new do
45
127
  no_transactions.times do |i|
46
- request = Appsignal::Transaction::GenericRequest.new(
47
- :controller => 'HomeController',
48
- :action => 'show',
49
- :params => {:id => 1}
50
- )
51
- Appsignal::Transaction.create("transaction_#{i}", Appsignal::Transaction::HTTP_REQUEST, request)
52
-
53
- Appsignal.instrument('process_action.action_controller') do
54
- Appsignal.instrument_sql('sql.active_record', nil, 'SELECT `users`.* FROM `users` WHERE `users`.`id` = ?')
55
- 10.times do
56
- Appsignal.instrument_sql('sql.active_record', nil, 'SELECT `todos`.* FROM `todos` WHERE `todos`.`id` = ?')
57
- end
58
-
59
- Appsignal.instrument('render_template.action_view', 'app/views/home/show.html.erb') do
60
- 5.times do
61
- Appsignal.instrument('render_partial.action_view', 'app/views/home/_piece.html.erb') do
62
- 3.times do
63
- Appsignal.instrument('cache.read')
64
- end
65
- end
66
- end
67
- end
68
- end
69
-
70
- Appsignal::Transaction.complete_current!
128
+ monitor_transaction("transaction_#{i}")
71
129
  end
72
130
  end
73
131
  thread.abort_on_exception = true
74
132
  threads << thread
75
133
  end
76
-
77
134
  threads.each(&:join)
78
- puts 'Finished'
135
+ puts "Finished"
79
136
  end)
80
137
 
81
138
  puts "Done, currently #{ObjectSpace.count_objects[:TOTAL] - total_objects} objects created"
@@ -39,7 +39,6 @@ module Appsignal
39
39
  # AppSignal demo documentation
40
40
  # @see https://docs.appsignal.com/support/debugging.html
41
41
  # Debugging AppSignal guide
42
- # @api private
43
42
  class Demo
44
43
  class << self
45
44
  # @param options [Hash]
@@ -10,6 +10,7 @@ module Appsignal
10
10
  class Config
11
11
  include Appsignal::Utils::StdoutAndLoggerMessage
12
12
 
13
+ # @api private
13
14
  DEFAULT_CONFIG = {
14
15
  :activejob_report_errors => "all",
15
16
  :ca_file_path => File.expand_path(File.join("../../../resources/cacert.pem"), __FILE__),
@@ -67,15 +68,31 @@ module Appsignal
67
68
  "trace" => ::Logger::DEBUG
68
69
  }.freeze
69
70
 
70
- ENV_TO_KEY_MAPPING = {
71
- "APPSIGNAL_ACTIVE" => :active,
71
+ # @api private
72
+ ENV_STRING_KEYS = {
72
73
  "APPSIGNAL_ACTIVEJOB_REPORT_ERRORS" => :activejob_report_errors,
73
74
  "APPSIGNAL_APP_NAME" => :name,
74
75
  "APPSIGNAL_BIND_ADDRESS" => :bind_address,
75
76
  "APPSIGNAL_CA_FILE_PATH" => :ca_file_path,
76
- "APPSIGNAL_CPU_COUNT" => :cpu_count,
77
+ "APPSIGNAL_HOSTNAME" => :hostname,
78
+ "APPSIGNAL_HOST_ROLE" => :host_role,
79
+ "APPSIGNAL_HTTP_PROXY" => :http_proxy,
80
+ "APPSIGNAL_LOG" => :log,
81
+ "APPSIGNAL_LOG_LEVEL" => :log_level,
82
+ "APPSIGNAL_LOG_PATH" => :log_path,
83
+ "APPSIGNAL_LOGGING_ENDPOINT" => :logging_endpoint,
84
+ "APPSIGNAL_PUSH_API_ENDPOINT" => :endpoint,
85
+ "APPSIGNAL_PUSH_API_KEY" => :push_api_key,
86
+ "APPSIGNAL_SIDEKIQ_REPORT_ERRORS" => :sidekiq_report_errors,
87
+ "APPSIGNAL_STATSD_PORT" => :statsd_port,
88
+ "APPSIGNAL_WORKING_DIRECTORY_PATH" => :working_directory_path,
89
+ "APPSIGNAL_WORKING_DIR_PATH" => :working_dir_path,
90
+ "APP_REVISION" => :revision
91
+ }.freeze
92
+ # @api private
93
+ ENV_BOOLEAN_KEYS = {
94
+ "APPSIGNAL_ACTIVE" => :active,
77
95
  "APPSIGNAL_DEBUG" => :debug,
78
- "APPSIGNAL_DNS_SERVERS" => :dns_servers,
79
96
  "APPSIGNAL_ENABLE_ALLOCATION_TRACKING" => :enable_allocation_tracking,
80
97
  "APPSIGNAL_ENABLE_HOST_METRICS" => :enable_host_metrics,
81
98
  "APPSIGNAL_ENABLE_MINUTELY_PROBES" => :enable_minutely_probes,
@@ -87,100 +104,33 @@ module Appsignal
87
104
  "APPSIGNAL_ENABLE_RAKE_PERFORMANCE_INSTRUMENTATION" =>
88
105
  :enable_rake_performance_instrumentation,
89
106
  "APPSIGNAL_FILES_WORLD_ACCESSIBLE" => :files_world_accessible,
90
- "APPSIGNAL_FILTER_METADATA" => :filter_metadata,
91
- "APPSIGNAL_FILTER_PARAMETERS" => :filter_parameters,
92
- "APPSIGNAL_FILTER_SESSION_DATA" => :filter_session_data,
93
- "APPSIGNAL_HOSTNAME" => :hostname,
94
- "APPSIGNAL_HOST_ROLE" => :host_role,
95
- "APPSIGNAL_HTTP_PROXY" => :http_proxy,
96
- "APPSIGNAL_IGNORE_ACTIONS" => :ignore_actions,
97
- "APPSIGNAL_IGNORE_ERRORS" => :ignore_errors,
98
- "APPSIGNAL_IGNORE_LOGS" => :ignore_logs,
99
- "APPSIGNAL_IGNORE_NAMESPACES" => :ignore_namespaces,
100
107
  "APPSIGNAL_INSTRUMENT_HTTP_RB" => :instrument_http_rb,
101
108
  "APPSIGNAL_INSTRUMENT_NET_HTTP" => :instrument_net_http,
102
109
  "APPSIGNAL_INSTRUMENT_REDIS" => :instrument_redis,
103
110
  "APPSIGNAL_INSTRUMENT_SEQUEL" => :instrument_sequel,
104
- "APPSIGNAL_LOG" => :log,
105
- "APPSIGNAL_LOG_LEVEL" => :log_level,
106
- "APPSIGNAL_LOG_PATH" => :log_path,
107
- "APPSIGNAL_LOGGING_ENDPOINT" => :logging_endpoint,
108
- "APPSIGNAL_PUSH_API_ENDPOINT" => :endpoint,
109
- "APPSIGNAL_PUSH_API_KEY" => :push_api_key,
110
- "APPSIGNAL_REQUEST_HEADERS" => :request_headers,
111
111
  "APPSIGNAL_RUNNING_IN_CONTAINER" => :running_in_container,
112
112
  "APPSIGNAL_SEND_ENVIRONMENT_METADATA" => :send_environment_metadata,
113
113
  "APPSIGNAL_SEND_PARAMS" => :send_params,
114
114
  "APPSIGNAL_SEND_SESSION_DATA" => :send_session_data,
115
- "APPSIGNAL_SIDEKIQ_REPORT_ERRORS" => :sidekiq_report_errors,
116
115
  "APPSIGNAL_SKIP_SESSION_DATA" => :skip_session_data,
117
- "APPSIGNAL_STATSD_PORT" => :statsd_port,
118
- "APPSIGNAL_TRANSACTION_DEBUG_MODE" => :transaction_debug_mode,
119
- "APPSIGNAL_WORKING_DIRECTORY_PATH" => :working_directory_path,
120
- "APPSIGNAL_WORKING_DIR_PATH" => :working_dir_path,
121
- "APP_REVISION" => :revision
116
+ "APPSIGNAL_TRANSACTION_DEBUG_MODE" => :transaction_debug_mode
122
117
  }.freeze
123
118
  # @api private
124
- ENV_STRING_KEYS = %w[
125
- APPSIGNAL_ACTIVEJOB_REPORT_ERRORS
126
- APPSIGNAL_APP_NAME
127
- APPSIGNAL_BIND_ADDRESS
128
- APPSIGNAL_CA_FILE_PATH
129
- APPSIGNAL_HOSTNAME
130
- APPSIGNAL_HOST_ROLE
131
- APPSIGNAL_HTTP_PROXY
132
- APPSIGNAL_LOG
133
- APPSIGNAL_LOG_LEVEL
134
- APPSIGNAL_LOG_PATH
135
- APPSIGNAL_LOGGING_ENDPOINT
136
- APPSIGNAL_PUSH_API_ENDPOINT
137
- APPSIGNAL_PUSH_API_KEY
138
- APPSIGNAL_SIDEKIQ_REPORT_ERRORS
139
- APPSIGNAL_STATSD_PORT
140
- APPSIGNAL_WORKING_DIRECTORY_PATH
141
- APPSIGNAL_WORKING_DIR_PATH
142
- APP_REVISION
143
- ].freeze
144
- # @api private
145
- ENV_BOOLEAN_KEYS = %w[
146
- APPSIGNAL_ACTIVE
147
- APPSIGNAL_DEBUG
148
- APPSIGNAL_ENABLE_ALLOCATION_TRACKING
149
- APPSIGNAL_ENABLE_HOST_METRICS
150
- APPSIGNAL_ENABLE_MINUTELY_PROBES
151
- APPSIGNAL_ENABLE_STATSD
152
- APPSIGNAL_ENABLE_NGINX_METRICS
153
- APPSIGNAL_ENABLE_GVL_GLOBAL_TIMER
154
- APPSIGNAL_ENABLE_GVL_WAITING_THREADS
155
- APPSIGNAL_ENABLE_RAILS_ERROR_REPORTER
156
- APPSIGNAL_ENABLE_RAKE_PERFORMANCE_INSTRUMENTATION
157
- APPSIGNAL_FILES_WORLD_ACCESSIBLE
158
- APPSIGNAL_INSTRUMENT_HTTP_RB
159
- APPSIGNAL_INSTRUMENT_NET_HTTP
160
- APPSIGNAL_INSTRUMENT_REDIS
161
- APPSIGNAL_INSTRUMENT_SEQUEL
162
- APPSIGNAL_RUNNING_IN_CONTAINER
163
- APPSIGNAL_SEND_ENVIRONMENT_METADATA
164
- APPSIGNAL_SEND_PARAMS
165
- APPSIGNAL_SEND_SESSION_DATA
166
- APPSIGNAL_SKIP_SESSION_DATA
167
- APPSIGNAL_TRANSACTION_DEBUG_MODE
168
- ].freeze
119
+ ENV_ARRAY_KEYS = {
120
+ "APPSIGNAL_DNS_SERVERS" => :dns_servers,
121
+ "APPSIGNAL_FILTER_METADATA" => :filter_metadata,
122
+ "APPSIGNAL_FILTER_PARAMETERS" => :filter_parameters,
123
+ "APPSIGNAL_FILTER_SESSION_DATA" => :filter_session_data,
124
+ "APPSIGNAL_IGNORE_ACTIONS" => :ignore_actions,
125
+ "APPSIGNAL_IGNORE_ERRORS" => :ignore_errors,
126
+ "APPSIGNAL_IGNORE_LOGS" => :ignore_logs,
127
+ "APPSIGNAL_IGNORE_NAMESPACES" => :ignore_namespaces,
128
+ "APPSIGNAL_REQUEST_HEADERS" => :request_headers
129
+ }.freeze
169
130
  # @api private
170
- ENV_ARRAY_KEYS = %w[
171
- APPSIGNAL_DNS_SERVERS
172
- APPSIGNAL_FILTER_METADATA
173
- APPSIGNAL_FILTER_PARAMETERS
174
- APPSIGNAL_FILTER_SESSION_DATA
175
- APPSIGNAL_IGNORE_ACTIONS
176
- APPSIGNAL_IGNORE_ERRORS
177
- APPSIGNAL_IGNORE_LOGS
178
- APPSIGNAL_IGNORE_NAMESPACES
179
- APPSIGNAL_REQUEST_HEADERS
180
- ].freeze
181
- ENV_FLOAT_KEYS = %w[
182
- APPSIGNAL_CPU_COUNT
183
- ].freeze
131
+ ENV_FLOAT_KEYS = {
132
+ "APPSIGNAL_CPU_COUNT" => :cpu_count
133
+ }.freeze
184
134
 
185
135
  # @attribute [r] system_config
186
136
  # Config detected on the system level.
@@ -211,8 +161,10 @@ module Appsignal
211
161
  # @api private
212
162
  # @return [Hash]
213
163
 
164
+ # @api private
214
165
  attr_reader :root_path, :env, :config_hash, :system_config,
215
166
  :initial_config, :file_config, :env_config, :override_config
167
+ # @api private
216
168
  attr_accessor :logger
217
169
 
218
170
  # Initialize a new configuration object for AppSignal.
@@ -316,6 +268,7 @@ module Appsignal
316
268
  config_hash[key] = value
317
269
  end
318
270
 
271
+ # @api private
319
272
  def log_level
320
273
  level = ::Logger::DEBUG if config_hash[:debug] || config_hash[:transaction_debug_mode]
321
274
  option = config_hash[:log_level]
@@ -326,6 +279,7 @@ module Appsignal
326
279
  level.nil? ? Appsignal::Config::DEFAULT_LOG_LEVEL : level
327
280
  end
328
281
 
282
+ # @api private
329
283
  def log_file_path
330
284
  return @log_file_path if defined? @log_file_path
331
285
 
@@ -360,6 +314,7 @@ module Appsignal
360
314
  @valid && config_hash[:active]
361
315
  end
362
316
 
317
+ # @api private
363
318
  def write_to_environment # rubocop:disable Metrics/AbcSize
364
319
  ENV["_APPSIGNAL_ACTIVE"] = active?.to_s
365
320
  ENV["_APPSIGNAL_AGENT_PATH"] = File.expand_path("../../ext", __dir__).to_s
@@ -405,6 +360,7 @@ module Appsignal
405
360
  ENV["_APP_REVISION"] = config_hash[:revision].to_s
406
361
  end
407
362
 
363
+ # @api private
408
364
  def validate
409
365
  # Strip path from endpoint so we're backwards compatible with
410
366
  # earlier versions of the gem.
@@ -503,35 +459,35 @@ module Appsignal
503
459
  config = {}
504
460
 
505
461
  # Configuration with string type
506
- ENV_STRING_KEYS.each do |var|
507
- env_var = ENV.fetch(var, nil)
462
+ ENV_STRING_KEYS.each do |env_key, option|
463
+ env_var = ENV.fetch(env_key, nil)
508
464
  next unless env_var
509
465
 
510
- config[ENV_TO_KEY_MAPPING[var]] = env_var
466
+ config[option] = env_var
511
467
  end
512
468
 
513
469
  # Configuration with boolean type
514
- ENV_BOOLEAN_KEYS.each do |var|
515
- env_var = ENV.fetch(var, nil)
470
+ ENV_BOOLEAN_KEYS.each do |env_key, option|
471
+ env_var = ENV.fetch(env_key, nil)
516
472
  next unless env_var
517
473
 
518
- config[ENV_TO_KEY_MAPPING[var]] = env_var.casecmp("true").zero?
474
+ config[option] = env_var.casecmp("true").zero?
519
475
  end
520
476
 
521
477
  # Configuration with array of strings type
522
- ENV_ARRAY_KEYS.each do |var|
523
- env_var = ENV.fetch(var, nil)
478
+ ENV_ARRAY_KEYS.each do |env_key, option|
479
+ env_var = ENV.fetch(env_key, nil)
524
480
  next unless env_var
525
481
 
526
- config[ENV_TO_KEY_MAPPING[var]] = env_var.split(",")
482
+ config[option] = env_var.split(",")
527
483
  end
528
484
 
529
485
  # Configuration with float type
530
- ENV_FLOAT_KEYS.each do |var|
531
- env_var = ENV.fetch(var, nil)
486
+ ENV_FLOAT_KEYS.each do |env_key, option|
487
+ env_var = ENV.fetch(env_key, nil)
532
488
  next unless env_var
533
489
 
534
- config[ENV_TO_KEY_MAPPING[var]] = env_var.to_f
490
+ config[option] = env_var.to_f
535
491
  end
536
492
 
537
493
  config
@@ -39,18 +39,15 @@ module Appsignal
39
39
  private
40
40
 
41
41
  def create_example_error_request
42
- transaction = Appsignal::Transaction.create(
43
- SecureRandom.uuid,
44
- Appsignal::Transaction::HTTP_REQUEST,
45
- rack_request
46
- )
42
+ transaction = Appsignal::Transaction.create(Appsignal::Transaction::HTTP_REQUEST)
47
43
  begin
48
44
  raise TestError,
49
45
  "Hello world! This is an error used for demonstration purposes."
50
46
  rescue => error
51
47
  Appsignal.set_error(error)
52
48
  end
53
- transaction.set_http_or_background_queue_start
49
+ add_params_to(transaction)
50
+ add_headers_to(transaction)
54
51
  transaction.set_metadata("path", "/hello")
55
52
  transaction.set_metadata("method", "GET")
56
53
  transaction.set_action("DemoController#hello")
@@ -59,16 +56,13 @@ module Appsignal
59
56
  end
60
57
 
61
58
  def create_example_performance_request
62
- transaction = Appsignal::Transaction.create(
63
- SecureRandom.uuid,
64
- Appsignal::Transaction::HTTP_REQUEST,
65
- rack_request
66
- )
59
+ transaction = Appsignal::Transaction.create(Appsignal::Transaction::HTTP_REQUEST)
67
60
  Appsignal.instrument "action_view.render", "Render hello.html.erb",
68
61
  "<h1>Hello world!</h1>" do
69
62
  sleep 2
70
63
  end
71
- transaction.set_http_or_background_queue_start
64
+ add_params_to(transaction)
65
+ add_headers_to(transaction)
72
66
  transaction.set_metadata("path", "/hello")
73
67
  transaction.set_metadata("method", "GET")
74
68
  transaction.set_action("DemoController#hello")
@@ -80,13 +74,15 @@ module Appsignal
80
74
  transaction.set_metadata("demo_sample", "true")
81
75
  end
82
76
 
83
- def rack_request
84
- env = ::Rack::MockRequest.env_for(
85
- "/demo",
86
- :params => {
87
- "controller" => "demo",
88
- "action" => "hello"
89
- },
77
+ def add_params_to(transaction)
78
+ transaction.set_params(
79
+ "controller" => "demo",
80
+ "action" => "hello"
81
+ )
82
+ end
83
+
84
+ def add_headers_to(transaction)
85
+ transaction.set_headers(
90
86
  "REMOTE_ADDR" => "127.0.0.1",
91
87
  "REQUEST_METHOD" => "GET",
92
88
  "SERVER_NAME" => "localhost",
@@ -102,7 +98,6 @@ module Appsignal
102
98
  "HTTP_USER_AGENT" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0)",
103
99
  "HTTP_REFERER" => "http://appsignal.com/accounts"
104
100
  )
105
- ::Rack::Request.new(env)
106
101
  end
107
102
  end
108
103
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Appsignal
4
4
  class EventFormatter
5
+ # @api private
5
6
  module Rom
6
7
  class SqlFormatter
7
8
  def format(payload)
@@ -10,14 +10,14 @@ module Appsignal
10
10
  # event, the same object will be called intermittently in a threaded environment.
11
11
  # So only keep global configuration as state and pass the payload around as an
12
12
  # argument if you need to use helper methods.
13
- #
14
- # @api private
15
13
  class EventFormatter
16
14
  class << self
15
+ # @api private
17
16
  def formatters
18
17
  @formatters ||= {}
19
18
  end
20
19
 
20
+ # @api private
21
21
  def formatter_classes
22
22
  @formatter_classes ||= {}
23
23
  end
@@ -49,6 +49,7 @@ module Appsignal
49
49
  end
50
50
  end
51
51
 
52
+ # @api private
52
53
  def format(name, payload)
53
54
  formatter = formatters[name]
54
55
  formatter&.format(payload)