appsignal 3.12.1 → 3.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 46d05d1215b1e5df918af1f3977f72113560dc8f7eb96370990830f8679bc207
4
- data.tar.gz: '095b571b4b2bb8d2e8f413d10f75ec07be08306472b2182cba69d2e628305b72'
3
+ metadata.gz: 6c3b3a593d57934c4d68cd4931ea948c5420ae2cc6e4fc43e482fab0df89165a
4
+ data.tar.gz: 0baf865761f51726ccc56b39ad9dabb7f5e0dbdb8be02ab9c1e4389b7d6595e1
5
5
  SHA512:
6
- metadata.gz: 071c32621a02badd7ba7cc4c2ddfcaed0eb1a05e271114b0bbc083ff5e1c4c2898c305c39fe36f7cb5e8cc634410f311034f04b2b2317cce1c8ce4157f8cdef9
7
- data.tar.gz: b60993c16502163d34dd7352a7636cea2fd4f7b572b241282d819be0e4a4d21dc739f52a615f2e4dd5ed28197b8873631b3288abfb29671fcd52b1f7cc2a6b3e
6
+ metadata.gz: 24e03e7a0255146b69fc04dbafb01f446d51f0ab2a72f3596b922b42f652a344b12171a6bc8d94e00d91da666fa40f4fa5820996c1fa2fe0651a23abd90a2cb4
7
+ data.tar.gz: 01b1507a66c700c640a5465f9ec15d2a0f8b5ea42f1ba246b8daa0a81816eaf0d04a37dcc13325686576ef2d47b3ee1d36488d0af3f8ee443c2905278d0bd9b6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # AppSignal for Ruby gem Changelog
2
2
 
