appsignal 4.0.6 → 4.0.7

Sign up to get free protection for your applications and to get access to all the features.
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,650 +0,0 @@
1
- if DependencyHelper.active_job_present?
2
- require "active_job"
3
- require "action_mailer"
4
-
5
- describe Appsignal::Hooks::ActiveJobHook do
6
- describe "#dependencies_present?" do
7
- subject { described_class.new.dependencies_present? }
8
-
9
- context "when ActiveJob constant is found" do
10
- before { stub_const "ActiveJob", Class.new }
11
-
12
- it { is_expected.to be_truthy }
13
- end
14
-
15
- context "when ActiveJob constant is not found" do
16
- before { hide_const "ActiveJob" }
17
-
18
- it { is_expected.to be_falsy }
19
- end
20
- end
21
-
22
- describe "#install" do
23
- it "extends ActiveJob::Base with the AppSignal ActiveJob plugin" do
24
- start_agent
25
-
26
- path, _line_number = ActiveJob::Base.method(:execute).source_location
27
- expect(path).to end_with("/lib/appsignal/hooks/active_job.rb")
28
- end
29
- end
30
- end
31
-
32
- describe Appsignal::Hooks::ActiveJobHook::ActiveJobClassInstrumentation do
33
- include ActiveJobHelpers
34
- let(:time) { Time.parse("2001-01-01 10:00:00UTC") }
35
- let(:namespace) { Appsignal::Transaction::BACKGROUND_JOB }
36
- let(:queue) { "default" }
37
- let(:parameterized_given_args) do
38
- {
39
- :foo => "Foo",
40
- "bar" => "Bar",
41
- "baz" => { "1" => "foo" }
42
- }
43
- end
44
- let(:method_given_args) do
45
- [
46
- "foo",
47
- parameterized_given_args
48
- ]
49
- end
50
- let(:parameterized_expected_args) do
51
- {
52
- "_aj_symbol_keys" => ["foo"],
53
- "foo" => "Foo",
54
- "bar" => "Bar",
55
- "baz" => {
56
- "_aj_symbol_keys" => [],
57
- "1" => "foo"
58
- }
59
- }
60
- end
61
- let(:method_expected_args) do
62
- [
63
- "foo",
64
- parameterized_expected_args
65
- ]
66
- end
67
- let(:expected_perform_events) do
68
- if DependencyHelper.rails7_present?
69
- ["perform.active_job", "perform_start.active_job"]
70
- else
71
- ["perform_start.active_job", "perform.active_job"]
72
- end
73
- end
74
- let(:options) { {} }
75
- before do
76
- ActiveJob::Base.queue_adapter = :inline
77
-
78
- start_agent(:options => options)
79
- class ActiveJobTestJob < ActiveJob::Base
80
- def perform(*_args)
81
- end
82
- end
83
-
84
- class ActiveJobErrorTestJob < ActiveJob::Base
85
- def perform
86
- raise "uh oh"
87
- end
88
- end
89
-
90
- class ActiveJobErrorWithRetryTestJob < ActiveJob::Base
91
- retry_on StandardError, :wait => 0.seconds, :attempts => 2
92
-
93
- def perform
94
- raise "uh oh"
95
- end
96
- end
97
-
98
- class ActiveJobCustomQueueTestJob < ActiveJob::Base
99
- queue_as :custom_queue
100
-
101
- def perform(*_args)
102
- end
103
- end
104
- end
105
- around { |example| keep_transactions { example.run } }
106
- after do
107
- Object.send(:remove_const, :ActiveJobTestJob)
108
- Object.send(:remove_const, :ActiveJobErrorTestJob)
109
- Object.send(:remove_const, :ActiveJobErrorWithRetryTestJob)
110
- Object.send(:remove_const, :ActiveJobCustomQueueTestJob)
111
- end
112
-
113
- it "reports the name from the ActiveJob integration" do
114
- tags = { :queue => queue }
115
- expect(Appsignal).to receive(:increment_counter)
116
- .with("active_job_queue_job_count", 1, tags.merge(:status => :processed))
117
-
118
- queue_job(ActiveJobTestJob)
119
-
120
- transaction = last_transaction
121
- expect(transaction).to have_namespace(namespace)
122
- expect(transaction).to have_action("ActiveJobTestJob#perform")
123
- expect(transaction).to_not have_error
124
- expect(transaction).to_not include_metadata
125
- expect(transaction).to include_params([])
126
- expect(transaction).to include_tags(
127
- "active_job_id" => kind_of(String),
128
- "request_id" => kind_of(String),
129
- "queue" => queue,
130
- "executions" => 1
131
- )
132
- events = transaction.to_h["events"]
133
- .sort_by { |e| e["start"] }
134
- .map { |event| event["name"] }
135
- expect(events).to eq(expected_perform_events)
136
- end
137
-
138
- context "with custom queue" do
139
- it "reports the custom queue as tag on the transaction" do
140
- tags = { :queue => "custom_queue" }
141
- expect(Appsignal).to receive(:increment_counter)
142
- .with("active_job_queue_job_count", 1, tags.merge(:status => :processed))
143
- queue_job(ActiveJobCustomQueueTestJob)
144
-
145
- expect(last_transaction).to include_tags("queue" => "custom_queue")
146
- end
147
- end
148
-
149
- if DependencyHelper.rails_version >= Gem::Version.new("5.0.0")
150
- context "with priority" do
151
- before do
152
- class ActiveJobPriorityTestJob < ActiveJob::Base
153
- queue_with_priority 10
154
-
155
- def perform(*_args)
156
- end
157
- end
158
- end
159
- after do
160
- Object.send(:remove_const, :ActiveJobPriorityTestJob)
161
- end
162
-
163
- it "reports the priority as tag on the transaction" do
164
- tags = { :queue => queue }
165
- expect(Appsignal).to receive(:increment_counter)
166
- .with("active_job_queue_job_count", 1, tags.merge(:status => :processed))
167
- expect(Appsignal).to receive(:increment_counter)
168
- .with("active_job_queue_priority_job_count", 1, tags.merge(:priority => 10,
169
- :status => :processed))
170
-
171
- queue_job(ActiveJobPriorityTestJob)
172
-
173
- expect(last_transaction).to include_tags("queue" => queue, "priority" => 10)
174
- end
175
- end
176
- end
177
-
178
- context "with error" do
179
- it "reports the error on the transaction from the ActiveRecord integration" do
180
- allow(Appsignal).to receive(:increment_counter) # Other calls we're testing in another test
181
- tags = { :queue => queue }
182
- expect(Appsignal).to receive(:increment_counter)
183
- .with("active_job_queue_job_count", 1, tags.merge(:status => :failed))
184
- expect(Appsignal).to receive(:increment_counter)
185
- .with("active_job_queue_job_count", 1, tags.merge(:status => :processed))
186
-
187
- expect do
188
- queue_job(ActiveJobErrorTestJob)
189
- end.to raise_error(RuntimeError, "uh oh")
190
-
191
- transaction = last_transaction
192
- expect(transaction).to have_namespace(namespace)
193
- expect(transaction).to have_action("ActiveJobErrorTestJob#perform")
194
- expect(transaction).to have_error("RuntimeError", "uh oh")
195
- expect(transaction).to_not include_metadata
196
- expect(transaction).to include_params([])
197
- expect(transaction).to include_tags(
198
- "active_job_id" => kind_of(String),
199
- "request_id" => kind_of(String),
200
- "queue" => queue,
201
- "executions" => 1
202
- )
203
-
204
- events = transaction.to_h["events"]
205
- .sort_by { |e| e["start"] }
206
- .map { |event| event["name"] }
207
- expect(events).to eq(expected_perform_events)
208
- end
209
-
210
- context "with activejob_report_errors set to none" do
211
- let(:options) { { :activejob_report_errors => "none" } }
212
-
213
- it "does not report the error" do
214
- allow(Appsignal).to receive(:increment_counter)
215
- tags = { :queue => queue }
216
- expect(Appsignal).to receive(:increment_counter)
217
- .with("active_job_queue_job_count", 1, tags.merge(:status => :failed))
218
-
219
- expect do
220
- queue_job(ActiveJobErrorTestJob)
221
- end.to raise_error(RuntimeError, "uh oh")
222
-
223
- expect(last_transaction).to_not have_error
224
- end
225
- end
226
-
227
- if DependencyHelper.rails_version >= Gem::Version.new("7.1.0")
228
- context "with activejob_report_errors set to discard" do
229
- let(:options) { { :activejob_report_errors => "discard" } }
230
-
231
- it "does not report error on first failure" do
232
- with_test_adapter do
233
- # Prevent the job from being instantly retried so we can test
234
- # what happens before it's retried
235
- allow_any_instance_of(ActiveJobErrorWithRetryTestJob).to receive(:retry_job)
236
-
237
- queue_job(ActiveJobErrorWithRetryTestJob)
238
- end
239
-
240
- transaction = last_transaction
241
- expect(transaction).to_not have_error
242
- expect(transaction).to include_tags("executions" => 1)
243
- end
244
-
245
- it "reports error when discarding the job" do
246
- allow(Appsignal).to receive(:increment_counter)
247
- tags = { :queue => queue }
248
- expect(Appsignal).to receive(:increment_counter)
249
- .with("active_job_queue_job_count", 1, tags.merge(:status => :failed))
250
-
251
- with_test_adapter do
252
- expect do
253
- queue_job(ActiveJobErrorWithRetryTestJob)
254
- end.to raise_error(RuntimeError, "uh oh")
255
- end
256
-
257
- transaction = last_transaction
258
- expect(transaction).to have_error("RuntimeError", "uh oh")
259
- expect(transaction).to include_tags("executions" => 2)
260
- end
261
- end
262
- end
263
-
264
- if DependencyHelper.rails_version >= Gem::Version.new("5.0.0")
265
- context "with priority" do
266
- before do
267
- class ActiveJobErrorPriorityTestJob < ActiveJob::Base
268
- queue_with_priority 10
269
-
270
- def perform(*_args)
271
- raise "uh oh"
272
- end
273
- end
274
- end
275
- after do
276
- Object.send(:remove_const, :ActiveJobErrorPriorityTestJob)
277
- end
278
-
279
- it "reports the priority as tag on the transaction" do
280
- tags = { :queue => queue }
281
- expect(Appsignal).to receive(:increment_counter)
282
- .with("active_job_queue_job_count", 1, tags.merge(:status => :processed))
283
- expect(Appsignal).to receive(:increment_counter)
284
- .with("active_job_queue_job_count", 1, tags.merge(:status => :failed))
285
- expect(Appsignal).to receive(:increment_counter)
286
- .with("active_job_queue_priority_job_count", 1, tags.merge(:priority => 10,
287
- :status => :processed))
288
- expect(Appsignal).to receive(:increment_counter)
289
- .with("active_job_queue_priority_job_count", 1, tags.merge(:priority => 10,
290
- :status => :failed))
291
-
292
- expect do
293
- queue_job(ActiveJobErrorPriorityTestJob)
294
- end.to raise_error(RuntimeError, "uh oh")
295
-
296
- expect(last_transaction).to include_tags("queue" => queue, "priority" => 10)
297
- end
298
- end
299
- end
300
- end
301
-
302
- context "with retries" do
303
- it "reports the number of retries as executions" do
304
- with_test_adapter do
305
- expect do
306
- queue_job(ActiveJobErrorWithRetryTestJob)
307
- end.to raise_error(RuntimeError, "uh oh")
308
- end
309
-
310
- expect(last_transaction).to include_tags("executions" => 2)
311
- end
312
- end
313
-
314
- context "when wrapped in another transaction" do
315
- it "does not create a new transaction or close the currently open one" do
316
- current_transaction = background_job_transaction
317
- set_current_transaction current_transaction
318
-
319
- queue_job(ActiveJobTestJob)
320
-
321
- expect(created_transactions.count).to eql(1)
322
-
323
- transaction = current_transaction
324
- expect(transaction).to_not be_completed
325
- transaction._sample
326
- # It does set data on the transaction
327
- expect(transaction).to have_namespace(namespace)
328
- expect(transaction).to have_id(current_transaction.transaction_id)
329
- expect(transaction).to have_action("ActiveJobTestJob#perform")
330
- expect(transaction).to_not have_error
331
- expect(transaction).to_not include_metadata
332
- expect(transaction).to include_params([])
333
- expect(transaction).to include_tags(
334
- "active_job_id" => kind_of(String),
335
- "request_id" => kind_of(String),
336
- "queue" => queue,
337
- "executions" => 1
338
- )
339
-
340
- events = transaction.to_h["events"]
341
- .reject { |e| e["name"] == "enqueue.active_job" }
342
- .sort_by { |e| e["start"] }
343
- .map { |event| event["name"] }
344
- expect(events).to eq(expected_perform_events)
345
- end
346
- end
347
-
348
- context "with params" do
349
- let(:options) { { :filter_parameters => ["foo"] } }
350
-
351
- it "filters the configured params" do
352
- queue_job(ActiveJobTestJob, method_given_args)
353
-
354
- transaction = last_transaction
355
- transaction_hash = transaction.to_h
356
- expect(transaction_hash["sample_data"]["params"]).to include(
357
- [
358
- "foo",
359
- {
360
- "_aj_symbol_keys" => ["foo"],
361
- "foo" => "[FILTERED]",
362
- "bar" => "Bar",
363
- "baz" => { "_aj_symbol_keys" => [], "1" => "foo" }
364
- }
365
- ]
366
- )
367
- end
368
- end
369
-
370
- context "with provider_job_id",
371
- :skip => DependencyHelper.rails_version < Gem::Version.new("5.0.0") do
372
- before do
373
- module ActiveJob
374
- module QueueAdapters
375
- # Adapter used in our test suite to add provider data to the job
376
- # data, as is done by Rails provided ActiveJob adapters.
377
- #
378
- # This implementation is based on the
379
- # `ActiveJob::QueueAdapters::InlineAdapter`.
380
- class AppsignalTestAdapter < InlineAdapter
381
- def enqueue(job)
382
- Base.execute(job.serialize.merge("provider_job_id" => "my_provider_job_id"))
383
- end
384
- end
385
- end
386
- end
387
-
388
- class ProviderWrappedActiveJobTestJob < ActiveJob::Base
389
- self.queue_adapter = :appsignal_test
390
-
391
- def perform(*_args)
392
- end
393
- end
394
- end
395
- after do
396
- ActiveJob::QueueAdapters.send(:remove_const, :AppsignalTestAdapter)
397
- Object.send(:remove_const, :ProviderWrappedActiveJobTestJob)
398
- end
399
-
400
- it "sets provider_job_id as tag" do
401
- queue_job(ProviderWrappedActiveJobTestJob)
402
-
403
- expect(last_transaction).to include_tags(
404
- "provider_job_id" => "my_provider_job_id"
405
- )
406
- end
407
- end
408
-
409
- context "with enqueued_at",
410
- :skip => DependencyHelper.rails_version < Gem::Version.new("6.0.0") do
411
- before do
412
- module ActiveJob
413
- module QueueAdapters
414
- # Adapter used in our test suite to add provider data to the job
415
- # data, as is done by Rails provided ActiveJob adapters.
416
- #
417
- # This implementation is based on the
418
- # `ActiveJob::QueueAdapters::InlineAdapter`.
419
- class AppsignalTestAdapter < InlineAdapter
420
- def enqueue(job)
421
- Base.execute(job.serialize.merge("enqueued_at" => "2020-10-10T10:10:10Z"))
422
- end
423
- end
424
- end
425
- end
426
-
427
- class ProviderWrappedActiveJobTestJob < ActiveJob::Base
428
- self.queue_adapter = :appsignal_test
429
-
430
- def perform(*_args)
431
- end
432
- end
433
- end
434
- after do
435
- ActiveJob::QueueAdapters.send(:remove_const, :AppsignalTestAdapter)
436
- Object.send(:remove_const, :ProviderWrappedActiveJobTestJob)
437
- end
438
-
439
- it "sets queue time on transaction" do
440
- queue_job(ProviderWrappedActiveJobTestJob)
441
-
442
- queue_time = Time.parse("2020-10-10T10:10:10Z")
443
- expect(last_transaction).to have_queue_start((queue_time.to_f * 1_000).to_i)
444
- end
445
- end
446
-
447
- context "with ActionMailer job" do
448
- include ActionMailerHelpers
449
-
450
- before do
451
- class ActionMailerTestJob < ActionMailer::Base
452
- def welcome(_first_arg = nil, _second_arg = nil)
453
- end
454
- end
455
- end
456
- after do
457
- Object.send(:remove_const, :ActionMailerTestJob)
458
- end
459
-
460
- context "without params" do
461
- it "sets the Action mailer data on the transaction" do
462
- perform_mailer(ActionMailerTestJob, :welcome)
463
-
464
- transaction = last_transaction
465
- expect(transaction).to have_action("ActionMailerTestJob#welcome")
466
- expect(transaction).to include_params(
467
- ["ActionMailerTestJob", "welcome", "deliver_now"] + active_job_args_wrapper
468
- )
469
- expect(transaction).to include_tags(
470
- "active_job_id" => kind_of(String),
471
- "request_id" => kind_of(String),
472
- "queue" => "mailers",
473
- "executions" => 1
474
- )
475
- end
476
- end
477
-
478
- context "with multiple arguments" do
479
- it "sets the arguments on the transaction" do
480
- perform_mailer(ActionMailerTestJob, :welcome, method_given_args)
481
-
482
- transaction = last_transaction
483
- expect(transaction).to have_action("ActionMailerTestJob#welcome")
484
- expect(transaction).to include_params(
485
- ["ActionMailerTestJob", "welcome",
486
- "deliver_now"] + active_job_args_wrapper(:args => method_expected_args)
487
- )
488
- expect(transaction).to include_tags(
489
- "active_job_id" => kind_of(String),
490
- "request_id" => kind_of(String),
491
- "queue" => "mailers",
492
- "executions" => 1
493
- )
494
- end
495
- end
496
-
497
- if DependencyHelper.rails_version >= Gem::Version.new("5.2.0")
498
- context "with parameterized arguments" do
499
- it "sets the arguments on the transaction" do
500
- perform_mailer(ActionMailerTestJob, :welcome, parameterized_given_args)
501
-
502
- transaction = last_transaction
503
- expect(transaction).to have_action("ActionMailerTestJob#welcome")
504
- expect(transaction).to include_params(
505
- [
506
- "ActionMailerTestJob",
507
- "welcome",
508
- "deliver_now"
509
- ] + active_job_args_wrapper(:params => parameterized_expected_args)
510
- )
511
- expect(transaction).to include_tags(
512
- "active_job_id" => kind_of(String),
513
- "request_id" => kind_of(String),
514
- "queue" => "mailers",
515
- "executions" => 1
516
- )
517
- end
518
- end
519
- end
520
- end
521
-
522
- if DependencyHelper.rails_version >= Gem::Version.new("6.0.0")
523
- context "with ActionMailer MailDeliveryJob job" do
524
- include ActionMailerHelpers
525
-
526
- before do
527
- class ActionMailerTestMailDeliveryJob < ActionMailer::Base
528
- self.delivery_job = ActionMailer::MailDeliveryJob
529
-
530
- def welcome(*_args)
531
- end
532
- end
533
- end
534
- after do
535
- Object.send(:remove_const, :ActionMailerTestMailDeliveryJob)
536
- end
537
-
538
- it "sets the Action mailer data on the transaction" do
539
- perform_mailer(ActionMailerTestMailDeliveryJob, :welcome)
540
-
541
- transaction = last_transaction
542
- expect(transaction).to have_action("ActionMailerTestMailDeliveryJob#welcome")
543
- expect(transaction).to include_params(
544
- [
545
- "ActionMailerTestMailDeliveryJob",
546
- "welcome",
547
- "deliver_now",
548
- { active_job_internal_key => ["args"], "args" => [] }
549
- ]
550
- )
551
- expect(transaction).to include_tags(
552
- "active_job_id" => kind_of(String),
553
- "request_id" => kind_of(String),
554
- "queue" => "mailers",
555
- "executions" => 1
556
- )
557
- end
558
-
559
- context "with method arguments" do
560
- it "sets the Action mailer data on the transaction" do
561
- perform_mailer(ActionMailerTestMailDeliveryJob, :welcome, method_given_args)
562
-
563
- transaction = last_transaction
564
- expect(transaction).to have_action("ActionMailerTestMailDeliveryJob#welcome")
565
- expect(transaction).to include_params(
566
- [
567
- "ActionMailerTestMailDeliveryJob",
568
- "welcome",
569
- "deliver_now",
570
- {
571
- active_job_internal_key => ["args"],
572
- "args" => method_expected_args
573
- }
574
- ]
575
- )
576
- expect(transaction).to include_tags(
577
- "active_job_id" => kind_of(String),
578
- "request_id" => kind_of(String),
579
- "queue" => "mailers",
580
- "executions" => 1
581
- )
582
- end
583
- end
584
-
585
- context "with parameterized arguments" do
586
- it "sets the Action mailer data on the transaction" do
587
- perform_mailer(ActionMailerTestMailDeliveryJob, :welcome, parameterized_given_args)
588
-
589
- transaction = last_transaction
590
- expect(transaction).to have_action("ActionMailerTestMailDeliveryJob#welcome")
591
- expect(transaction).to include_params(
592
- [
593
- "ActionMailerTestMailDeliveryJob",
594
- "welcome",
595
- "deliver_now",
596
- {
597
- active_job_internal_key => ["params", "args"],
598
- "args" => [],
599
- "params" => parameterized_expected_args
600
- }
601
- ]
602
- )
603
- expect(transaction).to include_tags(
604
- "active_job_id" => kind_of(String),
605
- "request_id" => kind_of(String),
606
- "queue" => "mailers",
607
- "executions" => 1
608
- )
609
- end
610
- end
611
- end
612
- end
613
-
614
- def with_test_adapter
615
- ActiveJob::Base.queue_adapter = :test
616
- ActiveJob::Base.queue_adapter.performed_jobs.clear
617
- ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true
618
- ActiveJob::Base.queue_adapter.perform_enqueued_at_jobs = true
619
- yield
620
- ensure
621
- ActiveJob::Base.queue_adapter = :inline # Restore to default
622
- end
623
-
624
- def perform_active_job(&block)
625
- Timecop.freeze(time, &block)
626
- end
627
-
628
- def queue_job(job_class, args = nil)
629
- perform_active_job do
630
- if args
631
- job_class.perform_later(args)
632
- else
633
- job_class.perform_later
634
- end
635
- end
636
- end
637
-
638
- def perform_mailer(mailer, method, args = nil)
639
- perform_active_job { perform_action_mailer(mailer, method, args) }
640
- end
641
-
642
- def active_job_internal_key
643
- if DependencyHelper.ruby_version >= Gem::Version.new("2.7.0")
644
- "_aj_ruby2_keywords"
645
- else
646
- "_aj_symbol_keys"
647
- end
648
- end
649
- end
650
- end