appsignal 4.5.1 → 4.5.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: d0a3c994c51b2372d7eb37af9efd818a4b432980282716feda7bb30a62d1df68
4
- data.tar.gz: 992757e738854650edd3b7ced396d00a84fa6016a22ed0b754e9be3d3a9a3ae6
3
+ metadata.gz: ad734051c53b1a0186c335e983a7c8c5062d151a108d480759fbdb0e35be8270
4
+ data.tar.gz: cd669a754156ec1a8a2854efaa1e927397eae75d58f9df5e6c277e856711df91
5
5
  SHA512:
6
- metadata.gz: adc1a98235a0cd31c69d1b9c1a7498856bb381b4c97a6efb365204fb1a6565a21fcf55f474961028a70c9dd8e2751bdf6b3758574e0a0c823b2b555021536d3a
7
- data.tar.gz: 531c4fa256cb99ccd5fe17af6f25ee637ee0b17c8790d3cb3d45c72cdec6fcc19a98c45b7d8098e4c12216b97020ccd6b8ce4854234715145c4f23e5a72951cf
6
+ metadata.gz: 3c24a9dc9fbd1c48e235fa22205a8780a8aa91099ce63502d9b2ae11ce05cdecca8d0848e80f584da84375091cbefe87ec75b057cf58e87ee4c39390241604c1
7
+ data.tar.gz: 6edd7715a85f5ae40c7ff6679ad432c16811ad45dd3541f83392c194391178174db0987a9ffd47797e1138f4df4176b03021f20e9091d6bc84df44c36acefc78
data/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # AppSignal for Ruby gem Changelog
2
2
 
