appsignal 4.5.6 → 4.5.8

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: 9c26526a57b19a4680e8d3b7293eb1f46c9e32b8bf4fc47e9ea9aa74c96a3b64
4
- data.tar.gz: 91ef88fce1c7fdf231ce23bbe6047338b34100f4610bbadea6f8b6fcbb79cacf
3
+ metadata.gz: f023b8343540c92b7c106f7c9853d7ec08c64f0138fa1904be7b606aadf6691b
4
+ data.tar.gz: eb18c6e7c352ab0e5e44f739190df8a2c671212b97133311070633944597b63f
5
5
  SHA512:
6
- metadata.gz: 18fbaec4092861cebc794fbeabdcb4ea189a5c38faabf99fe25cdd1b07d1d0d778de73c5d7f55977b8abfa69d2d77b924dcb4a6ec4a0c97beeab88770ea06115
7
- data.tar.gz: 43d538d0d1cd4571704abed7116f40819569d78cfe54b00bf0b888f3e5ca6b4f46d40e4100c1a7953cb63e66c904fa6ab2f3f3297eeef4ee1b34face4af63c39
6
+ metadata.gz: 678d39b904447512f7222a7c3f82bd251d507e745d9b1402f7c3a3784fabd691f1a1538421ff4dd7fb158cdc74d02e925cbea10eff59581c2d661d3d1ad9c03a
7
+ data.tar.gz: 18efa45cf4d42fd8faacaf5cec5ec93e76d41773d83e9e077a6d4528aeb5019a05ce41b35b1e88e3449ccd8635ce27045c8cca49d46077327d6490e3e6dc31d4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,50 @@
1
1
  # AppSignal for Ruby gem Changelog
2
2
 
