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.
Files changed (201) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/Rakefile +9 -9
  4. data/appsignal.gemspec +22 -1
  5. data/ext/agent.rb +27 -27
  6. data/lib/appsignal/check_in.rb +1 -1
  7. data/lib/appsignal/config.rb +1 -3
  8. data/lib/appsignal/integrations/resque.rb +1 -6
  9. data/lib/appsignal/utils/hash_sanitizer.rb +4 -0
  10. data/lib/appsignal/version.rb +1 -1
  11. metadata +2 -192
  12. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -31
  13. data/.github/ISSUE_TEMPLATE/chore.md +0 -14
  14. data/.github/workflows/ci.yml +0 -3285
  15. data/.github/workflows/create_release_from_tag.yml +0 -62
  16. data/.gitignore +0 -35
  17. data/.gitmodules +0 -3
  18. data/.rspec +0 -4
  19. data/.yardopts +0 -8
  20. data/benchmark.rake +0 -139
  21. data/gemfiles/capistrano2.gemfile +0 -6
  22. data/gemfiles/capistrano3.gemfile +0 -7
  23. data/gemfiles/dry-monitor.gemfile +0 -5
  24. data/gemfiles/grape.gemfile +0 -5
  25. data/gemfiles/hanami-2.0.gemfile +0 -7
  26. data/gemfiles/hanami-2.1.gemfile +0 -7
  27. data/gemfiles/http5.gemfile +0 -5
  28. data/gemfiles/no_dependencies.gemfile +0 -10
  29. data/gemfiles/padrino.gemfile +0 -7
  30. data/gemfiles/psych-3.gemfile +0 -5
  31. data/gemfiles/psych-4.gemfile +0 -5
  32. data/gemfiles/que-1.gemfile +0 -5
  33. data/gemfiles/que-2.gemfile +0 -5
  34. data/gemfiles/rails-6.0.gemfile +0 -10
  35. data/gemfiles/rails-6.1.gemfile +0 -11
  36. data/gemfiles/rails-7.0.gemfile +0 -11
  37. data/gemfiles/rails-7.1.gemfile +0 -11
  38. data/gemfiles/rails-7.2.gemfile +0 -11
  39. data/gemfiles/redis-4.gemfile +0 -5
  40. data/gemfiles/redis-5.gemfile +0 -6
  41. data/gemfiles/resque-2.gemfile +0 -6
  42. data/gemfiles/sequel.gemfile +0 -10
  43. data/gemfiles/sinatra.gemfile +0 -5
  44. data/gemfiles/webmachine1.gemfile +0 -7
  45. data/gemfiles/webmachine2.gemfile +0 -6
  46. data/mono.yml +0 -16
  47. data/spec/.rubocop.yml +0 -7
  48. data/spec/lib/appsignal/auth_check_spec.rb +0 -84
  49. data/spec/lib/appsignal/capistrano2_spec.rb +0 -227
  50. data/spec/lib/appsignal/capistrano3_spec.rb +0 -284
  51. data/spec/lib/appsignal/check_in/cron_spec.rb +0 -210
  52. data/spec/lib/appsignal/check_in/scheduler_spec.rb +0 -557
  53. data/spec/lib/appsignal/cli/demo_spec.rb +0 -46
  54. data/spec/lib/appsignal/cli/diagnose/paths_spec.rb +0 -16
  55. data/spec/lib/appsignal/cli/diagnose/utils_spec.rb +0 -86
  56. data/spec/lib/appsignal/cli/diagnose_spec.rb +0 -1553
  57. data/spec/lib/appsignal/cli/helpers_spec.rb +0 -179
  58. data/spec/lib/appsignal/cli/install_spec.rb +0 -848
  59. data/spec/lib/appsignal/cli_spec.rb +0 -56
  60. data/spec/lib/appsignal/config_spec.rb +0 -1380
  61. data/spec/lib/appsignal/demo_spec.rb +0 -83
  62. data/spec/lib/appsignal/environment_spec.rb +0 -190
  63. data/spec/lib/appsignal/event_formatter/action_view/render_formatter_spec.rb +0 -60
  64. data/spec/lib/appsignal/event_formatter/active_record/instantiation_formatter_spec.rb +0 -21
  65. data/spec/lib/appsignal/event_formatter/active_record/sql_formatter_spec.rb +0 -21
  66. data/spec/lib/appsignal/event_formatter/elastic_search/search_formatter_spec.rb +0 -52
  67. data/spec/lib/appsignal/event_formatter/faraday/request_formatter_spec.rb +0 -21
  68. data/spec/lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter_spec.rb +0 -84
  69. data/spec/lib/appsignal/event_formatter/rom/sql_formatter_spec.rb +0 -22
  70. data/spec/lib/appsignal/event_formatter/sequel/sql_formatter_spec.rb +0 -30
  71. data/spec/lib/appsignal/event_formatter/view_component/render_formatter_spec.rb +0 -41
  72. data/spec/lib/appsignal/event_formatter_spec.rb +0 -193
  73. data/spec/lib/appsignal/extension/jruby_spec.rb +0 -46
  74. data/spec/lib/appsignal/extension_install_failure_spec.rb +0 -20
  75. data/spec/lib/appsignal/extension_spec.rb +0 -178
  76. data/spec/lib/appsignal/garbage_collection_spec.rb +0 -98
  77. data/spec/lib/appsignal/hooks/action_cable_spec.rb +0 -345
  78. data/spec/lib/appsignal/hooks/action_mailer_spec.rb +0 -55
  79. data/spec/lib/appsignal/hooks/active_support_notifications/finish_with_state_shared_examples.rb +0 -23
  80. data/spec/lib/appsignal/hooks/active_support_notifications/instrument_shared_examples.rb +0 -99
  81. data/spec/lib/appsignal/hooks/active_support_notifications/start_finish_shared_examples.rb +0 -47
  82. data/spec/lib/appsignal/hooks/active_support_notifications_spec.rb +0 -47
  83. data/spec/lib/appsignal/hooks/activejob_spec.rb +0 -650
  84. data/spec/lib/appsignal/hooks/at_exit_spec.rb +0 -105
  85. data/spec/lib/appsignal/hooks/celluloid_spec.rb +0 -40
  86. data/spec/lib/appsignal/hooks/data_mapper_spec.rb +0 -40
  87. data/spec/lib/appsignal/hooks/delayed_job_spec.rb +0 -38
  88. data/spec/lib/appsignal/hooks/dry_monitor_spec.rb +0 -83
  89. data/spec/lib/appsignal/hooks/excon_spec.rb +0 -67
  90. data/spec/lib/appsignal/hooks/gvl_spec.rb +0 -145
  91. data/spec/lib/appsignal/hooks/http_spec.rb +0 -37
  92. data/spec/lib/appsignal/hooks/mongo_ruby_driver_spec.rb +0 -46
  93. data/spec/lib/appsignal/hooks/mri_spec.rb +0 -23
  94. data/spec/lib/appsignal/hooks/net_http_spec.rb +0 -18
  95. data/spec/lib/appsignal/hooks/passenger_spec.rb +0 -30
  96. data/spec/lib/appsignal/hooks/puma_spec.rb +0 -80
  97. data/spec/lib/appsignal/hooks/que_spec.rb +0 -19
  98. data/spec/lib/appsignal/hooks/rake_spec.rb +0 -144
  99. data/spec/lib/appsignal/hooks/redis_client_spec.rb +0 -218
  100. data/spec/lib/appsignal/hooks/redis_spec.rb +0 -124
  101. data/spec/lib/appsignal/hooks/resque_spec.rb +0 -27
  102. data/spec/lib/appsignal/hooks/sequel_spec.rb +0 -44
  103. data/spec/lib/appsignal/hooks/shoryuken_spec.rb +0 -29
  104. data/spec/lib/appsignal/hooks/sidekiq_spec.rb +0 -115
  105. data/spec/lib/appsignal/hooks/unicorn_spec.rb +0 -63
  106. data/spec/lib/appsignal/hooks/webmachine_spec.rb +0 -24
  107. data/spec/lib/appsignal/hooks_spec.rb +0 -124
  108. data/spec/lib/appsignal/integrations/data_mapper_spec.rb +0 -74
  109. data/spec/lib/appsignal/integrations/delayed_job_plugin_spec.rb +0 -454
  110. data/spec/lib/appsignal/integrations/http_spec.rb +0 -111
  111. data/spec/lib/appsignal/integrations/mongo_ruby_driver_spec.rb +0 -154
  112. data/spec/lib/appsignal/integrations/net_http_spec.rb +0 -33
  113. data/spec/lib/appsignal/integrations/object_spec.rb +0 -347
  114. data/spec/lib/appsignal/integrations/puma_spec.rb +0 -150
  115. data/spec/lib/appsignal/integrations/que_spec.rb +0 -187
  116. data/spec/lib/appsignal/integrations/railtie_spec.rb +0 -457
  117. data/spec/lib/appsignal/integrations/resque_spec.rb +0 -155
  118. data/spec/lib/appsignal/integrations/shoryuken_spec.rb +0 -165
  119. data/spec/lib/appsignal/integrations/sidekiq_spec.rb +0 -640
  120. data/spec/lib/appsignal/integrations/webmachine_spec.rb +0 -136
  121. data/spec/lib/appsignal/loaders/grape_spec.rb +0 -12
  122. data/spec/lib/appsignal/loaders/hanami_spec.rb +0 -92
  123. data/spec/lib/appsignal/loaders/padrino_spec.rb +0 -273
  124. data/spec/lib/appsignal/loaders/sinatra_spec.rb +0 -44
  125. data/spec/lib/appsignal/loaders_spec.rb +0 -144
  126. data/spec/lib/appsignal/logger_spec.rb +0 -205
  127. data/spec/lib/appsignal/marker_spec.rb +0 -51
  128. data/spec/lib/appsignal/probes/gvl_spec.rb +0 -164
  129. data/spec/lib/appsignal/probes/mri_spec.rb +0 -162
  130. data/spec/lib/appsignal/probes/sidekiq_spec.rb +0 -333
  131. data/spec/lib/appsignal/probes_spec.rb +0 -414
  132. data/spec/lib/appsignal/rack/abstract_middleware_spec.rb +0 -370
  133. data/spec/lib/appsignal/rack/body_wrapper_spec.rb +0 -319
  134. data/spec/lib/appsignal/rack/event_handler_spec.rb +0 -441
  135. data/spec/lib/appsignal/rack/grape_middleware_spec.rb +0 -201
  136. data/spec/lib/appsignal/rack/hanami_middleware_spec.rb +0 -36
  137. data/spec/lib/appsignal/rack/instrumentation_middleware_spec.rb +0 -38
  138. data/spec/lib/appsignal/rack/rails_instrumentation_spec.rb +0 -126
  139. data/spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb +0 -217
  140. data/spec/lib/appsignal/rack_spec.rb +0 -243
  141. data/spec/lib/appsignal/sample_data_spec.rb +0 -238
  142. data/spec/lib/appsignal/span_spec.rb +0 -141
  143. data/spec/lib/appsignal/system_spec.rb +0 -126
  144. data/spec/lib/appsignal/transaction_spec.rb +0 -2115
  145. data/spec/lib/appsignal/transmitter_spec.rb +0 -198
  146. data/spec/lib/appsignal/utils/data_spec.rb +0 -166
  147. data/spec/lib/appsignal/utils/hash_sanitizer_spec.rb +0 -182
  148. data/spec/lib/appsignal/utils/integration_logger_spec.rb +0 -21
  149. data/spec/lib/appsignal/utils/integration_memory_logger_spec.rb +0 -153
  150. data/spec/lib/appsignal/utils/json_spec.rb +0 -44
  151. data/spec/lib/appsignal/utils/query_params_sanitizer_spec.rb +0 -192
  152. data/spec/lib/appsignal_spec.rb +0 -1919
  153. data/spec/lib/puma/appsignal_spec.rb +0 -334
  154. data/spec/spec_helper.rb +0 -179
  155. data/spec/support/fixtures/generated_config.yml +0 -24
  156. data/spec/support/fixtures/projects/broken/config/appsignal.yml +0 -1
  157. data/spec/support/fixtures/projects/valid/config/appsignal.yml +0 -57
  158. data/spec/support/fixtures/projects/valid/log/.gitkeep +0 -0
  159. data/spec/support/fixtures/projects/valid_with_rails_app/config/application.rb +0 -16
  160. data/spec/support/fixtures/projects/valid_with_rails_app/config/appsignal.yml +0 -56
  161. data/spec/support/fixtures/projects/valid_with_rails_app/config/environment.rb +0 -10
  162. data/spec/support/fixtures/projects/valid_with_rails_app/log/.gitkeep +0 -0
  163. data/spec/support/fixtures/uploaded_file.txt +0 -0
  164. data/spec/support/hanami/hanami_app.rb +0 -29
  165. data/spec/support/helpers/action_mailer_helpers.rb +0 -25
  166. data/spec/support/helpers/activejob_helpers.rb +0 -27
  167. data/spec/support/helpers/api_request_helper.rb +0 -60
  168. data/spec/support/helpers/cli_helpers.rb +0 -40
  169. data/spec/support/helpers/config_helpers.rb +0 -66
  170. data/spec/support/helpers/dependency_helper.rb +0 -155
  171. data/spec/support/helpers/directory_helper.rb +0 -27
  172. data/spec/support/helpers/env_helpers.rb +0 -41
  173. data/spec/support/helpers/environment_metdata_helper.rb +0 -16
  174. data/spec/support/helpers/example_exception.rb +0 -13
  175. data/spec/support/helpers/example_standard_error.rb +0 -13
  176. data/spec/support/helpers/loader_helper.rb +0 -21
  177. data/spec/support/helpers/log_helpers.rb +0 -36
  178. data/spec/support/helpers/rails_helper.rb +0 -28
  179. data/spec/support/helpers/std_streams_helper.rb +0 -94
  180. data/spec/support/helpers/system_helpers.rb +0 -8
  181. data/spec/support/helpers/take_at_most_helper.rb +0 -21
  182. data/spec/support/helpers/time_helpers.rb +0 -11
  183. data/spec/support/helpers/transaction_helpers.rb +0 -122
  184. data/spec/support/helpers/wait_for_helper.rb +0 -39
  185. data/spec/support/matchers/contains_log.rb +0 -26
  186. data/spec/support/matchers/have_colorized_text.rb +0 -28
  187. data/spec/support/matchers/transaction.rb +0 -200
  188. data/spec/support/mocks/appsignal_mock.rb +0 -18
  189. data/spec/support/mocks/dummy_app.rb +0 -20
  190. data/spec/support/mocks/fake_gc_profiler.rb +0 -19
  191. data/spec/support/mocks/fake_gvl_tools.rb +0 -28
  192. data/spec/support/mocks/hash_like.rb +0 -10
  193. data/spec/support/mocks/mock_probe.rb +0 -13
  194. data/spec/support/mocks/puma_mock.rb +0 -43
  195. data/spec/support/shared_examples/instrument.rb +0 -48
  196. data/spec/support/stubs/appsignal/loaders/loader_stub.rb +0 -7
  197. data/spec/support/stubs/delayed_job.rb +0 -0
  198. data/spec/support/stubs/sidekiq/api.rb +0 -4
  199. data/spec/support/testing.rb +0 -203
  200. data/support/bundler_wrapper +0 -12
  201. data/support/install_deps +0 -33
