appsignal 3.12.1-java → 3.12.3-java

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: 444ef21c052b54cf0691be97d913fd6c3faa7e54219a570a6aae4117b7c83dea
4
- data.tar.gz: '095b571b4b2bb8d2e8f413d10f75ec07be08306472b2182cba69d2e628305b72'
3
+ metadata.gz: 751ad4a4320323d8c24373ac2c5900f1c901145416e2445b8b6c445c9f9525c9
4
+ data.tar.gz: 71e823be2cdc7aa5cd3f92eb07819134d74d7d214d85bc18af76ba10526f9eb6
5
5
  SHA512:
6
- metadata.gz: 28d506f968e386e6a195b9f30f9c0a10f7860105d88e120a021917fc6c8e57595eb4199778a6a57b5f2d058770f79125b36e8c0b6b9abd757027a397ec35791d
7
- data.tar.gz: b60993c16502163d34dd7352a7636cea2fd4f7b572b241282d819be0e4a4d21dc739f52a615f2e4dd5ed28197b8873631b3288abfb29671fcd52b1f7cc2a6b3e
6
+ metadata.gz: 3fd78385cd1e814ed7f13f38d62ba25453d43fcea1cdd8778d94938dc056d0c7ffa8c8408ebc4abcc45271b47c306d25e81997a27c84b48a70d6b36827bb502d
7
+ data.tar.gz: f73268ac9b4101426569e81593cf25913cafeaac362493f52c4fe8325af8f1adfba4a4c7bfd6b3a5ca5e3c5c3f21f68cf15e7b3529eacdb7284ef895d18b1539
data/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # AppSignal for Ruby gem Changelog
2
2
 
