appsignal 4.0.6-java → 4.0.7-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 (201) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/Rakefile +9 -9
  4. data/appsignal.gemspec +22 -1
  5. data/ext/agent.rb +27 -27
  6. data/lib/appsignal/check_in.rb +1 -1
  7. data/lib/appsignal/config.rb +1 -3
  8. data/lib/appsignal/integrations/resque.rb +1 -6
  9. data/lib/appsignal/utils/hash_sanitizer.rb +4 -0
  10. data/lib/appsignal/version.rb +1 -1
  11. metadata +2 -192
  12. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -31
  13. data/.github/ISSUE_TEMPLATE/chore.md +0 -14
  14. data/.github/workflows/ci.yml +0 -3285
  15. data/.github/workflows/create_release_from_tag.yml +0 -62
  16. data/.gitignore +0 -35
  17. data/.gitmodules +0 -3
  18. data/.rspec +0 -4
  19. data/.yardopts +0 -8
  20. data/benchmark.rake +0 -139
  21. data/gemfiles/capistrano2.gemfile +0 -6
  22. data/gemfiles/capistrano3.gemfile +0 -7
  23. data/gemfiles/dry-monitor.gemfile +0 -5
  24. data/gemfiles/grape.gemfile +0 -5
  25. data/gemfiles/hanami-2.0.gemfile +0 -7
  26. data/gemfiles/hanami-2.1.gemfile +0 -7
  27. data/gemfiles/http5.gemfile +0 -5
  28. data/gemfiles/no_dependencies.gemfile +0 -10
  29. data/gemfiles/padrino.gemfile +0 -7
  30. data/gemfiles/psych-3.gemfile +0 -5
  31. data/gemfiles/psych-4.gemfile +0 -5
  32. data/gemfiles/que-1.gemfile +0 -5
  33. data/gemfiles/que-2.gemfile +0 -5
  34. data/gemfiles/rails-6.0.gemfile +0 -10
  35. data/gemfiles/rails-6.1.gemfile +0 -11
  36. data/gemfiles/rails-7.0.gemfile +0 -11
  37. data/gemfiles/rails-7.1.gemfile +0 -11
  38. data/gemfiles/rails-7.2.gemfile +0 -11
  39. data/gemfiles/redis-4.gemfile +0 -5
  40. data/gemfiles/redis-5.gemfile +0 -6
  41. data/gemfiles/resque-2.gemfile +0 -6
  42. data/gemfiles/sequel.gemfile +0 -10
  43. data/gemfiles/sinatra.gemfile +0 -5
  44. data/gemfiles/webmachine1.gemfile +0 -7
  45. data/gemfiles/webmachine2.gemfile +0 -6
  46. data/mono.yml +0 -16
  47. data/spec/.rubocop.yml +0 -7
  48. data/spec/lib/appsignal/auth_check_spec.rb +0 -84
  49. data/spec/lib/appsignal/capistrano2_spec.rb +0 -227
  50. data/spec/lib/appsignal/capistrano3_spec.rb +0 -284
  51. data/spec/lib/appsignal/check_in/cron_spec.rb +0 -210
  52. data/spec/lib/appsignal/check_in/scheduler_spec.rb +0 -557
  53. data/spec/lib/appsignal/cli/demo_spec.rb +0 -46
  54. data/spec/lib/appsignal/cli/diagnose/paths_spec.rb +0 -16
  55. data/spec/lib/appsignal/cli/diagnose/utils_spec.rb +0 -86
  56. data/spec/lib/appsignal/cli/diagnose_spec.rb +0 -1553
  57. data/spec/lib/appsignal/cli/helpers_spec.rb +0 -179
  58. data/spec/lib/appsignal/cli/install_spec.rb +0 -848
  59. data/spec/lib/appsignal/cli_spec.rb +0 -56
  60. data/spec/lib/appsignal/config_spec.rb +0 -1380
  61. data/spec/lib/appsignal/demo_spec.rb +0 -83
  62. data/spec/lib/appsignal/environment_spec.rb +0 -190
  63. data/spec/lib/appsignal/event_formatter/action_view/render_formatter_spec.rb +0 -60
  64. data/spec/lib/appsignal/event_formatter/active_record/instantiation_formatter_spec.rb +0 -21
  65. data/spec/lib/appsignal/event_formatter/active_record/sql_formatter_spec.rb +0 -21
  66. data/spec/lib/appsignal/event_formatter/elastic_search/search_formatter_spec.rb +0 -52
  67. data/spec/lib/appsignal/event_formatter/faraday/request_formatter_spec.rb +0 -21
  68. data/spec/lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter_spec.rb +0 -84
  69. data/spec/lib/appsignal/event_formatter/rom/sql_formatter_spec.rb +0 -22
  70. data/spec/lib/appsignal/event_formatter/sequel/sql_formatter_spec.rb +0 -30
  71. data/spec/lib/appsignal/event_formatter/view_component/render_formatter_spec.rb +0 -41
  72. data/spec/lib/appsignal/event_formatter_spec.rb +0 -193
  73. data/spec/lib/appsignal/extension/jruby_spec.rb +0 -46
  74. data/spec/lib/appsignal/extension_install_failure_spec.rb +0 -20
  75. data/spec/lib/appsignal/extension_spec.rb +0 -178
  76. data/spec/lib/appsignal/garbage_collection_spec.rb +0 -98
  77. data/spec/lib/appsignal/hooks/action_cable_spec.rb +0 -345
  78. data/spec/lib/appsignal/hooks/action_mailer_spec.rb +0 -55
  79. data/spec/lib/appsignal/hooks/active_support_notifications/finish_with_state_shared_examples.rb +0 -23
  80. data/spec/lib/appsignal/hooks/active_support_notifications/instrument_shared_examples.rb +0 -99
  81. data/spec/lib/appsignal/hooks/active_support_notifications/start_finish_shared_examples.rb +0 -47
  82. data/spec/lib/appsignal/hooks/active_support_notifications_spec.rb +0 -47
  83. data/spec/lib/appsignal/hooks/activejob_spec.rb +0 -650
  84. data/spec/lib/appsignal/hooks/at_exit_spec.rb +0 -105
  85. data/spec/lib/appsignal/hooks/celluloid_spec.rb +0 -40
  86. data/spec/lib/appsignal/hooks/data_mapper_spec.rb +0 -40
  87. data/spec/lib/appsignal/hooks/delayed_job_spec.rb +0 -38
  88. data/spec/lib/appsignal/hooks/dry_monitor_spec.rb +0 -83
  89. data/spec/lib/appsignal/hooks/excon_spec.rb +0 -67
  90. data/spec/lib/appsignal/hooks/gvl_spec.rb +0 -145
  91. data/spec/lib/appsignal/hooks/http_spec.rb +0 -37
  92. data/spec/lib/appsignal/hooks/mongo_ruby_driver_spec.rb +0 -46
  93. data/spec/lib/appsignal/hooks/mri_spec.rb +0 -23
  94. data/spec/lib/appsignal/hooks/net_http_spec.rb +0 -18
  95. data/spec/lib/appsignal/hooks/passenger_spec.rb +0 -30
  96. data/spec/lib/appsignal/hooks/puma_spec.rb +0 -80
  97. data/spec/lib/appsignal/hooks/que_spec.rb +0 -19
  98. data/spec/lib/appsignal/hooks/rake_spec.rb +0 -144
  99. data/spec/lib/appsignal/hooks/redis_client_spec.rb +0 -218
  100. data/spec/lib/appsignal/hooks/redis_spec.rb +0 -124
  101. data/spec/lib/appsignal/hooks/resque_spec.rb +0 -27
  102. data/spec/lib/appsignal/hooks/sequel_spec.rb +0 -44
  103. data/spec/lib/appsignal/hooks/shoryuken_spec.rb +0 -29
  104. data/spec/lib/appsignal/hooks/sidekiq_spec.rb +0 -115
  105. data/spec/lib/appsignal/hooks/unicorn_spec.rb +0 -63
  106. data/spec/lib/appsignal/hooks/webmachine_spec.rb +0 -24
  107. data/spec/lib/appsignal/hooks_spec.rb +0 -124
  108. data/spec/lib/appsignal/integrations/data_mapper_spec.rb +0 -74
  109. data/spec/lib/appsignal/integrations/delayed_job_plugin_spec.rb +0 -454
  110. data/spec/lib/appsignal/integrations/http_spec.rb +0 -111
  111. data/spec/lib/appsignal/integrations/mongo_ruby_driver_spec.rb +0 -154
  112. data/spec/lib/appsignal/integrations/net_http_spec.rb +0 -33
  113. data/spec/lib/appsignal/integrations/object_spec.rb +0 -347
  114. data/spec/lib/appsignal/integrations/puma_spec.rb +0 -150
  115. data/spec/lib/appsignal/integrations/que_spec.rb +0 -187
  116. data/spec/lib/appsignal/integrations/railtie_spec.rb +0 -457
  117. data/spec/lib/appsignal/integrations/resque_spec.rb +0 -155
  118. data/spec/lib/appsignal/integrations/shoryuken_spec.rb +0 -165
  119. data/spec/lib/appsignal/integrations/sidekiq_spec.rb +0 -640
  120. data/spec/lib/appsignal/integrations/webmachine_spec.rb +0 -136
  121. data/spec/lib/appsignal/loaders/grape_spec.rb +0 -12
  122. data/spec/lib/appsignal/loaders/hanami_spec.rb +0 -92
  123. data/spec/lib/appsignal/loaders/padrino_spec.rb +0 -273
  124. data/spec/lib/appsignal/loaders/sinatra_spec.rb +0 -44
  125. data/spec/lib/appsignal/loaders_spec.rb +0 -144
  126. data/spec/lib/appsignal/logger_spec.rb +0 -205
  127. data/spec/lib/appsignal/marker_spec.rb +0 -51
  128. data/spec/lib/appsignal/probes/gvl_spec.rb +0 -164
  129. data/spec/lib/appsignal/probes/mri_spec.rb +0 -162
  130. data/spec/lib/appsignal/probes/sidekiq_spec.rb +0 -333
  131. data/spec/lib/appsignal/probes_spec.rb +0 -414
  132. data/spec/lib/appsignal/rack/abstract_middleware_spec.rb +0 -370
  133. data/spec/lib/appsignal/rack/body_wrapper_spec.rb +0 -319
  134. data/spec/lib/appsignal/rack/event_handler_spec.rb +0 -441
  135. data/spec/lib/appsignal/rack/grape_middleware_spec.rb +0 -201
  136. data/spec/lib/appsignal/rack/hanami_middleware_spec.rb +0 -36
  137. data/spec/lib/appsignal/rack/instrumentation_middleware_spec.rb +0 -38
  138. data/spec/lib/appsignal/rack/rails_instrumentation_spec.rb +0 -126
  139. data/spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb +0 -217
  140. data/spec/lib/appsignal/rack_spec.rb +0 -243
  141. data/spec/lib/appsignal/sample_data_spec.rb +0 -238
  142. data/spec/lib/appsignal/span_spec.rb +0 -141
  143. data/spec/lib/appsignal/system_spec.rb +0 -126
  144. data/spec/lib/appsignal/transaction_spec.rb +0 -2115
  145. data/spec/lib/appsignal/transmitter_spec.rb +0 -198
  146. data/spec/lib/appsignal/utils/data_spec.rb +0 -166
  147. data/spec/lib/appsignal/utils/hash_sanitizer_spec.rb +0 -182
  148. data/spec/lib/appsignal/utils/integration_logger_spec.rb +0 -21
  149. data/spec/lib/appsignal/utils/integration_memory_logger_spec.rb +0 -153
  150. data/spec/lib/appsignal/utils/json_spec.rb +0 -44
  151. data/spec/lib/appsignal/utils/query_params_sanitizer_spec.rb +0 -192
  152. data/spec/lib/appsignal_spec.rb +0 -1919
  153. data/spec/lib/puma/appsignal_spec.rb +0 -334
  154. data/spec/spec_helper.rb +0 -179
  155. data/spec/support/fixtures/generated_config.yml +0 -24
  156. data/spec/support/fixtures/projects/broken/config/appsignal.yml +0 -1
  157. data/spec/support/fixtures/projects/valid/config/appsignal.yml +0 -57
  158. data/spec/support/fixtures/projects/valid/log/.gitkeep +0 -0
  159. data/spec/support/fixtures/projects/valid_with_rails_app/config/application.rb +0 -16
  160. data/spec/support/fixtures/projects/valid_with_rails_app/config/appsignal.yml +0 -56
  161. data/spec/support/fixtures/projects/valid_with_rails_app/config/environment.rb +0 -10
  162. data/spec/support/fixtures/projects/valid_with_rails_app/log/.gitkeep +0 -0
  163. data/spec/support/fixtures/uploaded_file.txt +0 -0
  164. data/spec/support/hanami/hanami_app.rb +0 -29
  165. data/spec/support/helpers/action_mailer_helpers.rb +0 -25
  166. data/spec/support/helpers/activejob_helpers.rb +0 -27
  167. data/spec/support/helpers/api_request_helper.rb +0 -60
  168. data/spec/support/helpers/cli_helpers.rb +0 -40
  169. data/spec/support/helpers/config_helpers.rb +0 -66
  170. data/spec/support/helpers/dependency_helper.rb +0 -155
  171. data/spec/support/helpers/directory_helper.rb +0 -27
  172. data/spec/support/helpers/env_helpers.rb +0 -41
  173. data/spec/support/helpers/environment_metdata_helper.rb +0 -16
  174. data/spec/support/helpers/example_exception.rb +0 -13
  175. data/spec/support/helpers/example_standard_error.rb +0 -13
  176. data/spec/support/helpers/loader_helper.rb +0 -21
  177. data/spec/support/helpers/log_helpers.rb +0 -36
  178. data/spec/support/helpers/rails_helper.rb +0 -28
  179. data/spec/support/helpers/std_streams_helper.rb +0 -94
  180. data/spec/support/helpers/system_helpers.rb +0 -8
  181. data/spec/support/helpers/take_at_most_helper.rb +0 -21
  182. data/spec/support/helpers/time_helpers.rb +0 -11
  183. data/spec/support/helpers/transaction_helpers.rb +0 -122
  184. data/spec/support/helpers/wait_for_helper.rb +0 -39
  185. data/spec/support/matchers/contains_log.rb +0 -26
  186. data/spec/support/matchers/have_colorized_text.rb +0 -28
  187. data/spec/support/matchers/transaction.rb +0 -200
  188. data/spec/support/mocks/appsignal_mock.rb +0 -18
  189. data/spec/support/mocks/dummy_app.rb +0 -20
  190. data/spec/support/mocks/fake_gc_profiler.rb +0 -19
  191. data/spec/support/mocks/fake_gvl_tools.rb +0 -28
  192. data/spec/support/mocks/hash_like.rb +0 -10
  193. data/spec/support/mocks/mock_probe.rb +0 -13
  194. data/spec/support/mocks/puma_mock.rb +0 -43
  195. data/spec/support/shared_examples/instrument.rb +0 -48
  196. data/spec/support/stubs/appsignal/loaders/loader_stub.rb +0 -7
  197. data/spec/support/stubs/delayed_job.rb +0 -0
  198. data/spec/support/stubs/sidekiq/api.rb +0 -4
  199. data/spec/support/testing.rb +0 -203
  200. data/support/bundler_wrapper +0 -12
  201. data/support/install_deps +0 -33
