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,152 +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[1 birds],
|
13
|
-
:run_at => fixed_time,
|
14
|
-
:error_count => 0
|
15
|
-
}
|
16
|
-
end
|
17
|
-
let(:env) do
|
18
|
-
{
|
19
|
-
:class => "MyQueJob",
|
20
|
-
:method => "run",
|
21
|
-
:metadata => {
|
22
|
-
:id => 123,
|
23
|
-
:queue => "dfl",
|
24
|
-
:priority => 100,
|
25
|
-
:run_at => fixed_time.to_s,
|
26
|
-
:attempts => 0
|
27
|
-
},
|
28
|
-
:params => %w[1 birds]
|
29
|
-
}
|
30
|
-
end
|
31
|
-
let(:job) do
|
32
|
-
Class.new(::Que::Job) do
|
33
|
-
def run(*args)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
let(:instance) { job.new(job_attrs) }
|
38
|
-
before do
|
39
|
-
allow(Que).to receive(:execute)
|
40
|
-
|
41
|
-
start_agent
|
42
|
-
end
|
43
|
-
around { |example| keep_transactions { example.run } }
|
44
|
-
|
45
|
-
def perform_que_job(job)
|
46
|
-
job._run
|
47
|
-
end
|
48
|
-
|
49
|
-
context "success" do
|
50
|
-
it "creates a transaction for a job" do
|
51
|
-
expect do
|
52
|
-
perform_que_job(instance)
|
53
|
-
end.to change { created_transactions.length }.by(1)
|
54
|
-
|
55
|
-
transaction = last_transaction
|
56
|
-
expect(transaction).to have_id
|
57
|
-
expect(transaction).to have_namespace(Appsignal::Transaction::BACKGROUND_JOB)
|
58
|
-
expect(transaction).to have_action("MyQueJob#run")
|
59
|
-
expect(transaction).to_not have_error
|
60
|
-
expect(transaction).to include_event(
|
61
|
-
"body" => "",
|
62
|
-
"body_format" => Appsignal::EventFormatter::DEFAULT,
|
63
|
-
"count" => 1,
|
64
|
-
"name" => "perform_job.que",
|
65
|
-
"title" => ""
|
66
|
-
)
|
67
|
-
expect(transaction).to include_params(%w[1 birds])
|
68
|
-
expect(transaction).to include_tags(
|
69
|
-
"attempts" => 0,
|
70
|
-
"id" => 123,
|
71
|
-
"priority" => 100,
|
72
|
-
"queue" => "dfl",
|
73
|
-
"run_at" => fixed_time.to_s
|
74
|
-
)
|
75
|
-
expect(transaction).to be_completed
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
context "with exception" do
|
80
|
-
let(:error) { ExampleException.new("oh no!") }
|
81
|
-
|
82
|
-
it "reports exceptions and re-raise them" do
|
83
|
-
allow(instance).to receive(:run).and_raise(error)
|
84
|
-
|
85
|
-
expect do
|
86
|
-
expect do
|
87
|
-
perform_que_job(instance)
|
88
|
-
end.to raise_error(ExampleException)
|
89
|
-
end.to change { created_transactions.length }.by(1)
|
90
|
-
|
91
|
-
transaction = last_transaction
|
92
|
-
expect(transaction).to have_id
|
93
|
-
expect(transaction).to have_action("MyQueJob#run")
|
94
|
-
expect(transaction).to have_namespace(Appsignal::Transaction::BACKGROUND_JOB)
|
95
|
-
expect(transaction).to have_error(error.class.name, error.message)
|
96
|
-
expect(transaction).to include_params(%w[1 birds])
|
97
|
-
expect(transaction).to include_tags(
|
98
|
-
"attempts" => 0,
|
99
|
-
"id" => 123,
|
100
|
-
"priority" => 100,
|
101
|
-
"queue" => "dfl",
|
102
|
-
"run_at" => fixed_time.to_s
|
103
|
-
)
|
104
|
-
expect(transaction).to be_completed
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
context "with error" do
|
109
|
-
let(:error) { ExampleStandardError.new("oh no!") }
|
110
|
-
|
111
|
-
it "reports errors and not re-raise them" do
|
112
|
-
allow(instance).to receive(:run).and_raise(error)
|
113
|
-
|
114
|
-
expect { perform_que_job(instance) }.to change { created_transactions.length }.by(1)
|
115
|
-
|
116
|
-
transaction = last_transaction
|
117
|
-
expect(transaction).to have_id
|
118
|
-
expect(transaction).to have_action("MyQueJob#run")
|
119
|
-
expect(transaction).to have_namespace(Appsignal::Transaction::BACKGROUND_JOB)
|
120
|
-
expect(transaction).to have_error(error.class.name, error.message)
|
121
|
-
expect(transaction).to include_params(%w[1 birds])
|
122
|
-
expect(transaction).to include_tags(
|
123
|
-
"attempts" => 0,
|
124
|
-
"id" => 123,
|
125
|
-
"priority" => 100,
|
126
|
-
"queue" => "dfl",
|
127
|
-
"run_at" => fixed_time.to_s
|
128
|
-
)
|
129
|
-
expect(transaction).to be_completed
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
context "when action set in job" do
|
134
|
-
let(:job) do
|
135
|
-
Class.new(::Que::Job) do
|
136
|
-
def run(*_args)
|
137
|
-
Appsignal.set_action("MyCustomJob#perform")
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
it "uses the custom action" do
|
143
|
-
perform_que_job(instance)
|
144
|
-
|
145
|
-
transaction = last_transaction
|
146
|
-
expect(transaction).to have_action("MyCustomJob#perform")
|
147
|
-
expect(transaction).to be_completed
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
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
|