3
+ ## 3.12.3
4
+
5
+ _Published on 2024-07-30._
6
+
7
+ ### Fixed
8
+
9
+ - Fix the application environment being reported as "[]" when no valid environment could be found. (patch [cf081253](https://github.com/appsignal/appsignal-ruby/commit/cf0812536e0651ee5b62427847a4244d4640e22b))
10
+ - Fix `Appsignal.configure` call without `env` argument not reusing the previously configured configuration. (patch [65d5428c](https://github.com/appsignal/appsignal-ruby/commit/65d5428c4d41f683a796b67b0ae339a0d213c802))
11
+
12
+ ## 3.12.2
13
+
14
+ _Published on 2024-07-25._
15
+
16
+ ### Fixed
17
+
18
+ - 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))
19
+
3
20
  ## 3.12.1
4
21
 
5
22
  _Published on 2024-07-25._
@@ -20,6 +20,37 @@ 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
+
40
+ nil
41
+ end
42
+
43
+ # Determine which root path AppSignal should initialize with.
44
+ # @api private
45
+ def self.determine_root_path
46
+ loader_defaults.reverse.each do |(_loader_name, loader_defaults)|
47
+ root_path = loader_defaults[:root_path]
48
+ return root_path if root_path
49
+ end
50
+
51
+ Dir.pwd
52
+ end
53
+
23
54
  # @api private
24
55
  DEFAULT_CONFIG = {
25
56
  :activejob_report_errors => "all",
@@ -226,7 +257,9 @@ module Appsignal
226
257
 
227
258
  return unless load_on_new
228
259
 
229
- # Determine starting environment
260
+ # Always override environment if set via this env var.
261
+ # TODO: This is legacy behavior. In the `Appsignal.configure` method the
262
+ # env argument is leading.
230
263
  @env = ENV["APPSIGNAL_APP_ENV"] if ENV.key?("APPSIGNAL_APP_ENV")
231
264
  load_config
232
265
  validate
@@ -242,20 +275,7 @@ module Appsignal
242
275
  @system_config = detect_from_system
243
276
  merge(system_config)
244
277
 
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
-
278
+ # Merge initial config
259
279
  merge(initial_config)
260
280
  # Track origin of env
261
281
  @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.3"
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
 
@@ -244,12 +241,12 @@ module Appsignal
244
241
  return
245
242
  end
246
243
 
247
- if config && config.env == env.to_s
244
+ if config && (env.nil? || 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,103 @@
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
+
71
+ it "returns nil if no env was found" do
72
+ expect(described_class.determine_env).to be_nil
73
+ end
74
+ end
75
+ end
76
+
77
+ describe ".determine_root_path" do
78
+ it "reads the root path from the first loader if any" do
79
+ define_loader(:path_loader1) do
80
+ def on_load
81
+ register_config_defaults(:root_path => "/loader_path1")
82
+ end
83
+ end
84
+ load_loader(:path_loader1)
85
+
86
+ define_loader(:path_loader2) do
87
+ def on_load
88
+ register_config_defaults(:root_path => "/loader_path2")
89
+ end
90
+ end
91
+ load_loader(:path_loader2)
92
+
93
+ expect(described_class.determine_root_path).to eq("/loader_path2")
94
+ end
95
+
96
+ it "falls back on the current working directory" do
97
+ expect(described_class.determine_root_path).to eq(Dir.pwd)
98
+ end
99
+ end
100
+
2
101
  describe "#initialize" do
3
102
  describe "environment" do
4
103
  context "when environment is nil" do
@@ -123,76 +222,6 @@ describe Appsignal::Config do
123
222
  end
124
223
  end
125
224
 
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
225
  describe "initial config" do
197
226
  let(:initial_config) do
198
227
  {
@@ -61,6 +61,28 @@ describe Appsignal do
61
61
  end
62
62
 
63
63
  context "with config but not started" do
64
+ it "reuses the already loaded config if no env arg is given" do
65
+ Appsignal._config = Appsignal::Config.new(
66
+ project_fixture_path,
67
+ :my_env,
68
+ :ignore_actions => ["My action"]
69
+ )
70
+
71
+ Appsignal.configure do |config|
72
+ expect(config.env).to eq("my_env")
73
+ expect(config.ignore_actions).to eq(["My action"])
74
+
75
+ config.active = true
76
+ config.name = "My app"
77
+ config.push_api_key = "key"
78
+ end
79
+ expect(Appsignal.config.valid?).to be(true)
80
+ expect(Appsignal.config.env).to eq("my_env")
81
+ expect(Appsignal.config[:name]).to eq("My app")
82
+ expect(Appsignal.config[:push_api_key]).to eq("key")
83
+ expect(Appsignal.config[:ignore_actions]).to eq(["My action"])
84
+ end
85
+
64
86
  it "reuses the already loaded config if the env is the same" do
65
87
  Appsignal._config = Appsignal::Config.new(
66
88
  project_fixture_path,
@@ -209,6 +231,52 @@ describe Appsignal do
209
231
  expect(Appsignal.config.env).to eq("env_env")
210
232
  end
211
233
 
234
+ it "reads the environment from a loader default" do
235
+ clear_integration_env_vars!
236
+ define_loader(:loader_env) do
237
+ def on_load
238
+ register_config_defaults(
239
+ :env => "loader_env"
240
+ )
241
+ end
242
+ end
243
+ load_loader(:loader_env)
244
+
245
+ Appsignal.configure do |config|
246
+ expect(config.env).to eq("loader_env")
247
+ end
248
+
249
+ expect(Appsignal.config.env).to eq("loader_env")
250
+ end
251
+
252
+ it "reads the root_path from a loader default" do
253
+ clear_integration_env_vars!
254
+ define_loader(:loader_path) do
255
+ def on_load
256
+ register_config_defaults(
257
+ :root_path => "/loader_path"
258
+ )
259
+ end
260
+ end
261
+ load_loader(:loader_path)
262
+
263
+ Appsignal.configure do |config|
264
+ expect(config.app_path).to eq("/loader_path")
265
+ end
266
+
267
+ expect(Appsignal.config.root_path).to eq("/loader_path")
268
+ end
269
+
270
+ it "considers the given env leading above APPSIGNAL_APP_ENV" do
271
+ ENV["APPSIGNAL_APP_ENV"] = "env_env"
272
+
273
+ Appsignal.configure(:dsl_env) do |config|
274
+ expect(config.env).to eq("dsl_env")
275
+ end
276
+
277
+ expect(Appsignal.config.env).to eq("dsl_env")
278
+ end
279
+
212
280
  it "allows modification of previously unset config options" do
213
281
  expect do
214
282
  Appsignal.configure do |config|
@@ -251,6 +319,48 @@ describe Appsignal do
251
319
  expect(stderr).to_not include("[ERROR]")
252
320
  expect(stdout).to_not include("[ERROR]")
253
321
  end
322
+
323
+ it "reads the environment from the loader defaults" do
324
+ clear_integration_env_vars!
325
+ define_loader(:loader_env) do
326
+ def on_load
327
+ register_config_defaults(:env => "loader_env")
328
+ end
329
+ end
330
+ load_loader(:loader_env)
331
+
332
+ Appsignal.start
333
+
334
+ expect(Appsignal.config.env).to eq("loader_env")
335
+ end
336
+
337
+ it "reads the root_path from the loader defaults" do
338
+ define_loader(:loader_path) do
339
+ def on_load
340
+ register_config_defaults(:root_path => "/loader_path")
341
+ end
342
+ end
343
+ load_loader(:loader_path)
344
+
345
+ Appsignal.start
346
+
347
+ expect(Appsignal.config.root_path).to eq("/loader_path")
348
+ end
349
+
350
+ it "chooses APPSIGNAL_APP_ENV over the loader defaults as the default env" do
351
+ clear_integration_env_vars!
352
+ ENV["APPSIGNAL_APP_ENV"] = "env_env"
353
+ define_loader(:loader_env) do
354
+ def on_load
355
+ register_config_defaults(:env => "loader_env")
356
+ end
357
+ end
358
+ load_loader(:loader_env)
359
+
360
+ Appsignal.start
361
+
362
+ expect(Appsignal.config.env).to eq("env_env")
363
+ end
254
364
  end
255
365
 
256
366
  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.3
5
5
  platform: java
6
6
  authors:
7
7
  - Robert Beekman
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2024-07-25 00:00:00.000000000 Z
13
+ date: 2024-07-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rack