3
+ ## 4.5.8
4
+
5
+ _Published on 2025-04-04._
6
+
7
+ ### Added
8
+
9
+ - Add the `enable_at_exit_hook` option to configure if `Appsignal.stop` is called when the Ruby application exits. Calling `Appsignal.stop` will stop the application for a moment to flush all the data to our agent before shutting down.
10
+
11
+ This option has three possible values:
12
+
13
+ - `always`: Always call `Appsignal.stop` when the program exits. On (Docker) containers it's automatically set to this value.
14
+ - `never`: Never call `Appsignal.stop` when the program exits. The default value when the program doesn't run on a (Docker) container.
15
+ - `on_error`: Call `Appsignal.stop` when the program exits with an error.
16
+
17
+ (patch [d0a5875c](https://github.com/appsignal/appsignal-ruby/commit/d0a5875cef5101680f1cab4649d71440212f9ea8), [043a6c74](https://github.com/appsignal/appsignal-ruby/commit/043a6c740b708e1182ed7161e3c9ad38bd3314de), [b680fe6f](https://github.com/appsignal/appsignal-ruby/commit/b680fe6f6b283205a13ca61bd4a26167f541dbca))
18
+
19
+ ### Deprecated
20
+
21
+ - Deprecate the `Appsignal.monitor_and_stop` helper.
22
+
23
+ We instead recommend using the `Appsignal.monitor` helper and configuring the `enable_at_exit_hook` config option to `always`.
24
+
25
+ (patch [84969aea](https://github.com/appsignal/appsignal-ruby/commit/84969aeaca8f3737921e9adf1efdad55b52e1206))
26
+
27
+ ## 4.5.7
28
+
29
+ _Published on 2025-03-20._
30
+
31
+ ### Added
32
+
33
+ - Add the `Appsignal.config_error` and `Appsignal.config_error?` methods. This method contains any error that may have occurred while loading the `config/appsignal.rb` file. If it is `nil` no error occurred or `Appsignal.start` hasn't been called yet. The `Appsignal.config_error?` method is an alias for syntax sugar. (patch [0f3a7372](https://github.com/appsignal/appsignal-ruby/commit/0f3a73729306d96b630339ccf6e218318d1e2870))
34
+ - Add the `check_if_started!` method. This method will raise an error if the AppSignal Ruby gem failed to start.
35
+
36
+ Call this method in your CI or on app boot if you wish to verify that AppSignal has started when your application does, and want the application to fail to start if AppSignal hasn't started.
37
+
38
+ For example, in this Rails initializer:
39
+
40
+ ```
41
+ # config/initializers/appsignal.rb
42
+
43
+ Appsignal.check_if_started!
44
+ ```
45
+
46
+ (patch [b41c9c99](https://github.com/appsignal/appsignal-ruby/commit/b41c9c991bdbcd64b7a04e9832b15ddacda7ae20))
47
+
3
48
  ## 4.5.6
4
49
 
5
50
  _Published on 2025-03-20._
@@ -93,6 +93,7 @@ module Appsignal
93
93
  :ca_file_path => File.expand_path(File.join("../../../resources/cacert.pem"), __FILE__),
94
94
  :dns_servers => [],
95
95
  :enable_allocation_tracking => true,
96
+ :enable_at_exit_hook => "on_error",
96
97
  :enable_at_exit_reporter => true,
97
98
  :enable_host_metrics => true,
98
99
  :enable_minutely_probes => true,
@@ -153,6 +154,7 @@ module Appsignal
153
154
  :name => "APPSIGNAL_APP_NAME",
154
155
  :bind_address => "APPSIGNAL_BIND_ADDRESS",
155
156
  :ca_file_path => "APPSIGNAL_CA_FILE_PATH",
157
+ :enable_at_exit_hook => "APPSIGNAL_ENABLE_AT_EXIT_HOOK",
156
158
  :hostname => "APPSIGNAL_HOSTNAME",
157
159
  :host_role => "APPSIGNAL_HOST_ROLE",
158
160
  :http_proxy => "APPSIGNAL_HTTP_PROXY",
@@ -507,6 +509,8 @@ module Appsignal
507
509
  # environment variable is present and not empty.
508
510
  env_push_api_key = ENV["APPSIGNAL_PUSH_API_KEY"] || ""
509
511
  hash[:active] = true unless env_push_api_key.strip.empty?
512
+
513
+ hash[:enable_at_exit_hook] = "always" if Appsignal::Extension.running_in_container?
510
514
  end
511
515
  end
512
516
 
@@ -154,6 +154,11 @@ module Appsignal
154
154
  #
155
155
  # @see monitor
156
156
  def monitor_and_stop(action:, namespace: nil, &block)
157
+ Appsignal::Utils::StdoutAndLoggerMessage.warning \
158
+ "The `Appsignal.monitor_and_stop` helper is deprecated. " \
159
+ "Use the `Appsignal.monitor` along with our `enable_at_exit_hook` " \
160
+ "option instead."
161
+
157
162
  monitor(:namespace => namespace, :action => action, &block)
158
163
  ensure
159
164
  Appsignal.stop("monitor_and_stop")
@@ -11,27 +11,41 @@ module Appsignal
11
11
  end
12
12
 
13
13
  def install
14
- return unless Appsignal.config[:enable_at_exit_reporter]
15
-
16
14
  Kernel.at_exit(&AtExitCallback.method(:call))
17
15
  end
18
16
 
19
- # Report any unhandled errors and will crash the Ruby process.
17
+ # Stop AppSignal before the app exists.
18
+ #
19
+ # This is the default behavior and can be customized with the
20
+ # `enable_at_exit_hook` option.
21
+ #
22
+ # When the `enable_at_exit_reporter` option is set to `true` (the
23
+ # default), it will report any unhandled errors that will crash the Ruby
24
+ # process.
20
25
  #
21
26
  # If this error was previously reported by any of our instrumentation,
22
27
  # the error will not also be reported here. This way we don't report an
23
28
  # error from a Rake task or instrumented script twice.
24
29
  class AtExitCallback
25
30
  def self.call
31
+ report_error = false
32
+ return unless Appsignal.config&.[](:enable_at_exit_reporter)
33
+
26
34
  error = $! # rubocop:disable Style/SpecialGlobalVars
27
35
  return unless error
28
36
  return if ignored_error?(error)
29
37
  return if Appsignal::Transaction.last_errors.include?(error)
30
38
 
39
+ report_error = true
40
+
31
41
  Appsignal.report_error(error) do |transaction|
32
42
  transaction.set_namespace("unhandled")
33
43
  end
34
- Appsignal.stop("at_exit")
44
+ ensure
45
+ at_exit_hook = Appsignal.config&.[](:enable_at_exit_hook)
46
+ if at_exit_hook == "always" || (at_exit_hook == "on_error" && report_error)
47
+ Appsignal.stop("at_exit")
48
+ end
35
49
  end
36
50
 
37
51
  IGNORED_ERRORS = [
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Appsignal
4
+ # @api private
5
+ class InternalError < StandardError; end
6
+
7
+ # @api private
8
+ class NotStartedError < InternalError
9
+ MESSAGE = <<~MESSAGE
10
+ The AppSignal Ruby gem was not started!
11
+
12
+ This error was raised by calling `Appsignal.check_if_started!`
13
+ MESSAGE
14
+
15
+ def message
16
+ MESSAGE
17
+ end
18
+ end
19
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Appsignal
4
- VERSION = "4.5.6"
4
+ VERSION = "4.5.8"
5
5
  end
data/lib/appsignal.rb CHANGED
@@ -62,6 +62,19 @@ module Appsignal
62
62
  # @see start
63
63
  attr_writer :internal_logger
64
64
 
65
+ # Returns the error that was encountered while loading the `appsignal.rb`
66
+ # config file.
67
+ #
68
+ # It does not include any error that occurred while loading the
69
+ # `appsignal.yml` file.
70
+ #
71
+ # If the value is `nil`, no error was encountered or AppSignal wasn't
72
+ # started yet.
73
+ #
74
+ # @return [NilClass/Exception]
75
+ attr_reader :config_error
76
+ alias config_error? config_error
77
+
65
78
  # @api private
66
79
  def testing?
67
80
  false
@@ -483,6 +496,31 @@ module Appsignal
483
496
  defined?(@dsl_config_file_loaded) ? true : false
484
497
  end
485
498
 
499
+ # Check if the AppSignal Ruby gem has started successfully.
500
+ #
501
+ # If it has not (yet) started or encountered an error in the
502
+ # `config/appsignal.rb` config file during start up that prevented it from
503
+ # starting, it will raise a {Appsignal::NotStartedError}.
504
+ #
505
+ # If there an error raised from the config file, it will include it as the
506
+ # error cause of the raised error.
507
+ #
508
+ # @raise [Appsignal::NotStartedError]
509
+ # @return [void]
510
+ def check_if_started!
511
+ return if started?
512
+
513
+ begin
514
+ raise config_error if config_error?
515
+ rescue
516
+ # Raise the NotStartedError and make the config error the error cause
517
+ raise NotStartedError, config_error
518
+ end
519
+
520
+ # Raise the NotStartedError as normal
521
+ raise NotStartedError
522
+ end
523
+
486
524
  private
487
525
 
488
526
  def params_match_loaded_config?(env_param, root_path_param)
@@ -508,7 +546,7 @@ module Appsignal
508
546
  @dsl_config_file_loaded = true
509
547
  require path
510
548
  rescue => error
511
- @config_file_error = error
549
+ @config_error = error
512
550
  message = "Not starting AppSignal because an error occurred while " \
513
551
  "loading the AppSignal config file.\n" \
514
552
  "File: #{path.inspect}\n" \
@@ -527,7 +565,7 @@ module Appsignal
527
565
  end
528
566
 
529
567
  # Disable on config file error
530
- config[:active] = false if defined?(@config_file_error)
568
+ config[:active] = false if defined?(@config_error)
531
569
 
532
570
  ENV.delete("_APPSIGNAL_CONFIG_FILE_CONTEXT")
533
571
  ENV.delete("_APPSIGNAL_CONFIG_FILE_ENV")
@@ -569,6 +607,7 @@ module Appsignal
569
607
  end
570
608
  end
571
609
 
610
+ require "appsignal/internal_errors"
572
611
  require "appsignal/loaders"
573
612
  require "appsignal/sample_data"
574
613
  require "appsignal/environment"
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.6
4
+ version: 4.5.8
5
5
  platform: ruby
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: 2025-03-20 00:00:00.000000000 Z
13
+ date: 2025-04-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: logger
@@ -248,6 +248,7 @@ files:
248
248
  - lib/appsignal/integrations/sidekiq.rb
249
249
  - lib/appsignal/integrations/unicorn.rb
250
250
  - lib/appsignal/integrations/webmachine.rb
251
+ - lib/appsignal/internal_errors.rb
251
252
  - lib/appsignal/loaders.rb
252
253
  - lib/appsignal/loaders/grape.rb
253
254
  - lib/appsignal/loaders/hanami.rb