3
+ ## 4.5.2
4
+
5
+ _Published on 2025-02-24._
6
+
7
+ ### Fixed
8
+
9
+ - Validate application environment sources so nil values and empty strings are not valid app environments.
10
+ Symbols are now always cast to a String before set as the application environment.
11
+
12
+ ```ruby
13
+ # These will no longer be accepted as valid app environments
14
+ Appsignal.configure("")
15
+ Appsignal.configure(" ")
16
+ ```
17
+
18
+ (patch [bfe37be9](https://github.com/appsignal/appsignal-ruby/commit/bfe37be9ca14248f5e5a030d0cab42998d371d36))
19
+ - Fix Capistrano version 2 and 3 support when using an `appsignal.rb` config file. It will now pick up the config from `appsignal.rb` file. (patch [2a694196](https://github.com/appsignal/appsignal-ruby/commit/2a6941967435d6672c122e0aa07ec9c2de3e30bc))
20
+
3
21
  ## 4.5.1
4
22
 
5
23
  _Published on 2025-02-24._
@@ -39,8 +39,10 @@ module Appsignal
39
39
  ENV.fetch("APPSIGNAL_APP_ENV", nil),
40
40
  ENV.fetch("RAILS_ENV", nil),
41
41
  ENV.fetch("RACK_ENV", nil)
42
- ].compact.each do |env|
43
- return env if env
42
+ ].compact.each do |env_value|
43
+ value = env_value.to_s.strip
44
+ next if value.empty?
45
+ return value if value
44
46
  end
45
47
 
46
48
  loader_defaults.reverse.each do |loader_defaults|
@@ -246,8 +248,8 @@ module Appsignal
246
248
  )
247
249
  @load_yaml_file = load_yaml_file
248
250
  @root_path = root_path.to_s
249
- @config_file_error = false
250
- @config_file = config_file
251
+ @yml_config_file_error = false
252
+ @yml_config_file = yml_config_file
251
253
  @valid = false
252
254
 
253
255
  @env = env.to_s
@@ -479,9 +481,9 @@ module Appsignal
479
481
 
480
482
  # @api private
481
483
  def yml_config_file?
482
- return false unless config_file
484
+ return false unless yml_config_file
483
485
 
484
- File.exist?(config_file)
486
+ File.exist?(yml_config_file)
485
487
  end
486
488
 
487
489
  private
@@ -490,8 +492,8 @@ module Appsignal
490
492
  Appsignal.internal_logger
491
493
  end
492
494
 
493
- def config_file
494
- @config_file ||=
495
+ def yml_config_file
496
+ @yml_config_file ||=
495
497
  root_path.nil? ? nil : File.join(root_path, "config", "appsignal.yml")
496
498
  end
497
499
 
@@ -510,7 +512,7 @@ module Appsignal
510
512
  return unless yml_config_file?
511
513
 
512
514
  read_options = YAML::VERSION >= "4.0.0" ? { :aliases => true } : {}
513
- configurations = YAML.load(ERB.new(File.read(config_file)).result, **read_options)
515
+ configurations = YAML.load(ERB.new(File.read(yml_config_file)).result, **read_options)
514
516
  config_for_this_env = configurations[env]
515
517
  if config_for_this_env
516
518
  config_for_this_env.transform_keys(&:to_sym)
@@ -519,10 +521,10 @@ module Appsignal
519
521
  nil
520
522
  end
521
523
  rescue => e
522
- @config_file_error = true
524
+ @yml_config_file_error = true
523
525
  message = "An error occurred while loading the AppSignal config file. " \
524
526
  "Not starting AppSignal.\n" \
525
- "File: #{config_file.inspect}\n" \
527
+ "File: #{yml_config_file.inspect}\n" \
526
528
  "#{e.class.name}: #{e}"
527
529
  Kernel.warn "appsignal: #{message}"
528
530
  logger.error "#{message}\n#{e.backtrace.join("\n")}"
@@ -574,7 +576,7 @@ module Appsignal
574
576
  # If an error was detected during config file reading/parsing and the new
575
577
  # behavior is enabled to not start AppSignal on incomplete config, do not
576
578
  # start AppSignal.
577
- config[:active] = false if @config_file_error
579
+ config[:active] = false if @yml_config_file_error
578
580
 
579
581
  if config_hash[:activejob_report_errors] == "discard" &&
580
582
  !Appsignal::Hooks::ActiveJobHook.version_7_1_or_higher?
@@ -8,22 +8,18 @@ namespace :appsignal do
8
8
  user = fetch(:appsignal_user, ENV["USER"] || ENV.fetch("USERNAME", nil))
9
9
  revision = fetch(:appsignal_revision, fetch(:current_revision))
10
10
 
11
- appsignal_config = Appsignal::Config.new(
12
- Dir.pwd,
13
- appsignal_env
14
- ).tap do |c|
15
- c.merge_dsl_options(fetch(:appsignal_config, {}))
16
- c.validate
11
+ Appsignal._load_config!(appsignal_env) do |config|
12
+ config&.merge_dsl_options(fetch(:appsignal_config, {}))
17
13
  end
18
14
  Appsignal._start_logger
19
15
 
20
- if appsignal_config&.active?
16
+ if Appsignal.config&.active?
21
17
  marker_data = {
22
18
  :revision => revision,
23
19
  :user => user
24
20
  }
25
21
 
26
- marker = Appsignal::Marker.new(marker_data, appsignal_config)
22
+ marker = Appsignal::Marker.new(marker_data, Appsignal.config)
27
23
  # {#dry_run?} helper was added in Capistrano 3.5.0
28
24
  # https://github.com/capistrano/capistrano/commit/38d8d6d2c8485f1b5643857465b16ff01da57aff
29
25
  if respond_to?(:dry_run?) && dry_run?
@@ -5,40 +5,37 @@ module Appsignal
5
5
  # @api private
6
6
  class Capistrano
7
7
  def self.tasks(config)
8
- config.load do # rubocop:disable Metrics/BlockLength
8
+ config.load do
9
9
  after "deploy", "appsignal:deploy"
10
10
  after "deploy:migrations", "appsignal:deploy"
11
11
 
12
12
  namespace :appsignal do
13
13
  task :deploy do
14
- env = fetch(:appsignal_env,
14
+ appsignal_env = fetch(:appsignal_env,
15
15
  fetch(:stage, fetch(:rails_env, fetch(:rack_env, "production"))))
16
16
  user = fetch(:appsignal_user, ENV["USER"] || ENV.fetch("USERNAME", nil))
17
17
  revision = fetch(:appsignal_revision, fetch(:current_revision))
18
18
 
19
- appsignal_config = Appsignal::Config.new(
20
- ENV.fetch("PWD", nil),
21
- env
22
- ).tap do |c|
23
- c.merge_dsl_options(fetch(:appsignal_config, {}))
24
- c.validate
19
+ Appsignal._load_config!(appsignal_env) do |conf|
20
+ conf&.merge_dsl_options(fetch(:appsignal_config, {}))
25
21
  end
26
22
  Appsignal._start_logger
27
23
 
28
- if appsignal_config&.active?
24
+ if Appsignal.config&.active?
29
25
  marker_data = {
30
26
  :revision => revision,
31
27
  :user => user
32
28
  }
33
29
 
34
- marker = Marker.new(marker_data, appsignal_config)
30
+ marker = Marker.new(marker_data, Appsignal.config)
35
31
  if config.dry_run
36
32
  puts "Dry run: AppSignal deploy marker not actually sent."
37
33
  else
38
34
  marker.transmit
39
35
  end
40
36
  else
41
- puts "Not notifying of deploy, config is not active for environment: #{env}"
37
+ puts "Not notifying of deploy, config is not active for " \
38
+ "environment: #{appsignal_env}"
42
39
  end
43
40
  end
44
41
  end
@@ -49,7 +49,7 @@ module Appsignal
49
49
  # @return [void]
50
50
  def transmit
51
51
  transmitter = Transmitter.new(ACTION, config)
52
- puts "Notifying AppSignal of deploy with: " \
52
+ puts "Notifying AppSignal of '#{config.env}' deploy with " \
53
53
  "revision: #{marker_data[:revision]}, user: #{marker_data[:user]}"
54
54
 
55
55
  response = transmitter.transmit(marker_data)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Appsignal
4
- VERSION = "4.5.1"
4
+ VERSION = "4.5.2"
5
5
  end
data/lib/appsignal.rb CHANGED
@@ -152,7 +152,12 @@ module Appsignal
152
152
  # @param env_var [String, NilClass] Used by diagnose CLI to pass through
153
153
  # the environment CLI option value.
154
154
  # @api private
155
- def _load_config!(env_param = nil)
155
+ def _load_config!(env_param = nil, &block)
156
+ # Ensure it's not an empty string if it's a value
157
+ proper_env_param = env_param&.to_s&.strip
158
+ # Unset it if it's an empty string
159
+ proper_env_param = nil if proper_env_param&.empty?
160
+
156
161
  context = Appsignal::Config::Context.new(
157
162
  :env => Config.determine_env(env_param),
158
163
  :root_path => Config.determine_root_path
@@ -171,13 +176,25 @@ module Appsignal
171
176
  Appsignal::Utils::StdoutAndLoggerMessage.warning(message)
172
177
  else
173
178
  # Load it when no config is present
174
- load_dsl_config_file(context.dsl_config_file, env_param)
179
+ #
180
+ # We don't pass the `env_var` or `context.env` here so that the
181
+ # `Appsignal.configure` or `Appsignal.start` can figure out the
182
+ # environment themselves if it was not explicitly set.
183
+ # This way we prevent forcing an environment that's auto loaded on
184
+ # the to-be-loaded config file.
185
+ #
186
+ # The `(proper)_env_param` is only set when it's explicitly set,
187
+ # which means it needs to override any auto detected environment.
188
+ load_dsl_config_file(context.dsl_config_file, proper_env_param)
175
189
  end
176
190
  else
177
191
  # Load config if no config file was found and no config is present yet
178
192
  # This will load the config/appsignal.yml file automatically
179
193
  @config ||= Config.new(context.root_path, context.env)
180
194
  end
195
+ # Allow a block to be given to customize the config and override any
196
+ # loaded config before it's validated.
197
+ block.call(config) if block_given?
181
198
  # Validate the config, if present
182
199
  config&.validate
183
200
  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: 4.5.1
4
+ version: 4.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Beekman
@@ -316,7 +316,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
316
316
  - !ruby/object:Gem::Version
317
317
  version: '0'
318
318
  requirements: []
319
- rubygems_version: 3.4.10
319
+ rubygems_version: 3.5.23
320
320
  signing_key:
321
321
  specification_version: 4
322
322
  summary: Logs performance and exception data from your app to appsignal.com