appsignal 4.0.6-java → 4.0.7-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/Rakefile +9 -9
- data/appsignal.gemspec +22 -1
- data/ext/agent.rb +27 -27
- data/lib/appsignal/check_in.rb +1 -1
- data/lib/appsignal/config.rb +1 -3
- 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 -192
- data/.github/ISSUE_TEMPLATE/bug_report.md +0 -31
- data/.github/ISSUE_TEMPLATE/chore.md +0 -14
- data/.github/workflows/ci.yml +0 -3285
- 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-1.gemfile +0 -5
- data/gemfiles/que-2.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 -210
- data/spec/lib/appsignal/check_in/scheduler_spec.rb +0 -557
- 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 -187
- 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 -414
- 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 -2115
- 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 -179
- 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 -60
- 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 -155
- 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 -203
- data/support/bundler_wrapper +0 -12
- data/support/install_deps +0 -33
@@ -1,441 +0,0 @@
|
|
1
|
-
describe Appsignal::Rack::EventHandler do
|
2
|
-
let(:queue_start_time) { fixed_time * 1_000 }
|
3
|
-
let(:env) do
|
4
|
-
{
|
5
|
-
"HTTP_X_REQUEST_START" => "t=#{queue_start_time.to_i}", # in milliseconds
|
6
|
-
"REQUEST_METHOD" => "POST",
|
7
|
-
"PATH_INFO" => "/path",
|
8
|
-
"QUERY_STRING" => "query_param1=value1&query_param2=value2",
|
9
|
-
"rack.session" => { "session1" => "value1", "session2" => "value2" },
|
10
|
-
"rack.input" => StringIO.new("post_param1=value1&post_param2=value2")
|
11
|
-
}
|
12
|
-
end
|
13
|
-
let(:request) { Rack::Request.new(env) }
|
14
|
-
let(:response) { nil }
|
15
|
-
let(:log_stream) { StringIO.new }
|
16
|
-
let(:logs) { log_contents(log_stream) }
|
17
|
-
let(:event_handler_instance) { described_class.new }
|
18
|
-
let(:appsignal_env) { :default }
|
19
|
-
before do
|
20
|
-
start_agent(:env => appsignal_env)
|
21
|
-
Appsignal.internal_logger = test_logger(log_stream)
|
22
|
-
end
|
23
|
-
around { |example| keep_transactions { example.run } }
|
24
|
-
|
25
|
-
def on_start
|
26
|
-
event_handler_instance.on_start(request, response)
|
27
|
-
end
|
28
|
-
|
29
|
-
def on_error(error)
|
30
|
-
event_handler_instance.on_error(request, response, error)
|
31
|
-
end
|
32
|
-
|
33
|
-
describe "#on_start" do
|
34
|
-
it "creates a new transaction" do
|
35
|
-
expect { on_start }.to change { created_transactions.length }.by(1)
|
36
|
-
|
37
|
-
transaction = last_transaction
|
38
|
-
expect(transaction).to have_id
|
39
|
-
expect(transaction).to have_namespace(Appsignal::Transaction::HTTP_REQUEST)
|
40
|
-
|
41
|
-
expect(Appsignal::Transaction.current).to eq(transaction)
|
42
|
-
end
|
43
|
-
|
44
|
-
context "when not active" do
|
45
|
-
let(:appsignal_env) { :inactive_env }
|
46
|
-
|
47
|
-
it "does not create a new transaction" do
|
48
|
-
expect { on_start }.to_not(change { created_transactions.length })
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
context "when the handler is nested in another EventHandler" do
|
53
|
-
it "does not create a new transaction in the nested EventHandler" do
|
54
|
-
on_start
|
55
|
-
expect { described_class.new.on_start(request, response) }
|
56
|
-
.to_not(change { created_transactions.length })
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
it "registers transaction on the request environment" do
|
61
|
-
on_start
|
62
|
-
|
63
|
-
expect(request.env[Appsignal::Rack::APPSIGNAL_TRANSACTION])
|
64
|
-
.to eq(last_transaction)
|
65
|
-
end
|
66
|
-
|
67
|
-
it "registers an rack.after_reply callback that completes the transaction" do
|
68
|
-
request.env[Appsignal::Rack::RACK_AFTER_REPLY] = []
|
69
|
-
expect do
|
70
|
-
on_start
|
71
|
-
end.to change { request.env[Appsignal::Rack::RACK_AFTER_REPLY].length }.by(1)
|
72
|
-
|
73
|
-
expect(Appsignal::Transaction.current).to eq(last_transaction)
|
74
|
-
|
75
|
-
callback = request.env[Appsignal::Rack::RACK_AFTER_REPLY].first
|
76
|
-
callback.call
|
77
|
-
|
78
|
-
expect(Appsignal::Transaction.current).to be_kind_of(Appsignal::Transaction::NilTransaction)
|
79
|
-
|
80
|
-
expect(last_transaction.ext.queue_start).to eq(queue_start_time)
|
81
|
-
end
|
82
|
-
|
83
|
-
context "with error inside rack.after_reply handler" do
|
84
|
-
before do
|
85
|
-
on_start
|
86
|
-
# A random spot we can access to raise an error for this test
|
87
|
-
expect(request.env[Appsignal::Rack::APPSIGNAL_TRANSACTION])
|
88
|
-
.to receive(:finish_event)
|
89
|
-
.and_raise(ExampleStandardError, "oh no")
|
90
|
-
callback = request.env[Appsignal::Rack::RACK_AFTER_REPLY].first
|
91
|
-
callback.call
|
92
|
-
end
|
93
|
-
|
94
|
-
it "completes the transaction" do
|
95
|
-
expect(last_transaction).to be_completed
|
96
|
-
end
|
97
|
-
|
98
|
-
it "logs an error" do
|
99
|
-
expect(logs).to contains_log(
|
100
|
-
:error,
|
101
|
-
"Error occurred in Appsignal::Rack::EventHandler's after_reply: " \
|
102
|
-
"ExampleStandardError: oh no"
|
103
|
-
)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
it "logs errors from rack.after_reply callbacks" do
|
108
|
-
on_start
|
109
|
-
|
110
|
-
expect(request.env[Appsignal::Rack::APPSIGNAL_TRANSACTION])
|
111
|
-
.to receive(:finish_event)
|
112
|
-
.and_raise(ExampleStandardError, "oh no")
|
113
|
-
callback = request.env[Appsignal::Rack::RACK_AFTER_REPLY].first
|
114
|
-
callback.call
|
115
|
-
|
116
|
-
expect(logs).to contains_log(
|
117
|
-
:error,
|
118
|
-
"Error occurred in Appsignal::Rack::EventHandler's after_reply: ExampleStandardError: oh no"
|
119
|
-
)
|
120
|
-
end
|
121
|
-
|
122
|
-
it "logs an error in case of an error" do
|
123
|
-
expect(Appsignal::Transaction)
|
124
|
-
.to receive(:create).and_raise(ExampleStandardError, "oh no")
|
125
|
-
|
126
|
-
on_start
|
127
|
-
|
128
|
-
expect(logs).to contains_log(
|
129
|
-
:error,
|
130
|
-
"Error occurred in Appsignal::Rack::EventHandler#on_start: ExampleStandardError: oh no"
|
131
|
-
)
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
describe "#on_error" do
|
136
|
-
it "reports the error" do
|
137
|
-
on_start
|
138
|
-
on_error(ExampleStandardError.new("the error"))
|
139
|
-
|
140
|
-
expect(last_transaction).to have_error("ExampleStandardError", "the error")
|
141
|
-
end
|
142
|
-
|
143
|
-
context "when not active" do
|
144
|
-
let(:appsignal_env) { :inactive_env }
|
145
|
-
|
146
|
-
it "does not report the transaction" do
|
147
|
-
on_start
|
148
|
-
on_error(ExampleStandardError.new("the error"))
|
149
|
-
|
150
|
-
expect(last_transaction).to_not have_error
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
context "when the handler is nested in another EventHandler" do
|
155
|
-
it "does not report the error on the transaction" do
|
156
|
-
on_start
|
157
|
-
described_class.new.on_error(request, response, ExampleStandardError.new("the error"))
|
158
|
-
|
159
|
-
expect(last_transaction).to_not have_error
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
it "logs an error in case of an internal error" do
|
164
|
-
on_start
|
165
|
-
|
166
|
-
expect(request.env[Appsignal::Rack::APPSIGNAL_TRANSACTION])
|
167
|
-
.to receive(:set_error).and_raise(ExampleStandardError, "oh no")
|
168
|
-
|
169
|
-
on_error(ExampleStandardError.new("the error"))
|
170
|
-
|
171
|
-
expect(logs).to contains_log(
|
172
|
-
:error,
|
173
|
-
"Error occurred in Appsignal::Rack::EventHandler#on_error: ExampleStandardError: oh no"
|
174
|
-
)
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
describe "#on_finish" do
|
179
|
-
let(:response) { Rack::Events::BufferedResponse.new(200, {}, ["body"]) }
|
180
|
-
|
181
|
-
def on_finish(given_request = request, given_response = response)
|
182
|
-
event_handler_instance.on_finish(given_request, given_response)
|
183
|
-
end
|
184
|
-
|
185
|
-
it "doesn't do anything without a transaction" do
|
186
|
-
on_start
|
187
|
-
|
188
|
-
request.env[Appsignal::Rack::APPSIGNAL_TRANSACTION] = nil
|
189
|
-
|
190
|
-
on_finish
|
191
|
-
|
192
|
-
expect(last_transaction).to_not have_action
|
193
|
-
expect(last_transaction).to_not include_events
|
194
|
-
expect(last_transaction).to include("sample_data" => {})
|
195
|
-
expect(last_transaction).to_not be_completed
|
196
|
-
end
|
197
|
-
|
198
|
-
context "when not active" do
|
199
|
-
let(:appsignal_env) { :inactive_env }
|
200
|
-
|
201
|
-
it "doesn't do anything" do
|
202
|
-
request.env[Appsignal::Rack::APPSIGNAL_TRANSACTION] = http_request_transaction
|
203
|
-
on_finish
|
204
|
-
|
205
|
-
expect(last_transaction).to_not have_action
|
206
|
-
expect(last_transaction).to_not include_events
|
207
|
-
expect(last_transaction).to include("sample_data" => {})
|
208
|
-
expect(last_transaction).to_not be_completed
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
it "sets params on the transaction" do
|
213
|
-
on_start
|
214
|
-
on_finish
|
215
|
-
|
216
|
-
expect(last_transaction).to include_params(
|
217
|
-
"query_param1" => "value1",
|
218
|
-
"query_param2" => "value2",
|
219
|
-
"post_param1" => "value1",
|
220
|
-
"post_param2" => "value2"
|
221
|
-
)
|
222
|
-
end
|
223
|
-
|
224
|
-
it "sets headers on the transaction" do
|
225
|
-
on_start
|
226
|
-
on_finish
|
227
|
-
|
228
|
-
expect(last_transaction).to include_environment(
|
229
|
-
"REQUEST_METHOD" => "POST",
|
230
|
-
"PATH_INFO" => "/path"
|
231
|
-
)
|
232
|
-
end
|
233
|
-
|
234
|
-
it "sets session data on the transaction" do
|
235
|
-
on_start
|
236
|
-
on_finish
|
237
|
-
|
238
|
-
expect(last_transaction).to include_session_data(
|
239
|
-
"session1" => "value1",
|
240
|
-
"session2" => "value2"
|
241
|
-
)
|
242
|
-
end
|
243
|
-
|
244
|
-
it "sets the queue start time on the transaction" do
|
245
|
-
on_start
|
246
|
-
on_finish
|
247
|
-
|
248
|
-
expect(last_transaction).to have_queue_start(queue_start_time)
|
249
|
-
end
|
250
|
-
|
251
|
-
it "completes the transaction" do
|
252
|
-
on_start
|
253
|
-
on_finish
|
254
|
-
|
255
|
-
expect(last_transaction).to_not have_action
|
256
|
-
expect(last_transaction).to be_completed
|
257
|
-
end
|
258
|
-
|
259
|
-
context "without a response" do
|
260
|
-
it "sets params on the transaction" do
|
261
|
-
on_start
|
262
|
-
on_finish
|
263
|
-
|
264
|
-
expect(last_transaction).to include_params(
|
265
|
-
"query_param1" => "value1",
|
266
|
-
"query_param2" => "value2",
|
267
|
-
"post_param1" => "value1",
|
268
|
-
"post_param2" => "value2"
|
269
|
-
)
|
270
|
-
end
|
271
|
-
|
272
|
-
it "sets headers on the transaction" do
|
273
|
-
on_start
|
274
|
-
on_finish
|
275
|
-
|
276
|
-
expect(last_transaction).to include_environment(
|
277
|
-
"REQUEST_METHOD" => "POST",
|
278
|
-
"PATH_INFO" => "/path"
|
279
|
-
)
|
280
|
-
end
|
281
|
-
|
282
|
-
it "sets session data on the transaction" do
|
283
|
-
on_start
|
284
|
-
on_finish
|
285
|
-
|
286
|
-
expect(last_transaction).to include_session_data(
|
287
|
-
"session1" => "value1",
|
288
|
-
"session2" => "value2"
|
289
|
-
)
|
290
|
-
end
|
291
|
-
|
292
|
-
it "sets the queue start time on the transaction" do
|
293
|
-
on_start
|
294
|
-
on_finish
|
295
|
-
|
296
|
-
expect(last_transaction).to have_queue_start(queue_start_time)
|
297
|
-
end
|
298
|
-
|
299
|
-
it "completes the transaction" do
|
300
|
-
on_start
|
301
|
-
on_finish(request, nil)
|
302
|
-
|
303
|
-
# The action is not set on purpose, as we can't set a normalized route
|
304
|
-
# It requires the app to set an action name
|
305
|
-
expect(last_transaction).to_not have_action
|
306
|
-
expect(last_transaction).to be_completed
|
307
|
-
end
|
308
|
-
|
309
|
-
it "does not set a response_status tag" do
|
310
|
-
on_start
|
311
|
-
on_finish(request, nil)
|
312
|
-
|
313
|
-
expect(last_transaction).to_not include_tags("response_status" => anything)
|
314
|
-
end
|
315
|
-
|
316
|
-
it "does not report a response_status counter metric" do
|
317
|
-
expect(Appsignal).to_not receive(:increment_counter)
|
318
|
-
.with(:response_status, anything, anything)
|
319
|
-
|
320
|
-
on_start
|
321
|
-
on_finish(request, nil)
|
322
|
-
end
|
323
|
-
|
324
|
-
context "with an error previously recorded by on_error" do
|
325
|
-
it "sets response status 500 as a tag" do
|
326
|
-
on_start
|
327
|
-
on_error(ExampleStandardError.new("the error"))
|
328
|
-
on_finish(request, nil)
|
329
|
-
|
330
|
-
expect(last_transaction).to include_tags("response_status" => 500)
|
331
|
-
end
|
332
|
-
|
333
|
-
it "increments the response status counter for response status 500" do
|
334
|
-
expect(Appsignal).to receive(:increment_counter)
|
335
|
-
.with(:response_status, 1, :status => 500, :namespace => :web)
|
336
|
-
|
337
|
-
on_start
|
338
|
-
on_error(ExampleStandardError.new("the error"))
|
339
|
-
on_finish(request, nil)
|
340
|
-
end
|
341
|
-
end
|
342
|
-
end
|
343
|
-
|
344
|
-
context "with error inside on_finish handler" do
|
345
|
-
before do
|
346
|
-
on_start
|
347
|
-
# A random spot we can access to raise an error for this test
|
348
|
-
expect(Appsignal).to receive(:increment_counter).and_raise(ExampleStandardError, "oh no")
|
349
|
-
on_finish
|
350
|
-
end
|
351
|
-
|
352
|
-
it "completes the transaction" do
|
353
|
-
expect(last_transaction).to be_completed
|
354
|
-
end
|
355
|
-
|
356
|
-
it "logs an error" do
|
357
|
-
expect(logs).to contains_log(
|
358
|
-
:error,
|
359
|
-
"Error occurred in Appsignal::Rack::EventHandler#on_finish: ExampleStandardError: oh no"
|
360
|
-
)
|
361
|
-
end
|
362
|
-
end
|
363
|
-
|
364
|
-
context "when the handler is nested in another EventHandler" do
|
365
|
-
it "does not complete the transaction" do
|
366
|
-
on_start
|
367
|
-
described_class.new.on_finish(request, response)
|
368
|
-
|
369
|
-
expect(last_transaction).to_not have_action
|
370
|
-
expect(last_transaction).to_not include_metadata
|
371
|
-
expect(last_transaction).to_not include_events
|
372
|
-
expect(last_transaction.to_h).to include("sample_data" => {})
|
373
|
-
expect(last_transaction).to_not be_completed
|
374
|
-
end
|
375
|
-
end
|
376
|
-
|
377
|
-
it "doesn't set the action name if already set" do
|
378
|
-
on_start
|
379
|
-
last_transaction.set_action("My action")
|
380
|
-
on_finish
|
381
|
-
|
382
|
-
expect(last_transaction).to have_action("My action")
|
383
|
-
end
|
384
|
-
|
385
|
-
it "finishes the process_request.rack event" do
|
386
|
-
on_start
|
387
|
-
on_finish
|
388
|
-
|
389
|
-
expect(last_transaction).to include_event("name" => "process_request.rack")
|
390
|
-
end
|
391
|
-
|
392
|
-
context "with response" do
|
393
|
-
it "sets the response status as a tag" do
|
394
|
-
on_start
|
395
|
-
on_finish
|
396
|
-
|
397
|
-
expect(last_transaction).to include_tags("response_status" => 200)
|
398
|
-
end
|
399
|
-
|
400
|
-
it "increments the response status counter for response status" do
|
401
|
-
expect(Appsignal).to receive(:increment_counter)
|
402
|
-
.with(:response_status, 1, :status => 200, :namespace => :web)
|
403
|
-
|
404
|
-
on_start
|
405
|
-
on_finish
|
406
|
-
end
|
407
|
-
|
408
|
-
context "with an error previously recorded by on_error" do
|
409
|
-
it "sets response status from the response as a tag" do
|
410
|
-
on_start
|
411
|
-
on_error(ExampleStandardError.new("the error"))
|
412
|
-
on_finish
|
413
|
-
|
414
|
-
expect(last_transaction).to include_tags("response_status" => 200)
|
415
|
-
end
|
416
|
-
|
417
|
-
it "increments the response status counter based on the response" do
|
418
|
-
expect(Appsignal).to receive(:increment_counter)
|
419
|
-
.with(:response_status, 1, :status => 200, :namespace => :web)
|
420
|
-
|
421
|
-
on_start
|
422
|
-
on_error(ExampleStandardError.new("the error"))
|
423
|
-
on_finish
|
424
|
-
end
|
425
|
-
end
|
426
|
-
end
|
427
|
-
|
428
|
-
it "logs an error in case of an error" do
|
429
|
-
# A random spot we can access to raise an error for this test
|
430
|
-
expect(Appsignal).to receive(:increment_counter).and_raise(ExampleStandardError, "oh no")
|
431
|
-
|
432
|
-
on_start
|
433
|
-
on_finish
|
434
|
-
|
435
|
-
expect(logs).to contains_log(
|
436
|
-
:error,
|
437
|
-
"Error occurred in Appsignal::Rack::EventHandler#on_finish: ExampleStandardError: oh no"
|
438
|
-
)
|
439
|
-
end
|
440
|
-
end
|
441
|
-
end
|
@@ -1,201 +0,0 @@
|
|
1
|
-
if DependencyHelper.grape_present?
|
2
|
-
require "appsignal/rack/grape_middleware"
|
3
|
-
|
4
|
-
describe Appsignal::Rack::GrapeMiddleware do
|
5
|
-
let(:app) do
|
6
|
-
Class.new(::Grape::API) do
|
7
|
-
format :json
|
8
|
-
post :ping do
|
9
|
-
{ :message => "Hello world!" }
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
let(:api_endpoint) { app.endpoints.first }
|
14
|
-
let(:env) do
|
15
|
-
http_request_env_with_data \
|
16
|
-
"api.endpoint" => api_endpoint,
|
17
|
-
"REQUEST_METHOD" => "POST",
|
18
|
-
:path => "/ping"
|
19
|
-
end
|
20
|
-
let(:middleware) { Appsignal::Rack::GrapeMiddleware.new(api_endpoint) }
|
21
|
-
let(:transaction) { http_request_transaction }
|
22
|
-
before { start_agent }
|
23
|
-
around do |example|
|
24
|
-
GrapeExample = Module.new
|
25
|
-
GrapeExample.send(:const_set, :Api, app)
|
26
|
-
keep_transactions { example.run }
|
27
|
-
Object.send(:remove_const, :GrapeExample)
|
28
|
-
end
|
29
|
-
|
30
|
-
def make_request(env)
|
31
|
-
middleware.call(env)
|
32
|
-
end
|
33
|
-
|
34
|
-
def make_request_with_exception(env, exception_class, exception_message)
|
35
|
-
expect do
|
36
|
-
middleware.call(env)
|
37
|
-
end.to raise_error(exception_class, exception_message)
|
38
|
-
end
|
39
|
-
|
40
|
-
context "with error" do
|
41
|
-
let(:app) do
|
42
|
-
Class.new(::Grape::API) do
|
43
|
-
format :json
|
44
|
-
post :ping do
|
45
|
-
raise ExampleException, "error message"
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
it "sets the error" do
|
51
|
-
make_request_with_exception(env, ExampleException, "error message")
|
52
|
-
|
53
|
-
expect(last_transaction).to have_error("ExampleException", "error message")
|
54
|
-
end
|
55
|
-
|
56
|
-
context "with env['grape.skip_appsignal_error'] = true" do
|
57
|
-
let(:app) do
|
58
|
-
Class.new(::Grape::API) do
|
59
|
-
format :json
|
60
|
-
post :ping do
|
61
|
-
env["grape.skip_appsignal_error"] = true
|
62
|
-
raise ExampleException, "error message"
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
it "does not add the error" do
|
68
|
-
make_request_with_exception(env, ExampleException, "error message")
|
69
|
-
|
70
|
-
expect(last_transaction).to_not have_error
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context "with route" do
|
76
|
-
let(:app) do
|
77
|
-
Class.new(::Grape::API) do
|
78
|
-
route([:get, :post], "hello") do
|
79
|
-
"Hello!"
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
let(:env) do
|
84
|
-
http_request_env_with_data \
|
85
|
-
"api.endpoint" => api_endpoint,
|
86
|
-
"REQUEST_METHOD" => "GET",
|
87
|
-
:path => ""
|
88
|
-
end
|
89
|
-
|
90
|
-
it "sets non-unique route path" do
|
91
|
-
make_request(env)
|
92
|
-
|
93
|
-
expect(last_transaction).to have_action("GET::GrapeExample::Api#/hello")
|
94
|
-
expect(last_transaction).to include_metadata("path" => "/hello", "method" => "GET")
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
context "with route_param" do
|
99
|
-
let(:app) do
|
100
|
-
Class.new(::Grape::API) do
|
101
|
-
format :json
|
102
|
-
resource :users do
|
103
|
-
route_param :id do
|
104
|
-
get do
|
105
|
-
{ :name => "Tom" }
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
let(:env) do
|
112
|
-
http_request_env_with_data \
|
113
|
-
"api.endpoint" => api_endpoint,
|
114
|
-
"REQUEST_METHOD" => "GET",
|
115
|
-
:path => ""
|
116
|
-
end
|
117
|
-
|
118
|
-
it "sets non-unique route_param path" do
|
119
|
-
make_request(env)
|
120
|
-
|
121
|
-
expect(last_transaction).to have_action("GET::GrapeExample::Api#/users/:id/")
|
122
|
-
expect(last_transaction).to include_metadata("path" => "/users/:id/", "method" => "GET")
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
context "with namespaced path" do
|
127
|
-
context "with symbols" do
|
128
|
-
let(:app) do
|
129
|
-
Class.new(::Grape::API) do
|
130
|
-
format :json
|
131
|
-
namespace :v1 do
|
132
|
-
namespace :beta do
|
133
|
-
post :ping do
|
134
|
-
{ :message => "Hello namespaced world!" }
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
it "sets namespaced path" do
|
142
|
-
make_request(env)
|
143
|
-
|
144
|
-
expect(last_transaction).to have_action("POST::GrapeExample::Api#/v1/beta/ping")
|
145
|
-
expect(last_transaction).to include_metadata("path" => "/v1/beta/ping",
|
146
|
-
"method" => "POST")
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
context "with strings" do
|
151
|
-
context "without / prefix" do
|
152
|
-
let(:app) do
|
153
|
-
Class.new(::Grape::API) do
|
154
|
-
format :json
|
155
|
-
namespace "v1" do
|
156
|
-
namespace "beta" do
|
157
|
-
post "ping" do
|
158
|
-
{ :message => "Hello namespaced world!" }
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
it "sets namespaced path" do
|
166
|
-
make_request(env)
|
167
|
-
|
168
|
-
expect(last_transaction).to have_action("POST::GrapeExample::Api#/v1/beta/ping")
|
169
|
-
expect(last_transaction).to include_metadata(
|
170
|
-
"path" => "/v1/beta/ping",
|
171
|
-
"method" => "POST"
|
172
|
-
)
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
context "with / prefix" do
|
177
|
-
let(:app) do
|
178
|
-
Class.new(::Grape::API) do
|
179
|
-
format :json
|
180
|
-
namespace "/v1" do
|
181
|
-
namespace "/beta" do
|
182
|
-
post "/ping" do
|
183
|
-
{ :message => "Hello namespaced world!" }
|
184
|
-
end
|
185
|
-
end
|
186
|
-
end
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
it "sets namespaced path" do
|
191
|
-
make_request(env)
|
192
|
-
|
193
|
-
expect(last_transaction).to have_action("POST::GrapeExample::Api#/v1/beta/ping")
|
194
|
-
expect(last_transaction).to include_metadata("path" => "/v1/beta/ping",
|
195
|
-
"method" => "POST")
|
196
|
-
end
|
197
|
-
end
|
198
|
-
end
|
199
|
-
end
|
200
|
-
end
|
201
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require "appsignal/rack/hanami_middleware"
|
2
|
-
|
3
|
-
if DependencyHelper.hanami2_present?
|
4
|
-
describe Appsignal::Rack::HanamiMiddleware do
|
5
|
-
let(:app) { double(:call => true) }
|
6
|
-
let(:router_params) { { "param1" => "value1", "param2" => "value2" } }
|
7
|
-
let(:env) do
|
8
|
-
Rack::MockRequest.env_for(
|
9
|
-
"/some/path",
|
10
|
-
"router.params" => router_params
|
11
|
-
)
|
12
|
-
end
|
13
|
-
let(:middleware) { Appsignal::Rack::HanamiMiddleware.new(app, {}) }
|
14
|
-
|
15
|
-
before { start_agent }
|
16
|
-
around { |example| keep_transactions { example.run } }
|
17
|
-
|
18
|
-
def make_request(env)
|
19
|
-
middleware.call(env)
|
20
|
-
end
|
21
|
-
|
22
|
-
context "with params" do
|
23
|
-
it "sets request parameters on the transaction" do
|
24
|
-
make_request(env)
|
25
|
-
|
26
|
-
expect(last_transaction).to include_params("param1" => "value1", "param2" => "value2")
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
it "reports a process_action.hanami event" do
|
31
|
-
make_request(env)
|
32
|
-
|
33
|
-
expect(last_transaction).to include_event("name" => "process_action.hanami")
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|