@@ -1,187 +0,0 @@
1
- if DependencyHelper.que_present?
2
- require "appsignal/integrations/que"
3
-
4
- describe Appsignal::Integrations::QuePlugin do
5
- describe "#_run" do
6
- let(:job_attrs) do
7
- {
8
- :job_id => 123,
9
- :queue => "dfl",
10
- :job_class => "MyQueJob",
11
- :priority => 100,
12
- :args => %w[post_id_123 user_id_123],
13
- :run_at => fixed_time,
14
- :error_count => 0
15
- }.tap do |hash|
16
- hash[:kwargs] = {} if DependencyHelper.que2_present?
17
- end
18
- end
19
- let(:job) do
20
- Class.new(::Que::Job) do
21
- def run(post_id, user_id)
22
- end
23
- end
24
- end
25
- let(:instance) { job.new(job_attrs) }
26
- before do
27
- allow(Que).to receive(:execute)
28
-
29
- start_agent
30
- end
31
- around { |example| keep_transactions { example.run } }
32
-
33
- def perform_que_job(job)
34
- job._run
35
- end
36
-
37
- context "without exception" do
38
- it "creates a transaction for a job" do
39
- expect do
40
- perform_que_job(instance)
41
- end.to change { created_transactions.length }.by(1)
42
-
43
- transaction = last_transaction
44
- expect(transaction).to have_id
45
- expect(transaction).to have_namespace(Appsignal::Transaction::BACKGROUND_JOB)
46
- expect(transaction).to have_action("MyQueJob#run")
47
- expect(transaction).to_not have_error
48
- expect(transaction).to include_event(
49
- "body" => "",
50
- "body_format" => Appsignal::EventFormatter::DEFAULT,
51
- "count" => 1,
52
- "name" => "perform_job.que",
53
- "title" => ""
54
- )
55
- expect(transaction).to include_params(
56
- "arguments" => %w[post_id_123 user_id_123]
57
- )
58
- if DependencyHelper.que2_present?
59
- expect(transaction).to include_params(
60
- "keyword_arguments" => {}
61
- )
62
- else
63
- expect(transaction).to_not include_params(
64
- "keyword_arguments" => anything
65
- )
66
- end
67
- expect(transaction).to include_tags(
68
- "attempts" => 0,
69
- "id" => 123,
70
- "priority" => 100,
71
- "queue" => "dfl",
72
- "run_at" => fixed_time.to_s
73
- )
74
- expect(transaction).to be_completed
75
- end
76
- end
77
-
78
- context "with exception" do
79
- let(:error) { ExampleException.new("oh no!") }
80
-
81
- it "reports exceptions and re-raise them" do
82
- allow(instance).to receive(:run).and_raise(error)
83
-
84
- expect do
85
- expect do
86
- perform_que_job(instance)
87
- end.to raise_error(ExampleException)
88
- end.to change { created_transactions.length }.by(1)
89
-
90
- transaction = last_transaction
91
- expect(transaction).to have_id
92
- expect(transaction).to have_action("MyQueJob#run")
93
- expect(transaction).to have_namespace(Appsignal::Transaction::BACKGROUND_JOB)
94
- expect(transaction).to have_error(error.class.name, error.message)
95
- expect(transaction).to include_params(
96
- "arguments" => %w[post_id_123 user_id_123]
97
- )
98
- expect(transaction).to include_tags(
99
- "attempts" => 0,
100
- "id" => 123,
101
- "priority" => 100,
102
- "queue" => "dfl",
103
- "run_at" => fixed_time.to_s
104
- )
105
- expect(transaction).to be_completed
106
- end
107
- end
108
-
109
- context "with error" do
110
- let(:error) { ExampleStandardError.new("oh no!") }
111
-
112
- it "reports errors and not re-raise them" do
113
- allow(instance).to receive(:run).and_raise(error)
114
-
115
- expect { perform_que_job(instance) }.to change { created_transactions.length }.by(1)
116
-
117
- transaction = last_transaction
118
- expect(transaction).to have_id
119
- expect(transaction).to have_action("MyQueJob#run")
120
- expect(transaction).to have_namespace(Appsignal::Transaction::BACKGROUND_JOB)
121
- expect(transaction).to have_error(error.class.name, error.message)
122
- expect(transaction).to include_params(
123
- "arguments" => %w[post_id_123 user_id_123]
124
- )
125
- expect(transaction).to include_tags(
126
- "attempts" => 0,
127
- "id" => 123,
128
- "priority" => 100,
129
- "queue" => "dfl",
130
- "run_at" => fixed_time.to_s
131
- )
132
- expect(transaction).to be_completed
133
- end
134
- end
135
-
136
- if DependencyHelper.que2_present?
137
- context "with keyword argument" do
138
- let(:job_attrs) do
139
- {
140
- :job_id => 123,
141
- :queue => "dfl",
142
- :job_class => "MyQueJob",
143
- :priority => 100,
144
- :args => %w[post_id_123],
145
- :kwargs => { :user_id => "user_id_123" },
146
- :run_at => fixed_time,
147
- :error_count => 0
148
- }
149
- end
150
- let(:job) do
151
- Class.new(::Que::Job) do
152
- def run(post_id, user_id: nil)
153
- end
154
- end
155
- end
156
-
157
- it "reports keyword arguments as parameters" do
158
- perform_que_job(instance)
159
-
160
- expect(last_transaction).to include_params(
161
- "arguments" => %w[post_id_123],
162
- "keyword_arguments" => { "user_id" => "user_id_123" }
163
- )
164
- end
165
- end
166
- end
167
-
168
- context "when action set in job" do
169
- let(:job) do
170
- Class.new(::Que::Job) do
171
- def run(*_args)
172
- Appsignal.set_action("MyCustomJob#perform")
173
- end
174
- end
175
- end
176
-
177
- it "uses the custom action" do
178
- perform_que_job(instance)
179
-
180
- transaction = last_transaction
181
- expect(transaction).to have_action("MyCustomJob#perform")
182
- expect(transaction).to be_completed
183
- end
184
- end
185
- end
186
- end
187
- end
@@ -1,457 +0,0 @@
1
- if DependencyHelper.rails_present?
2
- require "action_mailer"
3
-
4
- describe Appsignal::Integrations::Railtie do
5
- include RailsHelper
6
- before { Appsignal.clear! }
7
- after { clear_rails_error_reporter! }
8
-
9
- def expect_middleware_to_match(middleware, klass, args)
10
- expect(middleware.klass).to eq(klass)
11
- expect(middleware.args).to match(args)
12
- end
13
-
14
- describe "on Rails app initialize!" do
15
- it "starts AppSignal by calling its hooks" do
16
- expect(Appsignal::Integrations::Railtie).to receive(:on_load).and_call_original
17
- expect(Appsignal::Integrations::Railtie).to receive(:after_initialize).and_call_original
18
-
19
- if MyApp::Application.initialized?
20
- run_appsignal_railtie
21
- else
22
- MyApp::Application.initialize!
23
- end
24
- end
25
- end
26
-
27
- describe "initializer" do
28
- let(:app) { MyApp::Application.new }
29
- before do
30
- # Make sure it's initialized at least once
31
- MyApp::Application.initialize!
32
- Appsignal.clear!
33
- end
34
-
35
- def initialize_railtie(event)
36
- MyApp::Application.config.root = rails_project_fixture_path
37
- case event
38
- when :on_load
39
- described_class.on_load(app)
40
- when :after_initialize
41
- # Must call both so no steps are missed
42
- described_class.on_load(app)
43
- described_class.after_initialize(app)
44
- when :only_after_initialize
45
- described_class.after_initialize(app)
46
- else
47
- raise "Unsupported test event '#{event}'"
48
- end
49
- end
50
-
51
- shared_examples "integrates with Rails" do
52
- it "starts AppSignal" do
53
- initialize_railtie(event)
54
-
55
- expect(Appsignal.active?).to be_truthy
56
- end
57
-
58
- it "sets the detected environment" do
59
- initialize_railtie(event)
60
-
61
- expect(Appsignal.config.env).to eq("test")
62
- end
63
-
64
- it "uses the APPSIGNAL_APP_ENV environment variable value as the environment" do
65
- ENV["APPSIGNAL_APP_ENV"] = "env_test"
66
- initialize_railtie(event)
67
-
68
- expect(Appsignal.config.env).to eq "env_test"
69
- end
70
-
71
- it "sets the Rails app path as root_path" do
72
- initialize_railtie(event)
73
-
74
- expect(Appsignal.config.root_path).to eq(Pathname.new(rails_project_fixture_path))
75
- end
76
-
77
- it "loads the Rails app name in the initial config" do
78
- initialize_railtie(event)
79
-
80
- rails_defaults = Appsignal::Config.loader_defaults
81
- .find { |loader| loader[:name] == :rails }
82
- expect(rails_defaults[:options][:name]).to eq("MyApp")
83
- expect(rails_defaults[:options][:log_path])
84
- .to eq(Pathname.new(File.join(rails_project_fixture_path, "log")))
85
- end
86
-
87
- it "loads the app name from the project's appsignal.yml file" do
88
- initialize_railtie(event)
89
-
90
- expect(Appsignal.config[:name]).to eq "TestApp"
91
- end
92
-
93
- it "sets the log_path based on the root_path" do
94
- initialize_railtie(event)
95
-
96
- expect(Appsignal.config[:log_path])
97
- .to eq(Pathname.new(File.join(rails_project_fixture_path, "log")))
98
- end
99
-
100
- it "adds the middleware" do
101
- initialize_railtie(event)
102
-
103
- middlewares = MyApp::Application.middleware
104
- expect_middleware_to_match(
105
- middlewares.find { |m| m.klass == ::Rack::Events },
106
- ::Rack::Events,
107
- [[instance_of(Appsignal::Rack::EventHandler)]]
108
- )
109
- expect_middleware_to_match(
110
- middlewares.find { |m| m.klass == Appsignal::Rack::RailsInstrumentation },
111
- Appsignal::Rack::RailsInstrumentation,
112
- []
113
- )
114
- end
115
-
116
- if Rails.respond_to?(:error)
117
- context "when Rails listens to `error`" do
118
- class ErrorReporterMock
119
- attr_reader :subscribers
120
-
121
- def initialize
122
- @subscribers = []
123
- end
124
-
125
- def subscribe(subscriber)
126
- @subscribers << subscriber
127
- end
128
- end
129
-
130
- let(:error_reporter) { ErrorReporterMock.new }
131
- before do
132
- allow(Rails).to receive(:error).and_return(error_reporter)
133
- end
134
-
135
- context "when enable_rails_error_reporter is enabled" do
136
- it "subscribes to the error reporter" do
137
- initialize_railtie(event)
138
-
139
- expect(error_reporter.subscribers)
140
- .to eq([Appsignal::Integrations::RailsErrorReporterSubscriber])
141
- end
142
- end
143
-
144
- context "when enable_rails_error_reporter is disabled" do
145
- it "does not subscribe to the error reporter" do
146
- ENV["APPSIGNAL_ENABLE_RAILS_ERROR_REPORTER"] = "false"
147
- initialize_railtie(event)
148
-
149
- expect(error_reporter.subscribers)
150
- .to_not eq([Appsignal::Integrations::RailsErrorReporterSubscriber])
151
- end
152
- end
153
- end
154
- else
155
- context "when Rails does not listen to `error`" do
156
- it "does not error trying to subscribe to the error reporter" do
157
- initialize_railtie(event)
158
- end
159
- end
160
- end
161
- end
162
-
163
- describe ".on_load" do
164
- let(:event) { :on_load }
165
-
166
- context "when start_at == :on_load" do
167
- include_examples "integrates with Rails"
168
- end
169
-
170
- context "when start_at == :after_initialize" do
171
- it "does not start AppSignal" do
172
- app.config.appsignal.start_at = :after_initialize
173
- initialize_railtie(event)
174
-
175
- expect(Appsignal.started?).to be_falsy
176
- expect(Appsignal.config).to be_nil
177
- end
178
- end
179
- end
180
-
181
- describe ".after_initialize" do
182
- let(:event) { :after_initialize }
183
-
184
- context "when start_at == :after_initialize" do
185
- before do
186
- app.config.appsignal.start_at = :after_initialize
187
- end
188
-
189
- include_examples "integrates with Rails"
190
- end
191
-
192
- context "when start_at == :on_load" do
193
- before do
194
- Appsignal.clear_started!
195
- Appsignal.clear_config!
196
- end
197
-
198
- it "does not start AppSignal" do
199
- app.config.appsignal.start_at = :on_load
200
- initialize_railtie(:only_after_initialize)
201
-
202
- expect(Appsignal.started?).to be_falsy
203
- expect(Appsignal.config).to be_nil
204
- end
205
- end
206
- end
207
- end
208
-
209
- if Rails.respond_to?(:error)
210
- describe "Rails error reporter" do
211
- before { start_agent }
212
- around { |example| keep_transactions { example.run } }
213
-
214
- it "reports the error when the error is not handled (reraises the error)" do
215
- with_rails_error_reporter do
216
- expect do
217
- Rails.error.record { raise ExampleStandardError, "error message" }
218
- end.to raise_error(ExampleStandardError, "error message")
219
- end
220
-
221
- expect(last_transaction).to have_error("ExampleStandardError", "error message")
222
- end
223
-
224
- it "reports the error when the error is handled (not reraised)" do
225
- with_rails_error_reporter do
226
- Rails.error.handle { raise ExampleStandardError, "error message" }
227
- end
228
-
229
- expect(last_transaction).to have_error("ExampleStandardError", "error message")
230
- end
231
-
232
- context "Sidekiq internal errors" do
233
- before do
234
- require "sidekiq"
235
- require "sidekiq/job_retry"
236
- end
237
-
238
- it "ignores Sidekiq::JobRetry::Handled errors" do
239
- with_rails_error_reporter do
240
- Rails.error.handle { raise Sidekiq::JobRetry::Handled, "error message" }
241
- end
242
-
243
- expect(last_transaction).to_not have_error
244
- end
245
-
246
- it "ignores Sidekiq::JobRetry::Skip errors" do
247
- with_rails_error_reporter do
248
- Rails.error.handle { raise Sidekiq::JobRetry::Skip, "error message" }
249
- end
250
-
251
- expect(last_transaction).to_not have_error
252
- end
253
-
254
- it "doesn't crash when no Sidekiq error classes are found" do
255
- hide_const("Sidekiq::JobRetry")
256
- with_rails_error_reporter do
257
- Rails.error.handle { raise ExampleStandardError, "error message" }
258
- end
259
-
260
- expect(last_transaction).to have_error("ExampleStandardError", "error message")
261
- end
262
- end
263
-
264
- context "when no transaction is active" do
265
- it "reports the error on a new transaction" do
266
- with_rails_error_reporter do
267
- expect do
268
- Rails.error.handle { raise ExampleStandardError, "error message" }
269
- end.to change { created_transactions.count }.by(1)
270
-
271
- transaction = last_transaction
272
- expect(transaction).to have_namespace(Appsignal::Transaction::HTTP_REQUEST)
273
- expect(transaction).to_not have_action
274
- expect(transaction).to have_error("ExampleStandardError", "error message")
275
- end
276
- end
277
- end
278
-
279
- context "when a transaction is active" do
280
- it "reports the error on the transaction when a transaction is active" do
281
- current_transaction = http_request_transaction
282
- current_transaction.set_namespace "custom"
283
- current_transaction.set_action "CustomAction"
284
- current_transaction.add_tags(:duplicated_tag => "duplicated value")
285
-
286
- with_rails_error_reporter do
287
- with_current_transaction current_transaction do
288
- Rails.error.handle { raise ExampleStandardError, "error message" }
289
- expect do
290
- current_transaction.complete
291
- end.to_not(change { created_transactions.count })
292
-
293
- transaction = current_transaction
294
- expect(transaction).to have_namespace("custom")
295
- expect(transaction).to have_action("CustomAction")
296
- expect(transaction).to have_error("ExampleStandardError", "error message")
297
- expect(transaction).to include_tags(
298
- "duplicated_tag" => "duplicated value",
299
- "severity" => "warning"
300
- )
301
- end
302
- end
303
- end
304
-
305
- context "when the current transaction has an error" do
306
- it "reports the error on a new transaction" do
307
- current_transaction = http_request_transaction
308
- current_transaction.set_namespace "custom"
309
- current_transaction.set_action "CustomAction"
310
- current_transaction.add_tags(:duplicated_tag => "duplicated value")
311
- current_transaction.add_error(ExampleStandardError.new("error message"))
312
-
313
- with_rails_error_reporter do
314
- with_current_transaction current_transaction do
315
- Rails.error.handle { raise ExampleStandardError, "other message" }
316
- expect do
317
- current_transaction.complete
318
- end.to change { created_transactions.count }.by(1)
319
-
320
- transaction = last_transaction
321
- expect(transaction).to have_namespace("custom")
322
- expect(transaction).to have_action("CustomAction")
323
- expect(transaction).to have_error("ExampleStandardError", "other message")
324
- expect(transaction).to include_tags(
325
- "duplicated_tag" => "duplicated value",
326
- "severity" => "warning"
327
- )
328
- end
329
- end
330
- end
331
-
332
- it "reports the error on a new transaction with the given context" do
333
- current_transaction = http_request_transaction
334
- current_transaction.set_namespace "custom"
335
- current_transaction.set_action "CustomAction"
336
- current_transaction.add_tags(:duplicated_tag => "duplicated value")
337
- current_transaction.add_custom_data(:original => "custom value")
338
- current_transaction.add_error(ExampleStandardError.new("error message"))
339
-
340
- with_rails_error_reporter do
341
- with_current_transaction current_transaction do
342
- given_context = {
343
- :appsignal => {
344
- :namespace => "context",
345
- :action => "ContextAction",
346
- :custom_data => { :context => "context data" }
347
-
348
- }
349
- }
350
- Rails.error.handle(:context => given_context) do
351
- raise ExampleStandardError, "other message"
352
- end
353
- expect do
354
- current_transaction.complete
355
- end.to change { created_transactions.count }.by(1)
356
-
357
- transaction = last_transaction
358
- expect(transaction).to have_namespace("context")
359
- expect(transaction).to have_action("ContextAction")
360
- expect(transaction).to have_error("ExampleStandardError", "other message")
361
- expect(transaction).to include_tags(
362
- "duplicated_tag" => "duplicated value",
363
- "severity" => "warning"
364
- )
365
- expect(transaction).to include_custom_data(
366
- "original" => "custom value",
367
- "context" => "context data"
368
- )
369
- end
370
- end
371
- end
372
- end
373
-
374
- it "overwrites duplicate tags with tags from context" do
375
- current_transaction = http_request_transaction
376
- current_transaction.add_tags(:tag1 => "duplicated value")
377
-
378
- with_rails_error_reporter do
379
- with_current_transaction current_transaction do
380
- given_context = { :tag1 => "value1", :tag2 => "value2" }
381
- Rails.error.handle(:context => given_context) { raise ExampleStandardError }
382
- current_transaction.complete
383
-
384
- expect(current_transaction).to include_tags(
385
- "tag1" => "value1",
386
- "tag2" => "value2",
387
- "severity" => "warning"
388
- )
389
- end
390
- end
391
- end
392
-
393
- it "sets namespace, action and custom data with values from context" do
394
- current_transaction = http_request_transaction
395
- current_transaction.set_namespace "custom"
396
- current_transaction.set_action "CustomAction"
397
-
398
- with_rails_error_reporter do
399
- with_current_transaction current_transaction do
400
- given_context = {
401
- :appsignal => {
402
- :namespace => "context",
403
- :action => "ContextAction",
404
- :custom_data => { :data => "context data" }
405
- }
406
- }
407
- Rails.error.handle(:context => given_context) { raise ExampleStandardError }
408
- current_transaction.complete
409
-
410
- expect(current_transaction).to have_namespace("context")
411
- expect(current_transaction).to have_action("ContextAction")
412
- expect(current_transaction).to include_custom_data("data" => "context data")
413
- end
414
- end
415
- end
416
- end
417
-
418
- if DependencyHelper.rails7_1_present?
419
- it "sets the namespace to 'runner' if the source is the Rails runner" do
420
- expect do
421
- with_rails_error_reporter do
422
- expect do
423
- Rails.error.record(:source => "application.runner.railties") do
424
- raise ExampleStandardError, "error message"
425
- end
426
- end.to raise_error(ExampleStandardError, "error message")
427
- end
428
- end.to change { created_transactions.count }.by(1)
429
-
430
- transaction = last_transaction
431
- expect(transaction).to have_namespace("runner")
432
- expect(transaction).to_not have_action
433
- expect(transaction).to have_error("ExampleStandardError", "error message")
434
- expect(transaction).to include_tags("source" => "application.runner.railties")
435
- end
436
- end
437
-
438
- it "sets the error context as tags" do
439
- given_context = {
440
- :appsignal => { :something => "not used" }, # Not set as tag
441
- :tag1 => "value1",
442
- :tag2 => "value2"
443
- }
444
- with_rails_error_reporter do
445
- Rails.error.handle(:context => given_context) { raise ExampleStandardError }
446
- end
447
-
448
- expect(last_transaction).to include_tags(
449
- "tag1" => "value1",
450
- "tag2" => "value2",
451
- "severity" => "warning"
452
- )
453
- end
454
- end
455
- end
456
- end
457
- end