@@ -1,1380 +0,0 @@
1
- describe Appsignal::Config do
2
- describe ".add_loader_defaults" do
3
- context "when the config is initialized" do
4
- before { Appsignal.configure(:test) }
5
-
6
- it "logs a warning" do
7
- logs = capture_logs { described_class.add_loader_defaults(:loader1) }
8
-
9
- expect(logs).to contains_log(
10
- :warn,
11
- "The config defaults from the 'loader1' loader are ignored"
12
- )
13
- end
14
- end
15
-
16
- it "adds loader defaults to the list" do
17
- described_class.add_loader_defaults(:loader1)
18
-
19
- expect(described_class.loader_defaults).to include(
20
- :name => :loader1,
21
- :root_path => nil,
22
- :env => nil,
23
- :options => {}
24
- )
25
- end
26
-
27
- it "registers multiple loaders in order of registration" do
28
- described_class.add_loader_defaults(:loader1)
29
- described_class.add_loader_defaults(:loader2)
30
-
31
- expect(described_class.loader_defaults).to eq([
32
- {
33
- :name => :loader1,
34
- :root_path => nil,
35
- :env => nil,
36
- :options => {}
37
- },
38
- {
39
- :name => :loader2,
40
- :root_path => nil,
41
- :env => nil,
42
- :options => {}
43
- }
44
- ])
45
- end
46
-
47
- it "adds loader with env and root_path" do
48
- described_class.add_loader_defaults(
49
- :loader1,
50
- :root_path => "/some-path",
51
- :env => "loader_env1"
52
- )
53
-
54
- expect(described_class.loader_defaults).to include(
55
- :name => :loader1,
56
- :root_path => "/some-path",
57
- :env => "loader_env1",
58
- :options => {}
59
- )
60
- end
61
-
62
- it "adds loader with options" do
63
- described_class.add_loader_defaults(
64
- :loader1,
65
- :my_option1 => "some value1",
66
- :my_option2 => "some value2"
67
- )
68
-
69
- expect(described_class.loader_defaults).to include(
70
- :name => :loader1,
71
- :root_path => nil,
72
- :env => nil,
73
- :options => {
74
- :my_option1 => "some value1",
75
- :my_option2 => "some value2"
76
- }
77
- )
78
- end
79
-
80
- it "does not set any nil options" do
81
- described_class.add_loader_defaults(:loader1, :nil_option => nil)
82
-
83
- expect(described_class.loader_defaults).to include(
84
- :name => :loader1,
85
- :root_path => nil,
86
- :env => nil,
87
- :options => {}
88
- )
89
- end
90
- end
91
-
92
- describe ".determine_env" do
93
- context "with env argument" do
94
- before { clear_integration_env_vars! }
95
-
96
- it "considers the given env leading" do
97
- expect(described_class.determine_env("given_env")).to eq("given_env")
98
- end
99
-
100
- it "considers the given env leading over APPSIGNAL_APP_ENV" do
101
- ENV["APPSIGNAL_APP_ENV"] = "env_env"
102
- expect(described_class.determine_env("given_env")).to eq("given_env")
103
- end
104
-
105
- it "considers the given env leading over other env vars" do
106
- ENV["RAILS_ENV"] = "rails_env"
107
- ENV["RACK_ENV"] = "rack_env"
108
- expect(described_class.determine_env("given_env")).to eq("given_env")
109
- end
110
-
111
- it "considers the given env leading over loader defaults" do
112
- define_loader(:env_loader) do
113
- def on_load
114
- register_config_defaults(:env => "loader_env")
115
- end
116
- end
117
- load_loader(:env_loader)
118
- expect(described_class.determine_env("given_env")).to eq("given_env")
119
- end
120
- end
121
-
122
- context "without env argument" do
123
- before { clear_integration_env_vars! }
124
-
125
- it "considers the APPSIGNAL_APP_ENV leading" do
126
- ENV["APPSIGNAL_APP_ENV"] = "env_env"
127
- ENV["RAILS_ENV"] = "rails_env"
128
- ENV["RACK_ENV"] = "rack_env"
129
- expect(described_class.determine_env).to eq("env_env")
130
- end
131
-
132
- it "considers the RAILS_ENV leading over other env vars" do
133
- ENV["RAILS_ENV"] = "rails_env"
134
- ENV["RACK_ENV"] = "rack_env"
135
- expect(described_class.determine_env).to eq("rails_env")
136
- end
137
-
138
- it "reads from the RACK_ENV env last" do
139
- ENV["RACK_ENV"] = "rack_env"
140
- expect(described_class.determine_env).to eq("rack_env")
141
- end
142
-
143
- it "falls back on the first loader env" do
144
- define_loader(:env_loader1) do
145
- def on_load
146
- register_config_defaults(:env => "loader_env1")
147
- end
148
- end
149
- load_loader(:env_loader1)
150
-
151
- define_loader(:env_loader2) do
152
- def on_load
153
- register_config_defaults(:env => "loader_env2")
154
- end
155
- end
156
- load_loader(:env_loader2)
157
-
158
- expect(described_class.determine_env).to eq("loader_env2")
159
- end
160
-
161
- it "returns nil if no env was found" do
162
- expect(described_class.determine_env).to be_nil
163
- end
164
- end
165
- end
166
-
167
- describe ".determine_root_path" do
168
- it "reads the root path from the first loader if any" do
169
- define_loader(:path_loader1) do
170
- def on_load
171
- register_config_defaults(:root_path => "/loader_path1")
172
- end
173
- end
174
- load_loader(:path_loader1)
175
-
176
- define_loader(:path_loader2) do
177
- def on_load
178
- register_config_defaults(:root_path => "/loader_path2")
179
- end
180
- end
181
- load_loader(:path_loader2)
182
-
183
- expect(described_class.determine_root_path).to eq("/loader_path2")
184
- end
185
-
186
- it "falls back on the current working directory" do
187
- expect(described_class.determine_root_path).to eq(Dir.pwd)
188
- end
189
- end
190
-
191
- describe "#initialize" do
192
- describe "environment" do
193
- context "when environment is nil" do
194
- let(:config) { described_class.new("", nil) }
195
-
196
- it "sets an empty string" do
197
- expect(config.env).to eq("")
198
- end
199
- end
200
-
201
- context "when environment is given" do
202
- let(:env) { "my_env" }
203
- let(:config) { described_class.new("/root/path", "my_env") }
204
-
205
- it "sets the environment" do
206
- expect(config.env).to eq(env)
207
- end
208
-
209
- it "sets the environment as loaded through the initial_config" do
210
- expect(config.initial_config).to eq(:env => env)
211
- expect(config.config_hash).to_not have_key(:env)
212
- expect(config.config_hash).to_not have_key(:root_path)
213
- end
214
-
215
- context "with APPSIGNAL_APP_ENV environment variable" do
216
- let(:env_env) { "my_env_env" }
217
- before { ENV["APPSIGNAL_APP_ENV"] = env_env }
218
-
219
- it "sets the environment as loaded through the env_config" do
220
- expect(config.env_config).to eq(:env => env_env)
221
- end
222
- end
223
- end
224
- end
225
- end
226
-
227
- describe "config based on the system" do
228
- let(:config) { silence { build_config(:env => :none) } }
229
-
230
- describe ":active" do
231
- subject { config[:active] }
232
-
233
- context "with APPSIGNAL_PUSH_API_KEY env variable" do
234
- context "when not empty" do
235
- before { ENV["APPSIGNAL_PUSH_API_KEY"] = "abc" }
236
-
237
- it "becomes active" do
238
- expect(subject).to be_truthy
239
- end
240
-
241
- it "sets the push_api_key as loaded through the env_config" do
242
- expect(config.env_config).to include(:push_api_key => "abc")
243
- expect(config.system_config).to include(:active => true)
244
- end
245
- end
246
-
247
- context "when empty string" do
248
- before { ENV["APPSIGNAL_PUSH_API_KEY"] = "" }
249
-
250
- it "does not becomes active" do
251
- expect(subject).to be_falsy
252
- end
253
-
254
- it "sets the push_api_key as loaded through the env_config" do
255
- expect(config.env_config).to include(:push_api_key => "")
256
- expect(config.system_config).to_not have_key(:active)
257
- end
258
- end
259
-
260
- context "when blank string" do
261
- before { ENV["APPSIGNAL_PUSH_API_KEY"] = " " }
262
-
263
- it "does not becomes active" do
264
- expect(subject).to be_falsy
265
- end
266
-
267
- it "sets the push_api_key as loaded through the env_config" do
268
- expect(config.env_config).to include(:push_api_key => " ")
269
- expect(config.system_config).to_not have_key(:active)
270
- end
271
- end
272
- end
273
-
274
- context "without APPSIGNAL_PUSH_API_KEY env variable" do
275
- it "remains inactive" do
276
- expect(subject).to be_falsy
277
- end
278
- end
279
- end
280
-
281
- describe ":log" do
282
- subject { config[:log] }
283
-
284
- context "when running on Heroku" do
285
- around { |example| recognize_as_heroku { example.run } }
286
-
287
- it "is set to stdout" do
288
- expect(subject).to eq("stdout")
289
- end
290
-
291
- it "sets the log as loaded through the system" do
292
- expect(config.system_config).to include(:log => "stdout")
293
- end
294
- end
295
-
296
- context "when not running on Heroku" do
297
- it "is set to file" do
298
- expect(subject).to eq("file")
299
- end
300
-
301
- it "does not set log as loaded through the system" do
302
- expect(config.system_config).to_not have_key(:log)
303
- end
304
- end
305
- end
306
- end
307
-
308
- describe "loader default config" do
309
- let(:config) { described_class.new("some-path", "production") }
310
- before do
311
- define_loader(:options_loader) do
312
- def on_load
313
- register_config_defaults(
314
- :env => "loader_env",
315
- :root_path => "loader-path",
316
- :ignore_actions => ["loader-action"],
317
- :my_option => "my_value",
318
- :nil_option => nil
319
- )
320
- end
321
- end
322
- load_loader(:options_loader)
323
- end
324
-
325
- it "overrides the default config option values" do
326
- expect(config[:ignore_actions]).to eq(["loader-action"])
327
- end
328
-
329
- it "does not set any nil values" do
330
- expect(config.config_hash).to_not have_key(:nil_option)
331
- end
332
-
333
- it "does not set the env" do
334
- # This is done by Config.determine_env
335
- expect(config.env).to eq("production")
336
- end
337
-
338
- it "does not set the root_path" do
339
- # This is done by Config.determine_root_path
340
- expect(config.root_path).to eq("some-path")
341
- end
342
-
343
- context "with multiple loaders" do
344
- before do
345
- define_loader(:options_loader2) do
346
- def on_load
347
- register_config_defaults(
348
- :my_option => "second_value",
349
- :second_option => "second_value"
350
- )
351
- end
352
- end
353
- load_loader(:options_loader2)
354
- end
355
-
356
- it "makes the first loader's config leading" do
357
- expect(config.config_hash).to include(
358
- :my_option => "my_value",
359
- :second_option => "second_value"
360
- )
361
- end
362
- end
363
- end
364
-
365
- context "when root path is nil" do
366
- let(:config) { described_class.new(nil, "production") }
367
-
368
- it "is not valid or active" do
369
- expect(config.valid?).to be_falsy
370
- expect(config.active?).to be_falsy
371
- end
372
- end
373
-
374
- context "without config file" do
375
- let(:config) { described_class.new(tmp_dir, "production") }
376
-
377
- it "is not valid or active" do
378
- expect(config.valid?).to be_falsy
379
- expect(config.active?).to be_falsy
380
- end
381
- end
382
-
383
- context "with a config file" do
384
- let(:config) { build_config(:env => "production") }
385
-
386
- context "with valid config" do
387
- it "is valid and active" do
388
- expect(config.valid?).to be_truthy
389
- expect(config.active?).to be_truthy
390
- end
391
-
392
- it "does not log an error" do
393
- log = capture_logs { config }
394
- expect(log).to_not contains_log(:error)
395
- end
396
- end
397
-
398
- context "with the config file causing an error" do
399
- let(:config_path) do
400
- File.expand_path(
401
- File.join(File.dirname(__FILE__), "../../support/fixtures/projects/broken")
402
- )
403
- end
404
- let(:config) { described_class.new(config_path, "production") }
405
-
406
- it "does not start AppSignal, logs & prints an error" do
407
- stdout = std_stream
408
- stderr = std_stream
409
- ENV["APPSIGNAL_ACTIVE"] = "true"
410
- ENV["APPSIGNAL_APP_NAME"] = "My app"
411
- ENV["APPSIGNAL_APP_ENV"] = "dev"
412
- ENV["APPSIGNAL_PUSH_API_KEY"] = "something valid"
413
- log = capture_logs { capture_std_streams(stdout, stderr) { config } }
414
- message = "An error occurred while loading the AppSignal config file. " \
415
- "Not starting AppSignal.\n" \
416
- "File: #{File.join(config_path, "config", "appsignal.yml").inspect}\n" \
417
- "KeyError: key not found"
418
- expect(log).to contains_log :error, message
419
- expect(log).to include("/appsignal/config.rb:") # Backtrace
420
- expect(stdout.read).to_not include("appsignal:")
421
- expect(stderr.read).to include "appsignal: #{message}"
422
- expect(config.file_config).to eql({})
423
- expect(config.active?).to be(false)
424
- end
425
- end
426
-
427
- it "sets the file_config" do
428
- # config found in spec/support/project_fixture/config/appsignal.yml
429
- expect(config.file_config).to match(
430
- :active => true,
431
- :push_api_key => "abc",
432
- :name => "TestApp",
433
- :enable_minutely_probes => false
434
- )
435
- end
436
-
437
- describe "overriding system and defaults config" do
438
- let(:config) do
439
- build_config(
440
- :root_path => "non-existing-path",
441
- :env => "production",
442
- :options => {
443
- :running_in_container => true,
444
- :debug => true,
445
- :log_level => "debug"
446
- }
447
- )
448
- end
449
-
450
- it "overrides system detected and defaults config" do
451
- expect(config[:running_in_container]).to be_truthy
452
- expect(config[:debug]).to be_truthy
453
- expect(config[:log_level]).to eq("debug")
454
- end
455
- end
456
-
457
- context "with the env name as a symbol" do
458
- let(:config) { build_config(:env => :production) }
459
-
460
- it "loads the config" do
461
- expect(config.valid?).to be_truthy
462
- expect(config.active?).to be_truthy
463
-
464
- expect(config[:push_api_key]).to eq("abc")
465
- end
466
- end
467
-
468
- context "without the selected env" do
469
- let(:config) { build_config(:env => :nonsense) }
470
-
471
- it "is not valid or active" do
472
- expect(config.valid?).to be_falsy
473
- expect(config.active?).to be_falsy
474
- end
475
-
476
- it "logs an error" do
477
- logs = capture_logs { config }
478
- expect(logs)
479
- .to contains_log(:error, "Not loading from config file: config for 'nonsense' not found")
480
- expect(logs)
481
- .to contains_log(:error, "Push API key not set after loading config")
482
- end
483
- end
484
- end
485
-
486
- context "with config in the environment" do
487
- let(:config) do
488
- described_class.new(
489
- "non-existing-path",
490
- "production"
491
- ).tap(&:validate)
492
- end
493
- let(:working_directory_path) { File.join(tmp_dir, "test_working_directory_path") }
494
- let(:env_config) do
495
- {
496
- :active => true,
497
- :activejob_report_errors => "all",
498
- :bind_address => "0.0.0.0",
499
- :ca_file_path => "/some/path",
500
- :cpu_count => 1.5,
501
- :dns_servers => ["8.8.8.8", "8.8.4.4"],
502
- :enable_allocation_tracking => false,
503
- :enable_at_exit_reporter => false,
504
- :enable_gvl_global_timer => false,
505
- :enable_gvl_waiting_threads => false,
506
- :enable_host_metrics => false,
507
- :enable_minutely_probes => false,
508
- :enable_nginx_metrics => false,
509
- :enable_rails_error_reporter => false,
510
- :enable_rake_performance_instrumentation => false,
511
- :enable_statsd => false,
512
- :endpoint => "https://test.appsignal.com",
513
- :files_world_accessible => false,
514
- :filter_metadata => ["key1", "key2"],
515
- :filter_parameters => ["param1", "param2"],
516
- :filter_session_data => ["session1", "session2"],
517
- :host_role => "my host role",
518
- :hostname => "my hostname",
519
- :http_proxy => "some proxy",
520
- :ignore_actions => ["action1", "action2"],
521
- :ignore_errors => ["ExampleStandardError", "AnotherError"],
522
- :ignore_logs => ["^start$", "^Completed 2.* in .*ms (.*)"],
523
- :ignore_namespaces => ["admin", "private_namespace"],
524
- :instrument_http_rb => false,
525
- :instrument_net_http => false,
526
- :instrument_redis => false,
527
- :instrument_sequel => false,
528
- :log => "file",
529
- :log_level => "debug",
530
- :log_path => "/tmp/something",
531
- :logging_endpoint => "https://appsignal-endpoint.net/test",
532
- :name => "App name",
533
- :push_api_key => "aaa-bbb-ccc",
534
- :request_headers => ["accept", "accept-charset"],
535
- :revision => "v2.5.1",
536
- :running_in_container => true,
537
- :send_environment_metadata => false,
538
- :send_params => false,
539
- :send_session_data => false,
540
- :sidekiq_report_errors => "all",
541
- :statsd_port => "7890",
542
- :working_directory_path => working_directory_path
543
- }
544
- end
545
- let(:env_vars) do
546
- {
547
- # Strings
548
- "APPSIGNAL_ACTIVEJOB_REPORT_ERRORS" => "all",
549
- "APPSIGNAL_APP_NAME" => "App name",
550
- "APPSIGNAL_BIND_ADDRESS" => "0.0.0.0",
551
- "APPSIGNAL_CA_FILE_PATH" => "/some/path",
552
- "APPSIGNAL_HOSTNAME" => "my hostname",
553
- "APPSIGNAL_HOST_ROLE" => "my host role",
554
- "APPSIGNAL_HTTP_PROXY" => "some proxy",
555
- "APPSIGNAL_LOG" => "file",
556
- "APPSIGNAL_LOGGING_ENDPOINT" => "https://appsignal-endpoint.net/test",
557
- "APPSIGNAL_LOG_LEVEL" => "debug",
558
- "APPSIGNAL_LOG_PATH" => "/tmp/something",
559
- "APPSIGNAL_PUSH_API_ENDPOINT" => "https://test.appsignal.com",
560
- "APPSIGNAL_PUSH_API_KEY" => "aaa-bbb-ccc",
561
- "APPSIGNAL_SIDEKIQ_REPORT_ERRORS" => "all",
562
- "APPSIGNAL_STATSD_PORT" => "7890",
563
- "APPSIGNAL_WORKING_DIRECTORY_PATH" => working_directory_path,
564
- "APP_REVISION" => "v2.5.1",
565
-
566
- # Booleans
567
- "APPSIGNAL_ACTIVE" => "true",
568
- "APPSIGNAL_ENABLE_ALLOCATION_TRACKING" => "false",
569
- "APPSIGNAL_ENABLE_AT_EXIT_REPORTER" => "false",
570
- "APPSIGNAL_ENABLE_GVL_GLOBAL_TIMER" => "false",
571
- "APPSIGNAL_ENABLE_GVL_WAITING_THREADS" => "false",
572
- "APPSIGNAL_ENABLE_HOST_METRICS" => "false",
573
- "APPSIGNAL_ENABLE_MINUTELY_PROBES" => "false",
574
- "APPSIGNAL_ENABLE_NGINX_METRICS" => "false",
575
- "APPSIGNAL_ENABLE_RAILS_ERROR_REPORTER" => "false",
576
- "APPSIGNAL_ENABLE_RAKE_PERFORMANCE_INSTRUMENTATION" => "false",
577
- "APPSIGNAL_ENABLE_STATSD" => "false",
578
- "APPSIGNAL_FILES_WORLD_ACCESSIBLE" => "false",
579
- "APPSIGNAL_INSTRUMENT_HTTP_RB" => "false",
580
- "APPSIGNAL_INSTRUMENT_NET_HTTP" => "false",
581
- "APPSIGNAL_INSTRUMENT_REDIS" => "false",
582
- "APPSIGNAL_INSTRUMENT_SEQUEL" => "false",
583
- "APPSIGNAL_RUNNING_IN_CONTAINER" => "true",
584
- "APPSIGNAL_SEND_ENVIRONMENT_METADATA" => "false",
585
- "APPSIGNAL_SEND_PARAMS" => "false",
586
- "APPSIGNAL_SEND_SESSION_DATA" => "false",
587
-
588
- # Arrays
589
- "APPSIGNAL_DNS_SERVERS" => "8.8.8.8,8.8.4.4",
590
- "APPSIGNAL_FILTER_METADATA" => "key1,key2",
591
- "APPSIGNAL_FILTER_PARAMETERS" => "param1,param2",
592
- "APPSIGNAL_FILTER_SESSION_DATA" => "session1,session2",
593
- "APPSIGNAL_IGNORE_ACTIONS" => "action1,action2",
594
- "APPSIGNAL_IGNORE_ERRORS" => "ExampleStandardError,AnotherError",
595
- "APPSIGNAL_IGNORE_LOGS" => "^start$,^Completed 2.* in .*ms (.*)",
596
- "APPSIGNAL_IGNORE_NAMESPACES" => "admin,private_namespace",
597
- "APPSIGNAL_REQUEST_HEADERS" => "accept,accept-charset",
598
-
599
- # Floats
600
- "APPSIGNAL_CPU_COUNT" => "1.5"
601
- }
602
- end
603
- before do
604
- env_vars.each do |key, value|
605
- ENV[key] = value
606
- end
607
- end
608
-
609
- it "reads all string env keys" do
610
- config
611
-
612
- Appsignal::Config::ENV_STRING_KEYS.each do |env_key, option|
613
- ENV.fetch(env_key) { raise "Config env var '#{env_key}' is not set for this test" }
614
- expect(config[option]).to eq(ENV.fetch(env_key, nil))
615
- end
616
- end
617
-
618
- it "reads all boolean env keys" do
619
- config
620
-
621
- Appsignal::Config::ENV_BOOLEAN_KEYS.each do |env_key, option|
622
- ENV.fetch(env_key) { raise "Config env var '#{env_key}' is not set for this test" }
623
- expect(config[option]).to eq(ENV.fetch(env_key, nil) == "true")
624
- end
625
- end
626
-
627
- it "reads all array env keys" do
628
- config
629
-
630
- Appsignal::Config::ENV_ARRAY_KEYS.each do |env_key, option|
631
- ENV.fetch(env_key) { raise "Config env var '#{env_key}' is not set for this test" }
632
- expect(config[option]).to eq(ENV.fetch(env_key, nil).split(","))
633
- end
634
- end
635
-
636
- it "reads all float env keys" do
637
- config
638
-
639
- Appsignal::Config::ENV_FLOAT_KEYS.each do |env_key, option|
640
- ENV.fetch(env_key) { raise "Config env var '#{env_key}' is not set for this test" }
641
- expect(config[option]).to eq(ENV.fetch(env_key, nil).to_f)
642
- end
643
- end
644
-
645
- it "overrides config with environment values" do
646
- expect(config.valid?).to be_truthy
647
- expect(config.active?).to be_truthy
648
- expect(config.config_hash).to include(env_config)
649
- end
650
-
651
- context "with mixed case `true` env variables values" do
652
- before do
653
- ENV["APPSIGNAL_ENABLE_RAKE_PERFORMANCE_INSTRUMENTATION"] = "TRUE"
654
- ENV["APPSIGNAL_INSTRUMENT_SEQUEL"] = "True"
655
- end
656
-
657
- it "accepts mixed case `true` values" do
658
- expect(config[:enable_rake_performance_instrumentation]).to eq(true)
659
- expect(config[:instrument_sequel]).to eq(true)
660
- end
661
- end
662
-
663
- it "sets the env_config" do
664
- expect(config.env_config).to eq(env_config)
665
- end
666
- end
667
-
668
- describe "DSL config" do
669
- let(:dsl_config) do
670
- {
671
- :push_api_key => "abc",
672
- :name => "TestApp",
673
- :active => true,
674
- :revision => "v2.5.1",
675
- :request_headers => []
676
- }
677
- end
678
- let(:config) do
679
- build_config(
680
- :root_path => "non-existing-path",
681
- :env => "production",
682
- :options => dsl_config
683
- )
684
- end
685
-
686
- it "merges with the default config" do
687
- expect(config.config_hash).to eq(
688
- :active => true,
689
- :activejob_report_errors => "all",
690
- :ca_file_path => File.join(resources_dir, "cacert.pem"),
691
- :dns_servers => [],
692
- :enable_allocation_tracking => true,
693
- :enable_at_exit_reporter => true,
694
- :enable_gvl_global_timer => true,
695
- :enable_gvl_waiting_threads => true,
696
- :enable_host_metrics => true,
697
- :enable_minutely_probes => true,
698
- :enable_statsd => true,
699
- :enable_nginx_metrics => false,
700
- :enable_rails_error_reporter => true,
701
- :enable_rake_performance_instrumentation => false,
702
- :endpoint => "https://push.appsignal.com",
703
- :files_world_accessible => true,
704
- :filter_metadata => [],
705
- :filter_parameters => [],
706
- :filter_session_data => [],
707
- :ignore_actions => [],
708
- :ignore_errors => [],
709
- :ignore_logs => [],
710
- :ignore_namespaces => [],
711
- :instrument_http_rb => true,
712
- :instrument_net_http => true,
713
- :instrument_redis => true,
714
- :instrument_sequel => true,
715
- :log => "file",
716
- :logging_endpoint => "https://appsignal-endpoint.net",
717
- :name => "TestApp",
718
- :push_api_key => "abc",
719
- :request_headers => [],
720
- :revision => "v2.5.1",
721
- :send_environment_metadata => true,
722
- :send_params => true,
723
- :send_session_data => true,
724
- :sidekiq_report_errors => "all"
725
- )
726
- end
727
-
728
- it "sets the dsl_config" do
729
- expect(config.dsl_config).to eq(dsl_config)
730
- end
731
-
732
- describe "overriding system detected config" do
733
- describe ":running_in_container" do
734
- let(:dsl_config) { { :running_in_container => true } }
735
- subject { config[:running_in_container] }
736
-
737
- it "overrides system detected config" do
738
- expect(subject).to be_truthy
739
- end
740
- end
741
-
742
- describe ":active" do
743
- subject { config[:active] }
744
-
745
- context "with APPSIGNAL_PUSH_API_KEY env variable" do
746
- let(:dsl_config) { { :active => false } }
747
- before { ENV["APPSIGNAL_PUSH_API_KEY"] = "abc" }
748
-
749
- it "sets given config rather than env variable" do
750
- expect(subject).to be_falsy
751
- end
752
- end
753
- end
754
- end
755
-
756
- describe "overriding loader config" do
757
- let(:config) do
758
- build_config(
759
- :root_path => "non-existing-path",
760
- :env => "production",
761
- :options => { :my_option => "initial value" }
762
- )
763
- end
764
- before do
765
- define_loader(:test_loader) do
766
- def on_load
767
- register_config_defaults(:my_option => "loader value")
768
- end
769
- end
770
- load_loader(:test_loader)
771
- end
772
-
773
- it "overrides loader config" do
774
- expect(config[:my_option]).to eq("initial value")
775
- end
776
- end
777
- end
778
-
779
- describe "config keys" do
780
- let(:config) { build_config(:options => options) }
781
-
782
- describe ":endpoint" do
783
- subject { config[:endpoint] }
784
-
785
- context "with an pre-0.12-style endpoint" do
786
- let(:options) { { :endpoint => "https://push.appsignal.com/1" } }
787
-
788
- it "strips off the path" do
789
- expect(subject).to eq "https://push.appsignal.com"
790
- end
791
- end
792
-
793
- context "with a non-standard port" do
794
- let(:options) { { :endpoint => "http://localhost:4567" } }
795
-
796
- it "keeps the port" do
797
- expect(subject).to eq "http://localhost:4567"
798
- end
799
- end
800
- end
801
-
802
- describe ":logging_endpoint" do
803
- subject { config[:logging_endpoint] }
804
-
805
- context "with a non-standard port" do
806
- let(:options) { { :logging_endpoint => "http://localhost:4567" } }
807
-
808
- it "keeps the port" do
809
- expect(subject).to eq "http://localhost:4567"
810
- end
811
- end
812
- end
813
- end
814
-
815
- describe "#[]" do
816
- let(:config) do
817
- build_config(:env => :none, :options => { :push_api_key => "foo", :request_headers => [] })
818
- end
819
-
820
- context "with existing key" do
821
- it "gets the value" do
822
- expect(config[:push_api_key]).to eq "foo"
823
- end
824
- end
825
-
826
- context "without existing key" do
827
- it "returns nil" do
828
- expect(config[:nonsense]).to be_nil
829
- end
830
- end
831
- end
832
-
833
- describe "#[]=" do
834
- let(:config) { build_config(:env => :none) }
835
-
836
- context "with existing key" do
837
- it "changes the value" do
838
- expect(config[:push_api_key]).to be_nil
839
- config[:push_api_key] = "abcde"
840
- expect(config[:push_api_key]).to eq "abcde"
841
- end
842
- end
843
-
844
- context "with new key" do
845
- it "sets the value" do
846
- expect(config[:foo]).to be_nil
847
- config[:foo] = "bar"
848
- expect(config[:foo]).to eq "bar"
849
- end
850
- end
851
- end
852
-
853
- describe "#write_to_environment" do
854
- let(:config) { build_config }
855
- before do
856
- config[:bind_address] = "0.0.0.0"
857
- config[:cpu_count] = 1.5
858
- config[:logging_endpoint] = "http://localhost:123"
859
- config[:http_proxy] = "http://localhost"
860
- config[:ignore_actions] = %w[action1 action2]
861
- config[:ignore_errors] = %w[ExampleStandardError AnotherError]
862
- config[:ignore_logs] = ["^start$", "^Completed 2.* in .*ms (.*)"]
863
- config[:ignore_namespaces] = %w[admin private_namespace]
864
- config[:log] = "stdout"
865
- config[:log_path] = "/tmp"
866
- config[:filter_parameters] = %w[password confirm_password]
867
- config[:filter_session_data] = %w[key1 key2]
868
- config[:running_in_container] = false
869
- config[:dns_servers] = ["8.8.8.8", "8.8.4.4"]
870
- config[:transaction_debug_mode] = true
871
- config[:send_environment_metadata] = false
872
- config[:revision] = "v2.5.1"
873
- config.write_to_environment
874
- end
875
-
876
- it "writes the current config to environment variables" do
877
- expect(ENV.fetch("_APPSIGNAL_ACTIVE", nil)).to eq "true"
878
- expect(ENV.fetch("_APPSIGNAL_APP_PATH", nil))
879
- .to end_with("spec/support/fixtures/projects/valid")
880
- expect(ENV.fetch("_APPSIGNAL_AGENT_PATH", nil)).to end_with("/ext")
881
- expect(ENV.fetch("_APPSIGNAL_BIND_ADDRESS", nil)).to eq("0.0.0.0")
882
- expect(ENV.fetch("_APPSIGNAL_CPU_COUNT", nil)).to eq("1.5")
883
- expect(ENV.fetch("_APPSIGNAL_LOG", nil)).to eq "stdout"
884
- expect(ENV.fetch("_APPSIGNAL_LOG_FILE_PATH", nil)).to end_with("/tmp/appsignal.log")
885
- expect(ENV.fetch("_APPSIGNAL_LOGGING_ENDPOINT", nil)).to eq "http://localhost:123"
886
- expect(ENV.fetch("_APPSIGNAL_PUSH_API_ENDPOINT", nil)).to eq "https://push.appsignal.com"
887
- expect(ENV.fetch("_APPSIGNAL_PUSH_API_KEY", nil)).to eq "abc"
888
- expect(ENV.fetch("_APPSIGNAL_APP_NAME", nil)).to eq "TestApp"
889
- expect(ENV.fetch("_APPSIGNAL_APP_ENV", nil)).to eq "production"
890
- expect(ENV.fetch("_APPSIGNAL_LANGUAGE_INTEGRATION_VERSION", nil))
891
- .to eq "ruby-#{Appsignal::VERSION}"
892
- expect(ENV.fetch("_APPSIGNAL_HTTP_PROXY", nil)).to eq "http://localhost"
893
- expect(ENV.fetch("_APPSIGNAL_IGNORE_ACTIONS", nil)).to eq "action1,action2"
894
- expect(ENV.fetch("_APPSIGNAL_IGNORE_ERRORS", nil)).to eq "ExampleStandardError,AnotherError"
895
- expect(ENV.fetch("_APPSIGNAL_IGNORE_LOGS", nil)).to eq "^start$,^Completed 2.* in .*ms (.*)"
896
- expect(ENV.fetch("_APPSIGNAL_IGNORE_NAMESPACES", nil)).to eq "admin,private_namespace"
897
- expect(ENV.fetch("_APPSIGNAL_RUNNING_IN_CONTAINER", nil)).to eq "false"
898
- expect(ENV.fetch("_APPSIGNAL_ENABLE_HOST_METRICS", nil)).to eq "true"
899
- expect(ENV.fetch("_APPSIGNAL_HOSTNAME", nil)).to eq ""
900
- expect(ENV.fetch("_APPSIGNAL_HOST_ROLE", nil)).to eq ""
901
- expect(ENV.fetch("_APPSIGNAL_PROCESS_NAME", nil)).to include "rspec"
902
- expect(ENV.fetch("_APPSIGNAL_CA_FILE_PATH", nil))
903
- .to eq File.join(resources_dir, "cacert.pem")
904
- expect(ENV.fetch("_APPSIGNAL_DNS_SERVERS", nil)).to eq "8.8.8.8,8.8.4.4"
905
- expect(ENV.fetch("_APPSIGNAL_FILES_WORLD_ACCESSIBLE", nil)).to eq "true"
906
- expect(ENV.fetch("_APPSIGNAL_SEND_ENVIRONMENT_METADATA", nil)).to eq "false"
907
- expect(ENV.fetch("_APPSIGNAL_STATSD_PORT", nil)).to eq ""
908
- expect(ENV.fetch("_APPSIGNAL_FILTER_PARAMETERS", nil)).to eq "password,confirm_password"
909
- expect(ENV.fetch("_APPSIGNAL_FILTER_SESSION_DATA", nil)).to eq "key1,key2"
910
- expect(ENV.fetch("_APP_REVISION", nil)).to eq "v2.5.1"
911
- expect(ENV).to_not have_key("_APPSIGNAL_WORKING_DIRECTORY_PATH")
912
- end
913
-
914
- context "with :hostname" do
915
- before do
916
- config[:hostname] = "Alices-MBP.example.com"
917
- config.write_to_environment
918
- end
919
-
920
- it "sets the modified :hostname" do
921
- expect(ENV.fetch("_APPSIGNAL_HOSTNAME", nil)).to eq "Alices-MBP.example.com"
922
- end
923
- end
924
-
925
- context "with :host_role" do
926
- before do
927
- config[:host_role] = "host role"
928
- config.write_to_environment
929
- end
930
-
931
- it "sets the modified :host_role" do
932
- expect(ENV.fetch("_APPSIGNAL_HOST_ROLE", nil)).to eq "host role"
933
- end
934
- end
935
-
936
- context "with :working_directory_path" do
937
- before do
938
- config[:working_directory_path] = "/tmp/appsignal2"
939
- config.write_to_environment
940
- end
941
-
942
- it "sets the modified :working_directory_path" do
943
- expect(ENV.fetch("_APPSIGNAL_WORKING_DIRECTORY_PATH", nil)).to eq "/tmp/appsignal2"
944
- end
945
- end
946
-
947
- context "with :statsd_port" do
948
- before do
949
- config[:statsd_port] = "1000"
950
- config.write_to_environment
951
- end
952
-
953
- it "sets the statsd_port env var" do
954
- expect(ENV.fetch("_APPSIGNAL_STATSD_PORT", nil)).to eq "1000"
955
- end
956
- end
957
- end
958
-
959
- describe "#log_file_path" do
960
- let(:out_stream) { std_stream }
961
- let(:output) { out_stream.read }
962
- let(:config) { build_config(:options => { :log_path => log_path }) }
963
-
964
- def log_file_path
965
- capture_stdout(out_stream) { config.log_file_path }
966
- end
967
-
968
- context "when path is writable" do
969
- let(:log_path) { File.join(tmp_dir, "writable-path") }
970
- before { FileUtils.mkdir_p(log_path, :mode => 0o755) }
971
- after { FileUtils.rm_rf(log_path) }
972
-
973
- it "returns log file path" do
974
- expect(log_file_path).to eq File.join(log_path, "appsignal.log")
975
- end
976
-
977
- it "prints no warning" do
978
- log_file_path
979
- expect(output).to be_empty
980
- end
981
- end
982
-
983
- shared_examples "#log_file_path: tmp path" do
984
- let(:system_tmp_dir) { described_class.system_tmp_dir }
985
- before { FileUtils.mkdir_p(system_tmp_dir) }
986
- after { FileUtils.rm_rf(system_tmp_dir) }
987
-
988
- context "when the /tmp fallback path is writable" do
989
- before { FileUtils.chmod(0o777, system_tmp_dir) }
990
-
991
- it "returns returns the tmp location" do
992
- expect(log_file_path).to eq(File.join(system_tmp_dir, "appsignal.log"))
993
- end
994
-
995
- it "prints a warning" do
996
- log_file_path
997
- expect(output).to include "appsignal: Unable to log to '#{log_path}'. " \
998
- "Logging to '#{system_tmp_dir}' instead."
999
- end
1000
-
1001
- it "prints a warning once" do
1002
- capture_stdout(out_stream) do
1003
- log_file_path
1004
- log_file_path
1005
- end
1006
- message = "appsignal: Unable to log to '#{log_path}'. " \
1007
- "Logging to '#{system_tmp_dir}' instead."
1008
- expect(output.scan(message).count).to eq(1)
1009
- end
1010
- end
1011
-
1012
- context "when the /tmp fallback path is not writable" do
1013
- before { FileUtils.chmod(0o555, system_tmp_dir) }
1014
-
1015
- it "returns nil" do
1016
- expect(log_file_path).to be_nil
1017
- end
1018
-
1019
- it "prints a warning" do
1020
- log_file_path
1021
- expect(output).to include "appsignal: Unable to log to '#{log_path}' " \
1022
- "or the '#{system_tmp_dir}' fallback."
1023
- end
1024
-
1025
- it "prints a warning once" do
1026
- capture_stdout(out_stream) do
1027
- log_file_path
1028
- log_file_path
1029
- end
1030
- message = "appsignal: Unable to log to '#{log_path}' or the '#{system_tmp_dir}' fallback."
1031
- expect(output.scan(message).count).to eq(1)
1032
- end
1033
- end
1034
- end
1035
-
1036
- context "when path is nil" do
1037
- let(:log_path) { nil }
1038
-
1039
- context "when root_path is nil" do
1040
- before { allow(config).to receive(:root_path).and_return(nil) }
1041
-
1042
- include_examples "#log_file_path: tmp path"
1043
- end
1044
-
1045
- context "when root_path is set" do
1046
- it "returns returns the project log location" do
1047
- expect(log_file_path).to eq File.join(config.root_path, "log/appsignal.log")
1048
- end
1049
-
1050
- it "prints no warning" do
1051
- log_file_path
1052
- expect(output).to be_empty
1053
- end
1054
- end
1055
- end
1056
-
1057
- context "when path does not exist" do
1058
- let(:log_path) { "/non-existing" }
1059
-
1060
- include_examples "#log_file_path: tmp path"
1061
- end
1062
-
1063
- context "when path is not writable" do
1064
- let(:log_path) { File.join(tmp_dir, "not-writable-path") }
1065
- before { FileUtils.mkdir_p(log_path, :mode => 0o555) }
1066
- after { FileUtils.rm_rf(log_path) }
1067
-
1068
- include_examples "#log_file_path: tmp path"
1069
- end
1070
-
1071
- context "when path is a symlink" do
1072
- context "when linked path does not exist" do
1073
- let(:real_path) { File.join(tmp_dir, "real-path") }
1074
- let(:log_path) { File.join(tmp_dir, "symlink-path") }
1075
- before { File.symlink(real_path, log_path) }
1076
- after { FileUtils.rm(log_path) }
1077
-
1078
- include_examples "#log_file_path: tmp path"
1079
- end
1080
-
1081
- context "when linked path exists" do
1082
- context "when linked path is not writable" do
1083
- let(:real_path) { File.join(tmp_dir, "real-path") }
1084
- let(:log_path) { File.join(tmp_dir, "symlink-path") }
1085
- before do
1086
- FileUtils.mkdir_p(real_path)
1087
- FileUtils.chmod(0o444, real_path)
1088
- File.symlink(real_path, log_path)
1089
- end
1090
- after do
1091
- FileUtils.rm_rf(real_path)
1092
- FileUtils.rm(log_path)
1093
- end
1094
-
1095
- include_examples "#log_file_path: tmp path"
1096
- end
1097
-
1098
- context "when linked path is writable" do
1099
- let(:real_path) { File.join(tmp_dir, "real-path") }
1100
- let(:log_path) { File.join(tmp_dir, "symlink-path") }
1101
- before do
1102
- FileUtils.mkdir_p(real_path)
1103
- File.symlink(real_path, log_path)
1104
- end
1105
- after do
1106
- FileUtils.rm_rf(real_path)
1107
- FileUtils.rm(log_path)
1108
- end
1109
-
1110
- it "returns real path of log path" do
1111
- expect(log_file_path).to eq(File.join(real_path, "appsignal.log"))
1112
- end
1113
- end
1114
- end
1115
- end
1116
- end
1117
-
1118
- describe ".system_tmp_dir" do
1119
- before do
1120
- # To counteract the stub in spec_helper
1121
- expect(Appsignal::Config).to receive(:system_tmp_dir).and_call_original
1122
- end
1123
-
1124
- context "when on a *NIX OS" do
1125
- before do
1126
- expect(Gem).to receive(:win_platform?).and_return(false)
1127
- end
1128
-
1129
- it "returns the system's tmp dir" do
1130
- expect(described_class.system_tmp_dir).to eq(File.realpath("/tmp"))
1131
- end
1132
- end
1133
-
1134
- context "when on Microsoft Windows" do
1135
- before do
1136
- expect(Gem).to receive(:win_platform?).and_return(true)
1137
- end
1138
-
1139
- it "returns the system's tmp dir" do
1140
- expect(described_class.system_tmp_dir).to eq(Dir.tmpdir)
1141
- end
1142
- end
1143
- end
1144
-
1145
- describe "#validate" do
1146
- subject { config.valid? }
1147
- let(:config) do
1148
- build_config(:root_path => Dir.pwd, :env => "production", :options => config_options)
1149
- end
1150
-
1151
- if DependencyHelper.rails_present?
1152
- require "active_job"
1153
-
1154
- context "activejob_report_errors" do
1155
- let(:config_options) { { :activejob_report_errors => "discard" } }
1156
-
1157
- if DependencyHelper.rails_version >= Gem::Version.new("7.1.0")
1158
- context "when Active Job >= 7.1 and 'discard'" do
1159
- it "does not override the activejob_report_errors value" do
1160
- expect(config[:activejob_report_errors]).to eq("discard")
1161
- expect(config.override_config[:activejob_report_errors]).to be_nil
1162
- end
1163
- end
1164
- else
1165
- context "when Active Job < 7.1 and 'discard'" do
1166
- it "sets activejob_report_errors to 'all'" do
1167
- expect(config[:activejob_report_errors]).to eq("all")
1168
- expect(config.override_config[:activejob_report_errors]).to eq("all")
1169
- end
1170
- end
1171
- end
1172
- end
1173
- end
1174
-
1175
- context "sidekiq_report_errors" do
1176
- let(:config_options) { { :sidekiq_report_errors => "discard" } }
1177
- before do
1178
- if Appsignal::Hooks::SidekiqHook.instance_variable_defined?(:@version_5_1_or_higher)
1179
- Appsignal::Hooks::SidekiqHook.remove_instance_variable(:@version_5_1_or_higher)
1180
- end
1181
- end
1182
-
1183
- context "when Sidekiq >= 5.1 and 'discard'" do
1184
- before { stub_const("Sidekiq::VERSION", "5.1.0") }
1185
-
1186
- it "does not override the sidekiq_report_errors value" do
1187
- expect(config[:sidekiq_report_errors]).to eq("discard")
1188
- expect(config.override_config[:sidekiq_report_errors]).to be_nil
1189
- end
1190
- end
1191
-
1192
- context "when Sidekiq < 5.1 and 'discard'" do
1193
- before { stub_const("Sidekiq::VERSION", "5.0.0") }
1194
-
1195
- it "sets sidekiq_report_errors to 'all'" do
1196
- expect(config[:sidekiq_report_errors]).to eq("all")
1197
- expect(config.override_config[:sidekiq_report_errors]).to eq("all")
1198
- end
1199
- end
1200
- end
1201
-
1202
- describe "push_api_key" do
1203
- let(:config_options) { { :push_api_key => push_api_key, :request_headers => [] } }
1204
- before { config.validate }
1205
-
1206
- context "with missing push_api_key" do
1207
- let(:push_api_key) { nil }
1208
-
1209
- it "sets valid to false" do
1210
- is_expected.to eq(false)
1211
- end
1212
- end
1213
-
1214
- context "with empty push_api_key" do
1215
- let(:push_api_key) { "" }
1216
-
1217
- it "sets valid to false" do
1218
- is_expected.to eq(false)
1219
- end
1220
- end
1221
-
1222
- context "with blank push_api_key" do
1223
- let(:push_api_key) { " " }
1224
-
1225
- it "sets valid to false" do
1226
- is_expected.to eq(false)
1227
- end
1228
- end
1229
-
1230
- context "with push_api_key present" do
1231
- let(:push_api_key) { "abc" }
1232
-
1233
- it "sets valid to true" do
1234
- is_expected.to eq(true)
1235
- end
1236
- end
1237
- end
1238
- end
1239
-
1240
- describe "#log_level" do
1241
- let(:options) { {} }
1242
- let(:config) { build_config(:root_path => "", :env => nil, :options => options) }
1243
- subject { config.log_level }
1244
-
1245
- context "without any config" do
1246
- it "returns info by default" do
1247
- is_expected.to eq(Logger::INFO)
1248
- end
1249
- end
1250
-
1251
- context "with log_level set to error" do
1252
- let(:options) { { :log_level => "error" } }
1253
- it { is_expected.to eq(Logger::ERROR) }
1254
- end
1255
-
1256
- context "with log_level set to warn" do
1257
- let(:options) { { :log_level => "warn" } }
1258
- it { is_expected.to eq(Logger::WARN) }
1259
- end
1260
-
1261
- context "with log_level set to info" do
1262
- let(:options) { { :log_level => "info" } }
1263
- it { is_expected.to eq(Logger::INFO) }
1264
- end
1265
-
1266
- context "with log_level set to debug" do
1267
- let(:options) { { :log_level => "debug" } }
1268
- it { is_expected.to eq(Logger::DEBUG) }
1269
- end
1270
-
1271
- context "with log_level set to trace" do
1272
- let(:options) { { :log_level => "trace" } }
1273
- it { is_expected.to eq(Logger::DEBUG) }
1274
- end
1275
-
1276
- context "with debug and log_level set" do
1277
- let(:options) { { :log_level => "error", :debug => true } }
1278
-
1279
- it "the log_level option is leading" do
1280
- is_expected.to eq(Logger::ERROR)
1281
- end
1282
- end
1283
-
1284
- context "with transaction_debug_mode and log_level set" do
1285
- let(:options) { { :log_level => "error", :transaction_debug_mode => true } }
1286
-
1287
- it "the log_level option is leading" do
1288
- is_expected.to eq(Logger::ERROR)
1289
- end
1290
- end
1291
-
1292
- context "with log level set to an unknown value" do
1293
- let(:options) { { :log_level => "fatal" } }
1294
-
1295
- it "prints a warning and doesn't use the log_level" do
1296
- is_expected.to eql(Logger::INFO)
1297
- end
1298
- end
1299
- end
1300
-
1301
- describe Appsignal::Config::ConfigDSL do
1302
- let(:env) { :production }
1303
- let(:config) { build_config(:env => env) }
1304
- let(:dsl) { described_class.new(config) }
1305
-
1306
- describe "default options" do
1307
- let(:env) { :unknown_env }
1308
-
1309
- it "returns default values for config options" do
1310
- Appsignal::Config::DEFAULT_CONFIG.each do |option, value|
1311
- expect(dsl.send(option)).to eq(value)
1312
- end
1313
- end
1314
- end
1315
-
1316
- it "returns already set values for config options" do
1317
- ENV["APPSIGNAL_IGNORE_ERRORS"] = "my_error1,my_error2"
1318
- config[:push_api_key] = "my push key"
1319
- config[:ignore_actions] = ["My ignored action"]
1320
-
1321
- expect(dsl.push_api_key).to eq("my push key")
1322
- expect(dsl.ignore_actions).to eq(["My ignored action"])
1323
- expect(dsl.ignore_errors).to eq(["my_error1", "my_error2"])
1324
- end
1325
-
1326
- it "returns the env" do
1327
- expect(dsl.env).to eq("production")
1328
- end
1329
-
1330
- it "sets config options" do
1331
- dsl.push_api_key = "my push key"
1332
- dsl.ignore_actions = ["My ignored action"]
1333
-
1334
- expect(dsl.push_api_key).to eq("my push key")
1335
- expect(dsl.ignore_actions).to eq(["My ignored action"])
1336
- end
1337
-
1338
- it "doesn't update the config object" do
1339
- dsl.push_api_key = "my push key"
1340
-
1341
- expect(dsl.push_api_key).to eq("my push key")
1342
- expect(config[:push_api_key]).to eq("abc") # Loaded from file
1343
- end
1344
-
1345
- it "casts strings to strings" do
1346
- dsl.activejob_report_errors = :all
1347
- dsl.sidekiq_report_errors = :all
1348
-
1349
- expect(dsl.activejob_report_errors).to eq("all")
1350
- expect(dsl.sidekiq_report_errors).to eq("all")
1351
- end
1352
-
1353
- it "casts booleans to booleans" do
1354
- dsl.active = :yes
1355
- dsl.enable_host_metrics = "An object representing a truthy value"
1356
- dsl.send_params = true
1357
- dsl.send_session_data = false
1358
-
1359
- expect(dsl.active).to be(true)
1360
- expect(dsl.enable_host_metrics).to be(true)
1361
- expect(dsl.send_params).to be(true)
1362
- expect(dsl.send_session_data).to be(false)
1363
- end
1364
-
1365
- it "casts arrays to arrays" do
1366
- ignore_actions = Set.new
1367
- ignore_actions << "my ignored action 1"
1368
- ignore_actions << "my ignored action 2"
1369
- dsl.ignore_actions = ignore_actions
1370
-
1371
- expect(dsl.ignore_actions).to eq(["my ignored action 1", "my ignored action 2"])
1372
- end
1373
-
1374
- it "casts floats to floats" do
1375
- dsl.cpu_count = 1
1376
-
1377
- expect(dsl.cpu_count).to eq(1.0)
1378
- end
1379
- end
1380
- end