appsignal 4.0.5 → 4.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -0
- data/Rakefile +9 -9
- data/appsignal.gemspec +22 -1
- data/build_matrix.yml +2 -1
- data/ext/agent.rb +27 -27
- data/lib/appsignal/check_in/scheduler.rb +3 -4
- data/lib/appsignal/check_in.rb +1 -1
- data/lib/appsignal/config.rb +1 -3
- data/lib/appsignal/integrations/que.rb +8 -2
- data/lib/appsignal/integrations/resque.rb +1 -6
- data/lib/appsignal/utils/hash_sanitizer.rb +4 -0
- data/lib/appsignal/version.rb +1 -1
- metadata +2 -191
- data/.github/ISSUE_TEMPLATE/bug_report.md +0 -31
- data/.github/ISSUE_TEMPLATE/chore.md +0 -14
- data/.github/workflows/ci.yml +0 -3150
- data/.github/workflows/create_release_from_tag.yml +0 -62
- data/.gitignore +0 -35
- data/.gitmodules +0 -3
- data/.rspec +0 -4
- data/.yardopts +0 -8
- data/benchmark.rake +0 -139
- data/gemfiles/capistrano2.gemfile +0 -6
- data/gemfiles/capistrano3.gemfile +0 -7
- data/gemfiles/dry-monitor.gemfile +0 -5
- data/gemfiles/grape.gemfile +0 -5
- data/gemfiles/hanami-2.0.gemfile +0 -7
- data/gemfiles/hanami-2.1.gemfile +0 -7
- data/gemfiles/http5.gemfile +0 -5
- data/gemfiles/no_dependencies.gemfile +0 -10
- data/gemfiles/padrino.gemfile +0 -7
- data/gemfiles/psych-3.gemfile +0 -5
- data/gemfiles/psych-4.gemfile +0 -5
- data/gemfiles/que.gemfile +0 -5
- data/gemfiles/rails-6.0.gemfile +0 -10
- data/gemfiles/rails-6.1.gemfile +0 -11
- data/gemfiles/rails-7.0.gemfile +0 -11
- data/gemfiles/rails-7.1.gemfile +0 -11
- data/gemfiles/rails-7.2.gemfile +0 -11
- data/gemfiles/redis-4.gemfile +0 -5
- data/gemfiles/redis-5.gemfile +0 -6
- data/gemfiles/resque-2.gemfile +0 -6
- data/gemfiles/sequel.gemfile +0 -10
- data/gemfiles/sinatra.gemfile +0 -5
- data/gemfiles/webmachine1.gemfile +0 -7
- data/gemfiles/webmachine2.gemfile +0 -6
- data/mono.yml +0 -16
- data/spec/.rubocop.yml +0 -7
- data/spec/lib/appsignal/auth_check_spec.rb +0 -84
- data/spec/lib/appsignal/capistrano2_spec.rb +0 -227
- data/spec/lib/appsignal/capistrano3_spec.rb +0 -284
- data/spec/lib/appsignal/check_in/cron_spec.rb +0 -202
- data/spec/lib/appsignal/check_in/scheduler_spec.rb +0 -443
- data/spec/lib/appsignal/cli/demo_spec.rb +0 -46
- data/spec/lib/appsignal/cli/diagnose/paths_spec.rb +0 -16
- data/spec/lib/appsignal/cli/diagnose/utils_spec.rb +0 -86
- data/spec/lib/appsignal/cli/diagnose_spec.rb +0 -1553
- data/spec/lib/appsignal/cli/helpers_spec.rb +0 -179
- data/spec/lib/appsignal/cli/install_spec.rb +0 -848
- data/spec/lib/appsignal/cli_spec.rb +0 -56
- data/spec/lib/appsignal/config_spec.rb +0 -1380
- data/spec/lib/appsignal/demo_spec.rb +0 -83
- data/spec/lib/appsignal/environment_spec.rb +0 -190
- data/spec/lib/appsignal/event_formatter/action_view/render_formatter_spec.rb +0 -60
- data/spec/lib/appsignal/event_formatter/active_record/instantiation_formatter_spec.rb +0 -21
- data/spec/lib/appsignal/event_formatter/active_record/sql_formatter_spec.rb +0 -21
- data/spec/lib/appsignal/event_formatter/elastic_search/search_formatter_spec.rb +0 -52
- data/spec/lib/appsignal/event_formatter/faraday/request_formatter_spec.rb +0 -21
- data/spec/lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter_spec.rb +0 -84
- data/spec/lib/appsignal/event_formatter/rom/sql_formatter_spec.rb +0 -22
- data/spec/lib/appsignal/event_formatter/sequel/sql_formatter_spec.rb +0 -30
- data/spec/lib/appsignal/event_formatter/view_component/render_formatter_spec.rb +0 -41
- data/spec/lib/appsignal/event_formatter_spec.rb +0 -193
- data/spec/lib/appsignal/extension/jruby_spec.rb +0 -46
- data/spec/lib/appsignal/extension_install_failure_spec.rb +0 -20
- data/spec/lib/appsignal/extension_spec.rb +0 -178
- data/spec/lib/appsignal/garbage_collection_spec.rb +0 -98
- data/spec/lib/appsignal/hooks/action_cable_spec.rb +0 -345
- data/spec/lib/appsignal/hooks/action_mailer_spec.rb +0 -55
- data/spec/lib/appsignal/hooks/active_support_notifications/finish_with_state_shared_examples.rb +0 -23
- data/spec/lib/appsignal/hooks/active_support_notifications/instrument_shared_examples.rb +0 -99
- data/spec/lib/appsignal/hooks/active_support_notifications/start_finish_shared_examples.rb +0 -47
- data/spec/lib/appsignal/hooks/active_support_notifications_spec.rb +0 -47
- data/spec/lib/appsignal/hooks/activejob_spec.rb +0 -650
- data/spec/lib/appsignal/hooks/at_exit_spec.rb +0 -105
- data/spec/lib/appsignal/hooks/celluloid_spec.rb +0 -40
- data/spec/lib/appsignal/hooks/data_mapper_spec.rb +0 -40
- data/spec/lib/appsignal/hooks/delayed_job_spec.rb +0 -38
- data/spec/lib/appsignal/hooks/dry_monitor_spec.rb +0 -83
- data/spec/lib/appsignal/hooks/excon_spec.rb +0 -67
- data/spec/lib/appsignal/hooks/gvl_spec.rb +0 -145
- data/spec/lib/appsignal/hooks/http_spec.rb +0 -37
- data/spec/lib/appsignal/hooks/mongo_ruby_driver_spec.rb +0 -46
- data/spec/lib/appsignal/hooks/mri_spec.rb +0 -23
- data/spec/lib/appsignal/hooks/net_http_spec.rb +0 -18
- data/spec/lib/appsignal/hooks/passenger_spec.rb +0 -30
- data/spec/lib/appsignal/hooks/puma_spec.rb +0 -80
- data/spec/lib/appsignal/hooks/que_spec.rb +0 -19
- data/spec/lib/appsignal/hooks/rake_spec.rb +0 -144
- data/spec/lib/appsignal/hooks/redis_client_spec.rb +0 -218
- data/spec/lib/appsignal/hooks/redis_spec.rb +0 -124
- data/spec/lib/appsignal/hooks/resque_spec.rb +0 -27
- data/spec/lib/appsignal/hooks/sequel_spec.rb +0 -44
- data/spec/lib/appsignal/hooks/shoryuken_spec.rb +0 -29
- data/spec/lib/appsignal/hooks/sidekiq_spec.rb +0 -115
- data/spec/lib/appsignal/hooks/unicorn_spec.rb +0 -63
- data/spec/lib/appsignal/hooks/webmachine_spec.rb +0 -24
- data/spec/lib/appsignal/hooks_spec.rb +0 -124
- data/spec/lib/appsignal/integrations/data_mapper_spec.rb +0 -74
- data/spec/lib/appsignal/integrations/delayed_job_plugin_spec.rb +0 -454
- data/spec/lib/appsignal/integrations/http_spec.rb +0 -111
- data/spec/lib/appsignal/integrations/mongo_ruby_driver_spec.rb +0 -154
- data/spec/lib/appsignal/integrations/net_http_spec.rb +0 -33
- data/spec/lib/appsignal/integrations/object_spec.rb +0 -347
- data/spec/lib/appsignal/integrations/puma_spec.rb +0 -150
- data/spec/lib/appsignal/integrations/que_spec.rb +0 -152
- data/spec/lib/appsignal/integrations/railtie_spec.rb +0 -457
- data/spec/lib/appsignal/integrations/resque_spec.rb +0 -155
- data/spec/lib/appsignal/integrations/shoryuken_spec.rb +0 -165
- data/spec/lib/appsignal/integrations/sidekiq_spec.rb +0 -640
- data/spec/lib/appsignal/integrations/webmachine_spec.rb +0 -136
- data/spec/lib/appsignal/loaders/grape_spec.rb +0 -12
- data/spec/lib/appsignal/loaders/hanami_spec.rb +0 -92
- data/spec/lib/appsignal/loaders/padrino_spec.rb +0 -273
- data/spec/lib/appsignal/loaders/sinatra_spec.rb +0 -44
- data/spec/lib/appsignal/loaders_spec.rb +0 -144
- data/spec/lib/appsignal/logger_spec.rb +0 -205
- data/spec/lib/appsignal/marker_spec.rb +0 -51
- data/spec/lib/appsignal/probes/gvl_spec.rb +0 -164
- data/spec/lib/appsignal/probes/mri_spec.rb +0 -162
- data/spec/lib/appsignal/probes/sidekiq_spec.rb +0 -333
- data/spec/lib/appsignal/probes_spec.rb +0 -411
- data/spec/lib/appsignal/rack/abstract_middleware_spec.rb +0 -370
- data/spec/lib/appsignal/rack/body_wrapper_spec.rb +0 -319
- data/spec/lib/appsignal/rack/event_handler_spec.rb +0 -441
- data/spec/lib/appsignal/rack/grape_middleware_spec.rb +0 -201
- data/spec/lib/appsignal/rack/hanami_middleware_spec.rb +0 -36
- data/spec/lib/appsignal/rack/instrumentation_middleware_spec.rb +0 -38
- data/spec/lib/appsignal/rack/rails_instrumentation_spec.rb +0 -126
- data/spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb +0 -217
- data/spec/lib/appsignal/rack_spec.rb +0 -243
- data/spec/lib/appsignal/sample_data_spec.rb +0 -238
- data/spec/lib/appsignal/span_spec.rb +0 -141
- data/spec/lib/appsignal/system_spec.rb +0 -126
- data/spec/lib/appsignal/transaction_spec.rb +0 -2111
- data/spec/lib/appsignal/transmitter_spec.rb +0 -198
- data/spec/lib/appsignal/utils/data_spec.rb +0 -166
- data/spec/lib/appsignal/utils/hash_sanitizer_spec.rb +0 -182
- data/spec/lib/appsignal/utils/integration_logger_spec.rb +0 -21
- data/spec/lib/appsignal/utils/integration_memory_logger_spec.rb +0 -153
- data/spec/lib/appsignal/utils/json_spec.rb +0 -44
- data/spec/lib/appsignal/utils/query_params_sanitizer_spec.rb +0 -192
- data/spec/lib/appsignal_spec.rb +0 -1919
- data/spec/lib/puma/appsignal_spec.rb +0 -334
- data/spec/spec_helper.rb +0 -173
- data/spec/support/fixtures/generated_config.yml +0 -24
- data/spec/support/fixtures/projects/broken/config/appsignal.yml +0 -1
- data/spec/support/fixtures/projects/valid/config/appsignal.yml +0 -57
- data/spec/support/fixtures/projects/valid/log/.gitkeep +0 -0
- data/spec/support/fixtures/projects/valid_with_rails_app/config/application.rb +0 -16
- data/spec/support/fixtures/projects/valid_with_rails_app/config/appsignal.yml +0 -56
- data/spec/support/fixtures/projects/valid_with_rails_app/config/environment.rb +0 -10
- data/spec/support/fixtures/projects/valid_with_rails_app/log/.gitkeep +0 -0
- data/spec/support/fixtures/uploaded_file.txt +0 -0
- data/spec/support/hanami/hanami_app.rb +0 -29
- data/spec/support/helpers/action_mailer_helpers.rb +0 -25
- data/spec/support/helpers/activejob_helpers.rb +0 -27
- data/spec/support/helpers/api_request_helper.rb +0 -20
- data/spec/support/helpers/cli_helpers.rb +0 -40
- data/spec/support/helpers/config_helpers.rb +0 -66
- data/spec/support/helpers/dependency_helper.rb +0 -150
- data/spec/support/helpers/directory_helper.rb +0 -27
- data/spec/support/helpers/env_helpers.rb +0 -41
- data/spec/support/helpers/environment_metdata_helper.rb +0 -16
- data/spec/support/helpers/example_exception.rb +0 -13
- data/spec/support/helpers/example_standard_error.rb +0 -13
- data/spec/support/helpers/loader_helper.rb +0 -21
- data/spec/support/helpers/log_helpers.rb +0 -36
- data/spec/support/helpers/rails_helper.rb +0 -28
- data/spec/support/helpers/std_streams_helper.rb +0 -94
- data/spec/support/helpers/system_helpers.rb +0 -8
- data/spec/support/helpers/take_at_most_helper.rb +0 -21
- data/spec/support/helpers/time_helpers.rb +0 -11
- data/spec/support/helpers/transaction_helpers.rb +0 -122
- data/spec/support/helpers/wait_for_helper.rb +0 -39
- data/spec/support/matchers/contains_log.rb +0 -26
- data/spec/support/matchers/have_colorized_text.rb +0 -28
- data/spec/support/matchers/transaction.rb +0 -200
- data/spec/support/mocks/appsignal_mock.rb +0 -18
- data/spec/support/mocks/dummy_app.rb +0 -20
- data/spec/support/mocks/fake_gc_profiler.rb +0 -19
- data/spec/support/mocks/fake_gvl_tools.rb +0 -28
- data/spec/support/mocks/hash_like.rb +0 -10
- data/spec/support/mocks/mock_probe.rb +0 -13
- data/spec/support/mocks/puma_mock.rb +0 -43
- data/spec/support/shared_examples/instrument.rb +0 -48
- data/spec/support/stubs/appsignal/loaders/loader_stub.rb +0 -7
- data/spec/support/stubs/delayed_job.rb +0 -0
- data/spec/support/stubs/sidekiq/api.rb +0 -4
- data/spec/support/testing.rb +0 -194
- data/support/bundler_wrapper +0 -12
- data/support/install_deps +0 -33
@@ -1,640 +0,0 @@
|
|
1
|
-
require "appsignal/integrations/sidekiq"
|
2
|
-
|
3
|
-
describe Appsignal::Integrations::SidekiqDeathHandler do
|
4
|
-
let(:options) { {} }
|
5
|
-
before do
|
6
|
-
stub_const("Sidekiq::VERSION", "7.1.0")
|
7
|
-
start_agent(:options => options)
|
8
|
-
end
|
9
|
-
around { |example| keep_transactions { example.run } }
|
10
|
-
|
11
|
-
let(:exception) do
|
12
|
-
raise ExampleStandardError, "uh oh"
|
13
|
-
rescue => error
|
14
|
-
error
|
15
|
-
end
|
16
|
-
let(:job_context) { {} }
|
17
|
-
let(:transaction) { http_request_transaction }
|
18
|
-
before { set_current_transaction(transaction) }
|
19
|
-
|
20
|
-
def call_handler
|
21
|
-
expect do
|
22
|
-
described_class.new.call(job_context, exception)
|
23
|
-
end.to_not(change { created_transactions.count })
|
24
|
-
end
|
25
|
-
|
26
|
-
def expect_error_on_transaction
|
27
|
-
expect(last_transaction).to have_error("ExampleStandardError", "uh oh")
|
28
|
-
end
|
29
|
-
|
30
|
-
def expect_no_error_on_transaction
|
31
|
-
expect(last_transaction).to_not have_error
|
32
|
-
end
|
33
|
-
|
34
|
-
context "when sidekiq_report_errors = none" do
|
35
|
-
let(:options) { { :sidekiq_report_errors => "none" } }
|
36
|
-
before { call_handler }
|
37
|
-
|
38
|
-
it "doesn't track the error on the transaction" do
|
39
|
-
expect_no_error_on_transaction
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
context "when sidekiq_report_errors = all" do
|
44
|
-
let(:options) { { :sidekiq_report_errors => "all" } }
|
45
|
-
before { call_handler }
|
46
|
-
|
47
|
-
it "doesn't track the error on the transaction" do
|
48
|
-
expect_no_error_on_transaction
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
context "when sidekiq_report_errors = discard" do
|
53
|
-
let(:options) { { :sidekiq_report_errors => "discard" } }
|
54
|
-
before { call_handler }
|
55
|
-
|
56
|
-
it "records each occurrence of the error on the transaction" do
|
57
|
-
expect_error_on_transaction
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe Appsignal::Integrations::SidekiqErrorHandler do
|
63
|
-
let(:options) { {} }
|
64
|
-
before { start_agent(:options => options) }
|
65
|
-
around { |example| keep_transactions { example.run } }
|
66
|
-
|
67
|
-
let(:exception) do
|
68
|
-
raise ExampleStandardError, "uh oh"
|
69
|
-
rescue => error
|
70
|
-
error
|
71
|
-
end
|
72
|
-
|
73
|
-
context "when error is an internal error" do
|
74
|
-
let(:job_context) do
|
75
|
-
{
|
76
|
-
:context => "Sidekiq internal error!",
|
77
|
-
:jobstr => "{ bad json }"
|
78
|
-
}
|
79
|
-
end
|
80
|
-
|
81
|
-
def expect_report_internal_error
|
82
|
-
expect do
|
83
|
-
described_class.new.call(exception, job_context)
|
84
|
-
end.to(change { created_transactions.count }.by(1))
|
85
|
-
|
86
|
-
transaction = last_transaction
|
87
|
-
expect(transaction).to have_action("SidekiqInternal")
|
88
|
-
expect(transaction).to have_error("ExampleStandardError", "uh oh")
|
89
|
-
expect(transaction).to include_params(
|
90
|
-
"jobstr" => "{ bad json }"
|
91
|
-
)
|
92
|
-
expect(transaction).to include_metadata(
|
93
|
-
"sidekiq_error" => "Sidekiq internal error!"
|
94
|
-
)
|
95
|
-
end
|
96
|
-
|
97
|
-
context "when sidekiq_report_errors = none" do
|
98
|
-
let(:options) { { :sidekiq_report_errors => "none" } }
|
99
|
-
|
100
|
-
it "tracks the error on a new transaction" do
|
101
|
-
expect_report_internal_error
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
context "when sidekiq_report_errors = all" do
|
106
|
-
let(:options) { { :sidekiq_report_errors => "all" } }
|
107
|
-
|
108
|
-
it "tracks the error on a new transaction" do
|
109
|
-
expect_report_internal_error
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
context "when sidekiq_report_errors = discard" do
|
114
|
-
let(:options) { { :sidekiq_report_errors => "discard" } }
|
115
|
-
|
116
|
-
it "tracks the error on a new transaction" do
|
117
|
-
expect_report_internal_error
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
context "when error is a job error" do
|
123
|
-
let(:sidekiq_context) { { :job => {} } }
|
124
|
-
let(:transaction) { http_request_transaction }
|
125
|
-
before do
|
126
|
-
transaction.set_action("existing transaction action")
|
127
|
-
set_current_transaction(transaction)
|
128
|
-
end
|
129
|
-
|
130
|
-
def call_handler
|
131
|
-
expect do
|
132
|
-
described_class.new.call(exception, sidekiq_context)
|
133
|
-
end.to_not(change { created_transactions.count })
|
134
|
-
end
|
135
|
-
|
136
|
-
def expect_error_on_transaction
|
137
|
-
expect(last_transaction).to have_error("ExampleStandardError", "uh oh")
|
138
|
-
end
|
139
|
-
|
140
|
-
def expect_no_error_on_transaction
|
141
|
-
expect(last_transaction).to_not have_error
|
142
|
-
end
|
143
|
-
|
144
|
-
context "when sidekiq_report_errors = none" do
|
145
|
-
let(:options) { { :sidekiq_report_errors => "none" } }
|
146
|
-
before { call_handler }
|
147
|
-
|
148
|
-
it "doesn't track the error on the transaction" do
|
149
|
-
expect_no_error_on_transaction
|
150
|
-
expect(last_transaction).to be_completed
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
context "when sidekiq_report_errors = all" do
|
155
|
-
let(:options) { { :sidekiq_report_errors => "all" } }
|
156
|
-
before { call_handler }
|
157
|
-
|
158
|
-
it "records each occurrence of the error on the transaction" do
|
159
|
-
expect_error_on_transaction
|
160
|
-
expect(last_transaction).to be_completed
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
context "when sidekiq_report_errors = discard" do
|
165
|
-
let(:options) { { :sidekiq_report_errors => "discard" } }
|
166
|
-
before { call_handler }
|
167
|
-
|
168
|
-
it "doesn't track the error on the transaction" do
|
169
|
-
expect_no_error_on_transaction
|
170
|
-
expect(last_transaction).to be_completed
|
171
|
-
end
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
describe Appsignal::Integrations::SidekiqMiddleware do
|
177
|
-
class DelayedTestClass; end
|
178
|
-
|
179
|
-
let(:namespace) { Appsignal::Transaction::BACKGROUND_JOB }
|
180
|
-
let(:worker) { anything }
|
181
|
-
let(:queue) { anything }
|
182
|
-
let(:given_args) do
|
183
|
-
[
|
184
|
-
"foo",
|
185
|
-
{
|
186
|
-
:foo => "Foo",
|
187
|
-
:bar => "Bar",
|
188
|
-
"baz" => { 1 => :foo }
|
189
|
-
}
|
190
|
-
]
|
191
|
-
end
|
192
|
-
let(:expected_args) do
|
193
|
-
[
|
194
|
-
"foo",
|
195
|
-
{
|
196
|
-
"foo" => "Foo",
|
197
|
-
"bar" => "Bar",
|
198
|
-
"baz" => { "1" => "foo" }
|
199
|
-
}
|
200
|
-
]
|
201
|
-
end
|
202
|
-
let(:job_class) { "TestClass" }
|
203
|
-
let(:jid) { "b4a577edbccf1d805744efa9" }
|
204
|
-
let(:item) do
|
205
|
-
{
|
206
|
-
"jid" => jid,
|
207
|
-
"class" => job_class,
|
208
|
-
"retry_count" => 0,
|
209
|
-
"queue" => "default",
|
210
|
-
"created_at" => Time.parse("2001-01-01 10:00:00UTC").to_f,
|
211
|
-
"enqueued_at" => Time.parse("2001-01-01 10:00:00UTC").to_f,
|
212
|
-
"args" => given_args,
|
213
|
-
"extra" => "data"
|
214
|
-
}
|
215
|
-
end
|
216
|
-
let(:plugin) { Appsignal::Integrations::SidekiqMiddleware.new }
|
217
|
-
let(:options) { {} }
|
218
|
-
before do
|
219
|
-
start_agent(:options => options)
|
220
|
-
end
|
221
|
-
around { |example| keep_transactions { example.run } }
|
222
|
-
|
223
|
-
def expect_no_yaml_parse_error(logs)
|
224
|
-
expect(logs).to_not contains_log(:warn, "Unable to load YAML")
|
225
|
-
end
|
226
|
-
|
227
|
-
describe "internal Sidekiq job values" do
|
228
|
-
it "does not save internal Sidekiq values as metadata on transaction" do
|
229
|
-
perform_sidekiq_job
|
230
|
-
|
231
|
-
transaction_hash = transaction.to_h
|
232
|
-
expect(transaction_hash["metadata"].keys)
|
233
|
-
.to_not include(*Appsignal::Integrations::SidekiqMiddleware::EXCLUDED_JOB_KEYS)
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
context "with parameter filtering" do
|
238
|
-
let(:options) { { :filter_parameters => ["foo"] } }
|
239
|
-
|
240
|
-
it "filters selected arguments" do
|
241
|
-
perform_sidekiq_job
|
242
|
-
|
243
|
-
expect(transaction).to include_params(
|
244
|
-
[
|
245
|
-
"foo",
|
246
|
-
{
|
247
|
-
"foo" => "[FILTERED]",
|
248
|
-
"bar" => "Bar",
|
249
|
-
"baz" => { "1" => "foo" }
|
250
|
-
}
|
251
|
-
]
|
252
|
-
)
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
|
-
context "with encrypted arguments" do
|
257
|
-
before do
|
258
|
-
item["encrypt"] = true
|
259
|
-
item["args"] << "super secret value" # Last argument will be replaced
|
260
|
-
end
|
261
|
-
|
262
|
-
it "replaces the last argument (the secret bag) with an [encrypted data] string" do
|
263
|
-
perform_sidekiq_job
|
264
|
-
|
265
|
-
expect(transaction).to include_params(expected_args << "[encrypted data]")
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
|
-
context "when using the Sidekiq delayed extension" do
|
270
|
-
let(:item) do
|
271
|
-
{
|
272
|
-
"jid" => jid,
|
273
|
-
"class" => "Sidekiq::Extensions::DelayedClass",
|
274
|
-
"queue" => "default",
|
275
|
-
"args" => [
|
276
|
-
"---\n- !ruby/class 'DelayedTestClass'\n- :foo_method\n- - :bar: baz\n"
|
277
|
-
],
|
278
|
-
"retry" => true,
|
279
|
-
"created_at" => Time.parse("2001-01-01 10:00:00UTC").to_f,
|
280
|
-
"enqueued_at" => Time.parse("2001-01-01 10:00:00UTC").to_f,
|
281
|
-
"extra" => "data"
|
282
|
-
}
|
283
|
-
end
|
284
|
-
|
285
|
-
it "uses the delayed class and method name for the action" do
|
286
|
-
perform_sidekiq_job
|
287
|
-
|
288
|
-
expect(transaction).to have_action("DelayedTestClass.foo_method")
|
289
|
-
expect(transaction).to include_params(["bar" => "baz"])
|
290
|
-
end
|
291
|
-
|
292
|
-
context "when job arguments is a malformed YAML object" do
|
293
|
-
before { item["args"] = [] }
|
294
|
-
|
295
|
-
it "logs a warning and uses the default argument" do
|
296
|
-
logs = capture_logs { perform_sidekiq_job }
|
297
|
-
|
298
|
-
expect(transaction).to have_action("Sidekiq::Extensions::DelayedClass#perform")
|
299
|
-
expect(transaction).to include_params([])
|
300
|
-
expect(logs).to contains_log(:warn, "Unable to load YAML")
|
301
|
-
end
|
302
|
-
end
|
303
|
-
end
|
304
|
-
|
305
|
-
context "when using the Sidekiq ActiveRecord instance delayed extension" do
|
306
|
-
let(:item) do
|
307
|
-
{
|
308
|
-
"jid" => jid,
|
309
|
-
"class" => "Sidekiq::Extensions::DelayedModel",
|
310
|
-
"queue" => "default",
|
311
|
-
"args" => [
|
312
|
-
"---\n- !ruby/object:DelayedTestClass {}\n- :foo_method\n- - :bar: :baz\n"
|
313
|
-
],
|
314
|
-
"retry" => true,
|
315
|
-
"created_at" => Time.parse("2001-01-01 10:00:00UTC").to_f,
|
316
|
-
"enqueued_at" => Time.parse("2001-01-01 10:00:00UTC").to_f,
|
317
|
-
"extra" => "data"
|
318
|
-
}
|
319
|
-
end
|
320
|
-
|
321
|
-
it "uses the delayed class and method name for the action" do
|
322
|
-
perform_sidekiq_job
|
323
|
-
|
324
|
-
expect(transaction).to have_action("DelayedTestClass#foo_method")
|
325
|
-
expect(transaction).to include_params(["bar" => "baz"])
|
326
|
-
end
|
327
|
-
|
328
|
-
context "when job arguments is a malformed YAML object" do
|
329
|
-
before { item["args"] = [] }
|
330
|
-
|
331
|
-
it "logs a warning and uses the default argument" do
|
332
|
-
logs = capture_logs { perform_sidekiq_job }
|
333
|
-
|
334
|
-
expect(transaction).to have_action("Sidekiq::Extensions::DelayedModel#perform")
|
335
|
-
expect(transaction).to include_params([])
|
336
|
-
expect(logs).to contains_log(:warn, "Unable to load YAML")
|
337
|
-
end
|
338
|
-
end
|
339
|
-
end
|
340
|
-
|
341
|
-
context "with an error" do
|
342
|
-
let(:error) { ExampleException }
|
343
|
-
|
344
|
-
it "creates a transaction and adds the error" do
|
345
|
-
# TODO: additional curly brackets required for issue
|
346
|
-
# https://github.com/rspec/rspec-mocks/issues/1460
|
347
|
-
expect(Appsignal).to receive(:increment_counter)
|
348
|
-
.with("sidekiq_queue_job_count", 1, { :queue => "default", :status => :failed })
|
349
|
-
expect(Appsignal).to receive(:increment_counter)
|
350
|
-
.with("sidekiq_queue_job_count", 1, { :queue => "default", :status => :processed })
|
351
|
-
expect do
|
352
|
-
perform_sidekiq_job { raise error, "uh oh" }
|
353
|
-
end.to raise_error(error)
|
354
|
-
|
355
|
-
expect(transaction).to have_id
|
356
|
-
expect(transaction).to have_namespace(namespace)
|
357
|
-
expect(transaction).to have_action("TestClass#perform")
|
358
|
-
expect(transaction).to have_error("ExampleException", "uh oh")
|
359
|
-
expect(transaction).to include_metadata(
|
360
|
-
"extra" => "data",
|
361
|
-
"queue" => "default",
|
362
|
-
"retry_count" => "0"
|
363
|
-
)
|
364
|
-
expect(transaction).to_not include_environment
|
365
|
-
expect(transaction).to include_params(expected_args)
|
366
|
-
expect(transaction).to include_tags("request_id" => jid)
|
367
|
-
expect(transaction).to_not include_breadcrumbs
|
368
|
-
expect_transaction_to_have_sidekiq_event(transaction)
|
369
|
-
end
|
370
|
-
end
|
371
|
-
|
372
|
-
if DependencyHelper.rails7_present?
|
373
|
-
context "with Rails error reporter" do
|
374
|
-
include RailsHelper
|
375
|
-
|
376
|
-
it "reports the worker name as the action, copies the namespace and tags" do
|
377
|
-
expect do
|
378
|
-
with_rails_error_reporter do
|
379
|
-
perform_sidekiq_job do
|
380
|
-
Appsignal.tag_job("test_tag" => "value")
|
381
|
-
Rails.error.handle do
|
382
|
-
raise ExampleStandardError, "error message"
|
383
|
-
end
|
384
|
-
end
|
385
|
-
end
|
386
|
-
end.to change { created_transactions.count }.by(1)
|
387
|
-
|
388
|
-
tags = { "test_tag" => "value" }
|
389
|
-
transaction = last_transaction
|
390
|
-
|
391
|
-
expect(transaction).to have_namespace("background_job")
|
392
|
-
expect(transaction).to have_action("TestClass#perform")
|
393
|
-
expect(transaction).to have_error("ExampleStandardError", "error message")
|
394
|
-
expect(transaction).to include_tags(tags)
|
395
|
-
end
|
396
|
-
end
|
397
|
-
end
|
398
|
-
|
399
|
-
context "without an error" do
|
400
|
-
it "creates a transaction with events" do
|
401
|
-
# TODO: additional curly brackets required for issue
|
402
|
-
# https://github.com/rspec/rspec-mocks/issues/1460
|
403
|
-
expect(Appsignal).to receive(:increment_counter)
|
404
|
-
.with("sidekiq_queue_job_count", 1, { :queue => "default", :status => :processed })
|
405
|
-
perform_sidekiq_job
|
406
|
-
|
407
|
-
expect(transaction).to have_id
|
408
|
-
expect(transaction).to have_namespace(namespace)
|
409
|
-
expect(transaction).to have_action("TestClass#perform")
|
410
|
-
expect(transaction).to_not have_error
|
411
|
-
expect(transaction).to include_tags("request_id" => jid)
|
412
|
-
expect(transaction).to_not include_environment
|
413
|
-
expect(transaction).to_not include_breadcrumbs
|
414
|
-
expect(transaction).to_not include_params(expected_args)
|
415
|
-
expect(transaction).to include_metadata(
|
416
|
-
"extra" => "data",
|
417
|
-
"queue" => "default",
|
418
|
-
"retry_count" => "0"
|
419
|
-
)
|
420
|
-
expect(transaction).to have_queue_start(Time.parse("2001-01-01 10:00:00UTC").to_i * 1000)
|
421
|
-
expect_transaction_to_have_sidekiq_event(transaction)
|
422
|
-
end
|
423
|
-
end
|
424
|
-
|
425
|
-
def perform_sidekiq_job
|
426
|
-
Timecop.freeze(Time.parse("2001-01-01 10:01:00UTC")) do
|
427
|
-
exception = nil
|
428
|
-
plugin.call(worker, item, queue) do
|
429
|
-
yield if block_given?
|
430
|
-
end
|
431
|
-
rescue Exception => exception # rubocop:disable Lint/RescueException
|
432
|
-
raise exception
|
433
|
-
ensure
|
434
|
-
Appsignal::Integrations::SidekiqErrorHandler.new.call(exception, :job => item) if exception
|
435
|
-
end
|
436
|
-
end
|
437
|
-
|
438
|
-
def transaction
|
439
|
-
last_transaction
|
440
|
-
end
|
441
|
-
|
442
|
-
def expect_transaction_to_have_sidekiq_event(transaction)
|
443
|
-
expect(transaction.to_h["events"].count).to eq(1)
|
444
|
-
expect(transaction).to include_event(
|
445
|
-
"name" => "perform_job.sidekiq",
|
446
|
-
"title" => "",
|
447
|
-
"count" => 1,
|
448
|
-
"body" => "",
|
449
|
-
"body_format" => Appsignal::EventFormatter::DEFAULT
|
450
|
-
)
|
451
|
-
end
|
452
|
-
end
|
453
|
-
|
454
|
-
if DependencyHelper.active_job_present?
|
455
|
-
require "active_job"
|
456
|
-
require "action_mailer"
|
457
|
-
require "sidekiq/testing"
|
458
|
-
|
459
|
-
describe "Sidekiq ActiveJob integration" do
|
460
|
-
include RailsHelper
|
461
|
-
include ActiveJobHelpers
|
462
|
-
|
463
|
-
let(:namespace) { Appsignal::Transaction::BACKGROUND_JOB }
|
464
|
-
let(:time) { Time.parse("2001-01-01 10:00:00UTC") }
|
465
|
-
let(:log) { StringIO.new }
|
466
|
-
let(:given_args) do
|
467
|
-
[
|
468
|
-
"foo",
|
469
|
-
{
|
470
|
-
:foo => "Foo",
|
471
|
-
"bar" => "Bar",
|
472
|
-
"baz" => { "1" => "foo" }
|
473
|
-
}
|
474
|
-
]
|
475
|
-
end
|
476
|
-
let(:expected_args) do
|
477
|
-
[
|
478
|
-
"foo",
|
479
|
-
{
|
480
|
-
"_aj_symbol_keys" => ["foo"],
|
481
|
-
"foo" => "Foo",
|
482
|
-
"bar" => "Bar",
|
483
|
-
"baz" => {
|
484
|
-
"_aj_symbol_keys" => [],
|
485
|
-
"1" => "foo"
|
486
|
-
}
|
487
|
-
}
|
488
|
-
]
|
489
|
-
end
|
490
|
-
let(:expected_wrapped_args) do
|
491
|
-
if DependencyHelper.active_job_wraps_args?
|
492
|
-
[{
|
493
|
-
"_aj_ruby2_keywords" => ["args"],
|
494
|
-
"args" => expected_args
|
495
|
-
}]
|
496
|
-
else
|
497
|
-
expected_args
|
498
|
-
end
|
499
|
-
end
|
500
|
-
let(:expected_tags) do
|
501
|
-
{ "executions" => 1 }.tap do |hash|
|
502
|
-
hash["active_job_id"] = kind_of(String)
|
503
|
-
if DependencyHelper.rails_version >= Gem::Version.new("5.0.0")
|
504
|
-
hash["provider_job_id"] = kind_of(String)
|
505
|
-
end
|
506
|
-
end
|
507
|
-
end
|
508
|
-
let(:expected_perform_events) do
|
509
|
-
if DependencyHelper.rails7_present?
|
510
|
-
["perform_job.sidekiq", "perform.active_job", "perform_start.active_job"]
|
511
|
-
else
|
512
|
-
["perform_job.sidekiq", "perform_start.active_job", "perform.active_job"]
|
513
|
-
end
|
514
|
-
end
|
515
|
-
around do |example|
|
516
|
-
with_rails_error_reporter do
|
517
|
-
keep_transactions do
|
518
|
-
Sidekiq::Testing.fake! do
|
519
|
-
example.run
|
520
|
-
end
|
521
|
-
end
|
522
|
-
end
|
523
|
-
end
|
524
|
-
before do
|
525
|
-
start_agent
|
526
|
-
Appsignal.internal_logger = test_logger(log)
|
527
|
-
ActiveJob::Base.queue_adapter = :sidekiq
|
528
|
-
|
529
|
-
class ActiveJobSidekiqTestJob < ActiveJob::Base
|
530
|
-
self.queue_adapter = :sidekiq
|
531
|
-
|
532
|
-
def perform(*_args)
|
533
|
-
end
|
534
|
-
end
|
535
|
-
|
536
|
-
class ActiveJobSidekiqErrorTestJob < ActiveJob::Base
|
537
|
-
self.queue_adapter = :sidekiq
|
538
|
-
|
539
|
-
def perform(*_args)
|
540
|
-
raise "uh oh"
|
541
|
-
end
|
542
|
-
end
|
543
|
-
# Manually add the AppSignal middleware for the Testing environment.
|
544
|
-
# It doesn't use configured middlewares by default looks like.
|
545
|
-
# We test somewhere else if the middleware is installed properly.
|
546
|
-
Sidekiq::Testing.server_middleware do |chain|
|
547
|
-
chain.add Appsignal::Integrations::SidekiqMiddleware
|
548
|
-
end
|
549
|
-
end
|
550
|
-
after do
|
551
|
-
Object.send(:remove_const, :ActiveJobSidekiqTestJob)
|
552
|
-
Object.send(:remove_const, :ActiveJobSidekiqErrorTestJob)
|
553
|
-
end
|
554
|
-
|
555
|
-
it "reports the transaction from the ActiveJob integration" do
|
556
|
-
perform_sidekiq_job(ActiveJobSidekiqTestJob, given_args)
|
557
|
-
|
558
|
-
transaction = last_transaction
|
559
|
-
expect(transaction).to have_namespace(namespace)
|
560
|
-
expect(transaction).to have_action("ActiveJobSidekiqTestJob#perform")
|
561
|
-
expect(transaction).to_not have_error
|
562
|
-
expect(transaction).to include_metadata("queue" => "default")
|
563
|
-
expect(transaction).to_not include_environment
|
564
|
-
expect(transaction).to include_params([expected_args])
|
565
|
-
expect(transaction).to include_tags(expected_tags.merge("queue" => "default"))
|
566
|
-
expect(transaction).to have_queue_start(time.to_i * 1000)
|
567
|
-
|
568
|
-
events = transaction.to_h["events"]
|
569
|
-
.sort_by { |e| e["start"] }
|
570
|
-
.map { |event| event["name"] }
|
571
|
-
expect(events).to eq(expected_perform_events)
|
572
|
-
end
|
573
|
-
|
574
|
-
context "with error" do
|
575
|
-
it "reports the error on the transaction from the ActiveRecord integration" do
|
576
|
-
expect do
|
577
|
-
perform_sidekiq_job(ActiveJobSidekiqErrorTestJob, given_args)
|
578
|
-
end.to raise_error(RuntimeError, "uh oh")
|
579
|
-
|
580
|
-
transaction = last_transaction
|
581
|
-
expect(transaction).to have_namespace(namespace)
|
582
|
-
expect(transaction).to have_action("ActiveJobSidekiqErrorTestJob#perform")
|
583
|
-
expect(transaction).to have_error("RuntimeError", "uh oh")
|
584
|
-
expect(transaction).to include_metadata("queue" => "default")
|
585
|
-
expect(transaction).to_not include_environment
|
586
|
-
expect(transaction).to include_params([expected_args])
|
587
|
-
expect(transaction).to include_tags(expected_tags.merge("queue" => "default"))
|
588
|
-
expect(transaction).to have_queue_start(time.to_i * 1000)
|
589
|
-
|
590
|
-
events = transaction.to_h["events"]
|
591
|
-
.sort_by { |e| e["start"] }
|
592
|
-
.map { |event| event["name"] }
|
593
|
-
expect(events).to eq(expected_perform_events)
|
594
|
-
end
|
595
|
-
end
|
596
|
-
|
597
|
-
context "with ActionMailer" do
|
598
|
-
include ActionMailerHelpers
|
599
|
-
|
600
|
-
before do
|
601
|
-
class ActionMailerSidekiqTestJob < ActionMailer::Base
|
602
|
-
def welcome(*args)
|
603
|
-
end
|
604
|
-
end
|
605
|
-
end
|
606
|
-
|
607
|
-
it "reports ActionMailer data on the transaction" do
|
608
|
-
perform_mailer(ActionMailerSidekiqTestJob, :welcome, given_args)
|
609
|
-
|
610
|
-
transaction = last_transaction
|
611
|
-
expect(transaction).to have_action("ActionMailerSidekiqTestJob#welcome")
|
612
|
-
expect(transaction).to include_params(
|
613
|
-
["ActionMailerSidekiqTestJob", "welcome",
|
614
|
-
"deliver_now"] + expected_wrapped_args
|
615
|
-
)
|
616
|
-
end
|
617
|
-
end
|
618
|
-
|
619
|
-
def perform_sidekiq
|
620
|
-
Timecop.freeze(time) do
|
621
|
-
yield
|
622
|
-
# Combined with Sidekiq::Testing.fake! and drain_all we get a
|
623
|
-
# enqueue_at in the job data.
|
624
|
-
Sidekiq::Worker.drain_all
|
625
|
-
rescue Exception => exception # rubocop:disable Lint/RescueException
|
626
|
-
raise exception
|
627
|
-
ensure
|
628
|
-
Appsignal::Integrations::SidekiqErrorHandler.new.call(exception, {}) if exception
|
629
|
-
end
|
630
|
-
end
|
631
|
-
|
632
|
-
def perform_sidekiq_job(job_class, args)
|
633
|
-
perform_sidekiq { job_class.perform_later(args) }
|
634
|
-
end
|
635
|
-
|
636
|
-
def perform_mailer(mailer, method, args = nil)
|
637
|
-
perform_sidekiq { perform_action_mailer(mailer, method, args) }
|
638
|
-
end
|
639
|
-
end
|
640
|
-
end
|