3
+ ## 3.12.2
4
+
5
+ _Published on 2024-07-25._
6
+
7
+ ### Fixed
8
+
9
+ - Fix the default env and root path for the integrations using loader mechanism. If `APPSIGNAL_APP_ENV` is set when using `Appsignal.load(...)`, the AppSignal env set in `APPSIGNAL_APP_ENV` is now leading again. (patch [b2d1c7ee](https://github.com/appsignal/appsignal-ruby/commit/b2d1c7ee082e6865d9dc8d23ef060ecec9197a0e))
10
+
3
11
  ## 3.12.1
4
12
 
5
13
  _Published on 2024-07-25._
@@ -20,6 +20,35 @@ module Appsignal
20
20
  loader_defaults << [name, options]
21
21
  end
22
22
 
23
+ # Determine which env AppSignal should initialize with.
24
+ # @api private
25
+ def self.determine_env(initial_env = nil)
26
+ [
27
+ initial_env,
28
+ ENV.fetch("APPSIGNAL_APP_ENV", nil),
29
+ ENV.fetch("RAILS_ENV", nil),
30
+ ENV.fetch("RACK_ENV", nil)
31
+ ].compact.each do |env|
32
+ return env if env
33
+ end
34
+
35
+ loader_defaults.reverse.each do |(_loader_name, loader_defaults)|
36
+ env = loader_defaults[:env]
37
+ return env if env
38
+ end
39
+ end
40
+
41
+ # Determine which root path AppSignal should initialize with.
42
+ # @api private
43
+ def self.determine_root_path
44
+ loader_defaults.reverse.each do |(_loader_name, loader_defaults)|
45
+ root_path = loader_defaults[:root_path]
46
+ return root_path if root_path
47
+ end
48
+
49
+ Dir.pwd
50
+ end
51
+
23
52
  # @api private
24
53
  DEFAULT_CONFIG = {
25
54
  :activejob_report_errors => "all",
@@ -226,7 +255,9 @@ module Appsignal
226
255
 
227
256
  return unless load_on_new
228
257
 
229
- # Determine starting environment
258
+ # Always override environment if set via this env var.
259
+ # TODO: This is legacy behavior. In the `Appsignal.configure` method the
260
+ # env argument is leading.
230
261
  @env = ENV["APPSIGNAL_APP_ENV"] if ENV.key?("APPSIGNAL_APP_ENV")
231
262
  load_config
232
263
  validate
@@ -242,20 +273,7 @@ module Appsignal
242
273
  @system_config = detect_from_system
243
274
  merge(system_config)
244
275
 
245
- # Set defaults from loaders in reverse order so the first register
246
- # loader's defaults overwrite all others
247
- self.class.loader_defaults.reverse.each do |(_loader_name, loader_defaults)|
248
- defaults = loader_defaults.compact.dup
249
- # Overwrite root path
250
- loader_path = defaults.delete(:root_path)
251
- @root_path = loader_path if loader_path
252
- # Overwrite env
253
- loader_env = defaults.delete(:env)
254
- @env = loader_env.to_s if loader_env
255
- # Merge with the config loaded so far
256
- merge(defaults)
257
- end
258
-
276
+ # Merge initial config
259
277
  merge(initial_config)
260
278
  # Track origin of env
261
279
  @initial_config[:env] = @initial_env.to_s
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Appsignal
4
- VERSION = "3.12.1"
4
+ VERSION = "3.12.2"
5
5
  end
data/lib/appsignal.rb CHANGED
@@ -121,10 +121,7 @@ module Appsignal
121
121
 
122
122
  internal_logger.debug("Loading AppSignal gem")
123
123
 
124
- @config ||= Config.new(
125
- Dir.pwd,
126
- ENV["APPSIGNAL_APP_ENV"] || ENV["RAILS_ENV"] || ENV.fetch("RACK_ENV", nil)
127
- )
124
+ @config ||= Config.new(Config.determine_root_path, Config.determine_env)
128
125
 
129
126
  _start_logger
130
127
 
@@ -247,9 +244,9 @@ module Appsignal
247
244
  if config && config.env == env.to_s
248
245
  config
249
246
  else
250
- self._config = Appsignal::Config.new(
251
- Dir.pwd,
252
- env || ENV["APPSIGNAL_APP_ENV"] || ENV["RAILS_ENV"] || ENV.fetch("RACK_ENV", nil),
247
+ @config = Config.new(
248
+ Config.determine_root_path,
249
+ Config.determine_env(env),
253
250
  {},
254
251
  Appsignal.internal_logger,
255
252
  nil,
@@ -1,4 +1,99 @@
1
1
  describe Appsignal::Config do
2
+ describe ".determine_env" do
3
+ context "with env argument" do
4
+ before { clear_integration_env_vars! }
5
+
6
+ it "considers the given env leading" do
7
+ expect(described_class.determine_env("given_env")).to eq("given_env")
8
+ end
9
+
10
+ it "considers the given env leading over APPSIGNAL_APP_ENV" do
11
+ ENV["APPSIGNAL_APP_ENV"] = "env_env"
12
+ expect(described_class.determine_env("given_env")).to eq("given_env")
13
+ end
14
+
15
+ it "considers the given env leading over other env vars" do
16
+ ENV["RAILS_ENV"] = "rails_env"
17
+ ENV["RACK_ENV"] = "rack_env"
18
+ expect(described_class.determine_env("given_env")).to eq("given_env")
19
+ end
20
+
21
+ it "considers the given env leading over loader defaults" do
22
+ define_loader(:env_loader) do
23
+ def on_load
24
+ register_config_defaults(:env => "loader_env")
25
+ end
26
+ end
27
+ load_loader(:env_loader)
28
+ expect(described_class.determine_env("given_env")).to eq("given_env")
29
+ end
30
+ end
31
+
32
+ context "without env argument" do
33
+ before { clear_integration_env_vars! }
34
+
35
+ it "considers the APPSIGNAL_APP_ENV leading" do
36
+ ENV["APPSIGNAL_APP_ENV"] = "env_env"
37
+ ENV["RAILS_ENV"] = "rails_env"
38
+ ENV["RACK_ENV"] = "rack_env"
39
+ expect(described_class.determine_env).to eq("env_env")
40
+ end
41
+
42
+ it "considers the RAILS_ENV leading over other env vars" do
43
+ ENV["RAILS_ENV"] = "rails_env"
44
+ ENV["RACK_ENV"] = "rack_env"
45
+ expect(described_class.determine_env).to eq("rails_env")
46
+ end
47
+
48
+ it "reads from the RACK_ENV env last" do
49
+ ENV["RACK_ENV"] = "rack_env"
50
+ expect(described_class.determine_env).to eq("rack_env")
51
+ end
52
+
53
+ it "falls back on the first loader env" do
54
+ define_loader(:env_loader1) do
55
+ def on_load
56
+ register_config_defaults(:env => "loader_env1")
57
+ end
58
+ end
59
+ load_loader(:env_loader1)
60
+
61
+ define_loader(:env_loader2) do
62
+ def on_load
63
+ register_config_defaults(:env => "loader_env2")
64
+ end
65
+ end
66
+ load_loader(:env_loader2)
67
+
68
+ expect(described_class.determine_env).to eq("loader_env2")
69
+ end
70
+ end
71
+ end
72
+
73
+ describe ".determine_root_path" do
74
+ it "reads the root path from the first loader if any" do
75
+ define_loader(:path_loader1) do
76
+ def on_load
77
+ register_config_defaults(:root_path => "/loader_path1")
78
+ end
79
+ end
80
+ load_loader(:path_loader1)
81
+
82
+ define_loader(:path_loader2) do
83
+ def on_load
84
+ register_config_defaults(:root_path => "/loader_path2")
85
+ end
86
+ end
87
+ load_loader(:path_loader2)
88
+
89
+ expect(described_class.determine_root_path).to eq("/loader_path2")
90
+ end
91
+
92
+ it "falls back on the current working directory" do
93
+ expect(described_class.determine_root_path).to eq(Dir.pwd)
94
+ end
95
+ end
96
+
2
97
  describe "#initialize" do
3
98
  describe "environment" do
4
99
  context "when environment is nil" do
@@ -123,76 +218,6 @@ describe Appsignal::Config do
123
218
  end
124
219
  end
125
220
 
126
- describe "loader default config" do
127
- let(:config) do
128
- described_class.new("some-path", "production")
129
- end
130
- before do
131
- class TestLoader < Appsignal::Loaders::Loader
132
- register :test
133
- def on_load
134
- register_config_defaults(
135
- :env => "new_env",
136
- :root_path => "/some/path",
137
- :my_option => "my_value",
138
- :nil_option => nil
139
- )
140
- end
141
- end
142
- load_loader(:test)
143
- end
144
- after do
145
- Object.send(:remove_const, :TestLoader)
146
- unregister_loader(:first)
147
- end
148
-
149
- it "merges with the loader defaults" do
150
- expect(config.config_hash).to include(:my_option => "my_value")
151
- end
152
-
153
- it "does not set any nil values" do
154
- expect(config.config_hash).to_not have_key(:nil_option)
155
- end
156
-
157
- it "overwrites the env" do
158
- expect(config.env).to eq("new_env")
159
- end
160
-
161
- it "overwrites the path" do
162
- expect(config.root_path).to eq("/some/path")
163
- end
164
-
165
- context "with multiple loaders" do
166
- before do
167
- class SecondLoader < Appsignal::Loaders::Loader
168
- register :second
169
- def on_load
170
- register_config_defaults(
171
- :env => "second_env",
172
- :root_path => "/second/path",
173
- :my_option => "second_value",
174
- :second_option => "second_value"
175
- )
176
- end
177
- end
178
- load_loader(:second)
179
- end
180
- after do
181
- Object.send(:remove_const, :SecondLoader)
182
- unregister_loader(:second)
183
- end
184
-
185
- it "makes the first loader's config leading" do
186
- expect(config.config_hash).to include(
187
- :my_option => "my_value",
188
- :second_option => "second_value"
189
- )
190
- expect(config.env).to eq("new_env")
191
- expect(config.root_path).to eq("/some/path")
192
- end
193
- end
194
- end
195
-
196
221
  describe "initial config" do
197
222
  let(:initial_config) do
198
223
  {
@@ -209,6 +209,52 @@ describe Appsignal do
209
209
  expect(Appsignal.config.env).to eq("env_env")
210
210
  end
211
211
 
212
+ it "reads the environment from a loader default" do
213
+ clear_integration_env_vars!
214
+ define_loader(:loader_env) do
215
+ def on_load
216
+ register_config_defaults(
217
+ :env => "loader_env"
218
+ )
219
+ end
220
+ end
221
+ load_loader(:loader_env)
222
+
223
+ Appsignal.configure do |config|
224
+ expect(config.env).to eq("loader_env")
225
+ end
226
+
227
+ expect(Appsignal.config.env).to eq("loader_env")
228
+ end
229
+
230
+ it "reads the root_path from a loader default" do
231
+ clear_integration_env_vars!
232
+ define_loader(:loader_path) do
233
+ def on_load
234
+ register_config_defaults(
235
+ :root_path => "/loader_path"
236
+ )
237
+ end
238
+ end
239
+ load_loader(:loader_path)
240
+
241
+ Appsignal.configure do |config|
242
+ expect(config.app_path).to eq("/loader_path")
243
+ end
244
+
245
+ expect(Appsignal.config.root_path).to eq("/loader_path")
246
+ end
247
+
248
+ it "considers the given env leading above APPSIGNAL_APP_ENV" do
249
+ ENV["APPSIGNAL_APP_ENV"] = "env_env"
250
+
251
+ Appsignal.configure(:dsl_env) do |config|
252
+ expect(config.env).to eq("dsl_env")
253
+ end
254
+
255
+ expect(Appsignal.config.env).to eq("dsl_env")
256
+ end
257
+
212
258
  it "allows modification of previously unset config options" do
213
259
  expect do
214
260
  Appsignal.configure do |config|
@@ -251,6 +297,48 @@ describe Appsignal do
251
297
  expect(stderr).to_not include("[ERROR]")
252
298
  expect(stdout).to_not include("[ERROR]")
253
299
  end
300
+
301
+ it "reads the environment from the loader defaults" do
302
+ clear_integration_env_vars!
303
+ define_loader(:loader_env) do
304
+ def on_load
305
+ register_config_defaults(:env => "loader_env")
306
+ end
307
+ end
308
+ load_loader(:loader_env)
309
+
310
+ Appsignal.start
311
+
312
+ expect(Appsignal.config.env).to eq("loader_env")
313
+ end
314
+
315
+ it "reads the root_path from the loader defaults" do
316
+ define_loader(:loader_path) do
317
+ def on_load
318
+ register_config_defaults(:root_path => "/loader_path")
319
+ end
320
+ end
321
+ load_loader(:loader_path)
322
+
323
+ Appsignal.start
324
+
325
+ expect(Appsignal.config.root_path).to eq("/loader_path")
326
+ end
327
+
328
+ it "chooses APPSIGNAL_APP_ENV over the loader defaults as the default env" do
329
+ clear_integration_env_vars!
330
+ ENV["APPSIGNAL_APP_ENV"] = "env_env"
331
+ define_loader(:loader_env) do
332
+ def on_load
333
+ register_config_defaults(:env => "loader_env")
334
+ end
335
+ end
336
+ load_loader(:loader_env)
337
+
338
+ Appsignal.start
339
+
340
+ expect(Appsignal.config.env).to eq("env_env")
341
+ end
254
342
  end
255
343
 
256
344
  context "when config is loaded" do
@@ -26,4 +26,10 @@ module ConfigHelpers
26
26
  Appsignal._config = project_fixture_config(env)
27
27
  Appsignal.start
28
28
  end
29
+
30
+ def clear_integration_env_vars!
31
+ ENV.delete("RAILS_ENV")
32
+ ENV.delete("RACK_ENV")
33
+ ENV.delete("PADRINO_ENV")
34
+ end
29
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appsignal
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.12.1
4
+ version: 3.12.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Beekman