appsignal 4.0.0.beta.2-java → 4.0.0-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13fbf7d3d59f4a0cfd1b455bdccac4dbed20a7217769784d23ddf82d21e54e29
4
- data.tar.gz: e9b763431f5c412a6aa3354f9b9e9c4ebd3ee6a1e36f7f9addd9b4c796811af1
3
+ metadata.gz: 8b24fff89ddabacc2b97eedd0f2350e332084c31c4e879dab2b9f13e02f631e2
4
+ data.tar.gz: ec09dc858c399b9004cebb9afcdb1e041ba4f0efd068f173c6177e2bb5d10b1c
5
5
  SHA512:
6
- metadata.gz: d55472d738317c2c2977a6ae3a9b5321ddb1d1164960e2c0f33052c8312af95bea21744c51c698455c94d8a6d937625bc8bc118448a5173550101153e3cda8c7
7
- data.tar.gz: d6b4d552c1eb6016e8a58ed06fee58719f49a0b775c588b6052da9ac6c97b2a3c1a71f80a1c2e9e0d0e7aa3734f0b3d27ddb9b2352ae9f81f3c2efbb6c9047df
6
+ metadata.gz: 0ff5785db46ea54a79b993742b1f2730cae2bb236069c331414782732ed47de3a0c28a95e3bb8c9db45adcf2a402083af88f909d5065d839551d9f52bc560e64
7
+ data.tar.gz: 6da6a43068a8edf31158269f956be507f2125ec61dd8374192f228582c730862a5a659d5b2f530e7c995264e571d2e27daf049367089608dcdbbb63b5db16ef9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # AppSignal for Ruby gem Changelog
2
2
 
3
+ ## 4.0.0
4
+
5
+ _Published on 2024-08-23._
6
+
7
+ ### Changed
8
+
9
+ - Release the final package version. See the pre-release changelog entries for the changes in this version. (major)
10
+
11
+ ### Removed
12
+
13
+ - Remove the `Transaction.new` method Transaction ID argument. The Transaction ID will always be automatically generated. (major [bb938a9f](https://github.com/appsignal/appsignal-ruby/commit/bb938a9f79b8b51e4c47d3f268326f89c137df6f))
14
+
3
15
  ## 4.0.0.beta.2
4
16
 
5
17
  _Published on 2024-08-19._
@@ -121,6 +133,22 @@ _Published on 2024-08-19._
121
133
 
122
134
  - Fix an issue where, when setting several errors for the same transaction, error causes from a different error would be shown for an error that has no causes. (patch [d54ce8b9](https://github.com/appsignal/appsignal-ruby/commit/d54ce8b947c9316756c4191155e8d255a8e25a8c))
123
135
 
136
+ ## 3.13.1
137
+
138
+ _Published on 2024-08-23._
139
+
140
+ ### Changed
141
+
142
+ - Release the final package version. See the pre-release changelog entries for the changes in this version. (patch)
143
+
144
+ ## 3.13.1.alpha.1
145
+
146
+ _Published on 2024-08-22._
147
+
148
+ ### Changed
149
+
150
+ - Ignore `Errno::EPIPE` errors when instrumenting response bodies. We've noticed this error gets reported when the connection is broken between server and client. This happens in normal scenarios so we'll ignore this error in this scenario to avoid error reports from errors that cannot be resolved. (patch [8ad8a057](https://github.com/appsignal/appsignal-ruby/commit/8ad8a05787dcb12a5c7febc64559e7f145a59096))
151
+
124
152
  ## 3.13.0
125
153
 
126
154
  _Published on 2024-08-14._
data/README.md CHANGED
@@ -42,7 +42,7 @@ request.
42
42
  begin
43
43
  config = File.read("config.yml")
44
44
  rescue => e
45
- Appsignal.set_error(e)
45
+ Appsignal.report_error(e)
46
46
  # Load alternative config
47
47
  config = { :name => ENV["NAME"] }
48
48
  end
@@ -56,9 +56,9 @@ Need more information with errors and performance issues? Add tags to your
56
56
  requests to identify common factors for problems.
57
57
 
58
58
  ```ruby
59
- Appsignal.tag_request(
60
- user: current_user.id,
61
- locale: I18n.locale
59
+ Appsignal.add_tags(
60
+ :user => current_user.id,
61
+ :locale => I18n.locale
62
62
  )
63
63
  ```
64
64
 
@@ -143,11 +143,6 @@ anything.
143
143
  For more detailed information and examples please visit our
144
144
  [integrations] page.
145
145
 
146
- ### Front-end monitoring (Beta)
147
-
148
- We have a [Front-end monitoring program][front-end-monitoring] running in Beta
149
- currently. Be sure to check it out!
150
-
151
146
  ## Supported systems
152
147
 
153
148
  Currently the AppSignal agent works on most Unix-like operating systems, such
@@ -304,11 +299,11 @@ Also see our [SUPPORT.md file](SUPPORT.md).
304
299
  [ruby-doc]: https://www.rubydoc.info/gems/appsignal
305
300
  [contributing-guide]: https://docs.appsignal.com/appsignal/contributing.html
306
301
  [supported-systems]: https://docs.appsignal.com/support/operating-systems.html
307
- [integrations]: https://docs.appsignal.com/ruby/integrations/index.html
308
- [custom-instrumentation]: https://docs.appsignal.com/ruby/instrumentation/
309
- [front-end-monitoring]: https://docs.appsignal.com/front-end/error-handling.html
302
+ [integrations]: https://docs.appsignal.com/ruby/integrations.html
303
+ [custom-instrumentation]: https://docs.appsignal.com/ruby/instrumentation.html
304
+ [front-end-monitoring]: https://docs.appsignal.com/front-end.html
310
305
  [exception-handling]: https://docs.appsignal.com/ruby/instrumentation/exception-handling.html
311
- [tagging]: https://docs.appsignal.com/ruby/instrumentation/tagging.html
306
+ [tagging]: https://docs.appsignal.com/guides/custom-data/tagging-request.html
312
307
  [host-metrics]: https://docs.appsignal.com/metrics/host.html
313
308
  [custom-metrics]: https://docs.appsignal.com/metrics/custom.html
314
309
 
data/benchmark.rake CHANGED
@@ -65,10 +65,11 @@ def start_agent
65
65
  end
66
66
 
67
67
  def monitor_transaction(transaction_id)
68
- transaction = Appsignal::Transaction.create(
69
- transaction_id,
70
- Appsignal::Transaction::HTTP_REQUEST
68
+ transaction = Appsignal::Transaction.new(
69
+ Appsignal::Transaction::HTTP_REQUEST,
70
+ :id => transaction_id
71
71
  )
72
+ Appsignal::Transaction.set_current_transaction(transaction)
72
73
  transaction.set_action("HomeController#show")
73
74
  transaction.add_params(:id => 1)
74
75
 
@@ -88,6 +88,7 @@ module Appsignal
88
88
  # end
89
89
  # end
90
90
  #
91
+ # @since 3.11.0
91
92
  # @param namespace [String/Symbol] The namespace to set on the new
92
93
  # transaction.
93
94
  # Defaults to the 'web' namespace.
@@ -105,10 +106,10 @@ module Appsignal
105
106
  # @raise [Exception] Any exception that occurs within the given block is
106
107
  # re-raised by this method.
107
108
  # @return [Object] The value of the given block is returned.
108
- # @since 3.11.0
109
- def monitor(
110
- action:, namespace: nil
111
- )
109
+ #
110
+ # @see https://docs.appsignal.com/ruby/instrumentation/background-jobs.html
111
+ # Monitor guide
112
+ def monitor(action:, namespace: nil)
112
113
  return yield unless active?
113
114
 
114
115
  has_parent_transaction = Appsignal::Transaction.current?
@@ -160,6 +161,8 @@ module Appsignal
160
161
 
161
162
  # Send an error to AppSignal regardless of the context.
162
163
  #
164
+ # **We recommend using the {#report_error} helper instead.**
165
+ #
163
166
  # Records and send the exception to AppSignal.
164
167
  #
165
168
  # This instrumentation helper does not require a transaction to be
@@ -186,6 +189,7 @@ module Appsignal
186
189
  # Appsignal.add_tags(:key => "value")
187
190
  # end
188
191
  #
192
+ # @since 0.6.0
189
193
  # @param error [Exception] The error to send to AppSignal.
190
194
  # @yield [transaction] yields block to allow modification of the
191
195
  # transaction before it's send.
@@ -193,12 +197,8 @@ module Appsignal
193
197
  # used to send the error.
194
198
  # @return [void]
195
199
  #
196
- # @see Transaction#report_error
197
200
  # @see https://docs.appsignal.com/ruby/instrumentation/exception-handling.html
198
201
  # Exception handling guide
199
- # @see https://docs.appsignal.com/ruby/instrumentation/tagging.html
200
- # Tagging guide
201
- # @since 0.6.0
202
202
  def send_error(error, &block)
203
203
  return unless active?
204
204
 
@@ -208,10 +208,8 @@ module Appsignal
208
208
  return
209
209
  end
210
210
 
211
- transaction = Appsignal::Transaction.new(
212
- SecureRandom.uuid,
213
- Appsignal::Transaction::HTTP_REQUEST
214
- )
211
+ transaction =
212
+ Appsignal::Transaction.new(Appsignal::Transaction::HTTP_REQUEST)
215
213
  transaction.set_error(error, &block)
216
214
 
217
215
  transaction.complete
@@ -220,6 +218,8 @@ module Appsignal
220
218
 
221
219
  # Set an error on the current transaction.
222
220
  #
221
+ # **We recommend using the {#report_error} helper instead.**
222
+ #
223
223
  # **Note**: Does not do anything if AppSignal is not active, no
224
224
  # transaction is currently active or when the "error" is not a class
225
225
  # extended from Ruby's Exception class.
@@ -253,6 +253,7 @@ module Appsignal
253
253
  # Appsignal.add_tags(:key => "value")
254
254
  # end
255
255
  #
256
+ # @since 0.6.6
256
257
  # @param exception [Exception] The error to add to the current
257
258
  # transaction.
258
259
  # @yield [transaction] yields block to allow modification of the
@@ -261,11 +262,8 @@ module Appsignal
261
262
  # used to store the error.
262
263
  # @return [void]
263
264
  #
264
- # @see Transaction#set_error
265
- # @see Transaction#report_error
266
265
  # @see https://docs.appsignal.com/ruby/instrumentation/exception-handling.html
267
266
  # Exception handling guide
268
- # @since 0.6.6
269
267
  def set_error(exception)
270
268
  unless exception.is_a?(Exception)
271
269
  internal_logger.error "Appsignal.set_error: Cannot set error. " \
@@ -281,12 +279,21 @@ module Appsignal
281
279
  alias :set_exception :set_error
282
280
  alias :add_exception :set_error
283
281
 
284
- # Report an error.
282
+ # Report an error to AppSignal.
285
283
  #
286
284
  # If a transaction is currently active, it will report the error on the
287
285
  # current transaction. If no transaction is active, it will report the
288
286
  # error on a new transaction.
289
287
  #
288
+ # If a transaction is active and the transaction already has an error
289
+ # reported on it, it will report multiple errors, up to a maximum of 10
290
+ # errors.
291
+ #
292
+ # If a block is given to this method, the metadata set in this block will
293
+ # only be applied to the transaction created for the given error. The
294
+ # block will be called when the transaction is completed, which can be
295
+ # much later than when {#report_error} is called.
296
+ #
290
297
  # **Note**: If AppSignal is not active, no error is reported.
291
298
  #
292
299
  # **Note**: If the given exception argument is not an Exception subclass,
@@ -309,6 +316,7 @@ module Appsignal
309
316
  # Appsignal.add_tags(:key => "value")
310
317
  # end
311
318
  #
319
+ # @since 4.0.0
312
320
  # @param exception [Exception] The error to add to the current
313
321
  # transaction.
314
322
  # @yield [transaction] yields block to allow modification of the
@@ -319,7 +327,6 @@ module Appsignal
319
327
  #
320
328
  # @see https://docs.appsignal.com/ruby/instrumentation/exception-handling.html
321
329
  # Exception handling guide
322
- # @since 3.10.0
323
330
  def report_error(exception, &block)
324
331
  unless exception.is_a?(Exception)
325
332
  internal_logger.error "Appsignal.report_error: Cannot add error. " \
@@ -333,10 +340,7 @@ module Appsignal
333
340
  if has_parent_transaction
334
341
  Appsignal::Transaction.current
335
342
  else
336
- Appsignal::Transaction.new(
337
- SecureRandom.uuid,
338
- Appsignal::Transaction::HTTP_REQUEST
339
- )
343
+ Appsignal::Transaction.new(Appsignal::Transaction::HTTP_REQUEST)
340
344
  end
341
345
 
342
346
  transaction.add_error(exception, &block)
@@ -363,10 +367,9 @@ module Appsignal
363
367
  # end
364
368
  # end
365
369
  #
370
+ # @since 2.2.0
366
371
  # @param action [String]
367
372
  # @return [void]
368
- # @see Transaction#set_action
369
- # @since 2.2.0
370
373
  def set_action(action)
371
374
  return if !active? ||
372
375
  !Appsignal::Transaction.current? ||
@@ -403,10 +406,12 @@ module Appsignal
403
406
  # end
404
407
  # end
405
408
  #
409
+ # @since 2.2.0
406
410
  # @param namespace [String]
407
411
  # @return [void]
408
- # @see Transaction#set_namespace
409
- # @since 2.2.0
412
+ #
413
+ # @see https://docs.appsignal.com/guides/namespaces.html
414
+ # Grouping with namespaces guide
410
415
  def set_namespace(namespace)
411
416
  return if !active? ||
412
417
  !Appsignal::Transaction.current? ||
@@ -452,7 +457,6 @@ module Appsignal
452
457
  # @param data [Hash/Array] Custom data to add to the transaction.
453
458
  # @return [void]
454
459
  #
455
- # @see Transaction#add_custom_data
456
460
  # @see https://docs.appsignal.com/guides/custom-data/sample-data.html
457
461
  # Sample data guide
458
462
  def add_custom_data(data)
@@ -497,7 +501,6 @@ module Appsignal
497
501
  # The name of the tag as a String.
498
502
  # @return [void]
499
503
  #
500
- # @see Transaction#add_tags
501
504
  # @see https://docs.appsignal.com/ruby/instrumentation/tagging.html
502
505
  # Tagging guide
503
506
  def add_tags(tags = {})
@@ -542,7 +545,6 @@ module Appsignal
542
545
  # Sample data guide
543
546
  # @see https://docs.appsignal.com/guides/filter-data/filter-parameters.html
544
547
  # Parameter filtering guide
545
- # @see Transaction#add_params
546
548
  def add_params(params = nil, &block)
547
549
  return unless active?
548
550
  return unless Appsignal::Transaction.current?
@@ -557,6 +559,7 @@ module Appsignal
557
559
  # @api private
558
560
  # @since 4.0.0
559
561
  # @return [void]
562
+ #
560
563
  # @see Helpers::Instrumentation#set_empty_params!
561
564
  def set_empty_params!
562
565
  return unless active?
@@ -598,7 +601,6 @@ module Appsignal
598
601
  # Sample data guide
599
602
  # @see https://docs.appsignal.com/guides/filter-data/filter-session-data.html
600
603
  # Session data filtering guide
601
- # @see Transaction#add_session_data
602
604
  def add_session_data(session_data = nil, &block)
603
605
  return unless active?
604
606
  return unless Appsignal::Transaction.current?
@@ -640,7 +642,6 @@ module Appsignal
640
642
  # Sample data guide
641
643
  # @see https://docs.appsignal.com/guides/filter-data/filter-headers.html
642
644
  # Request headers filtering guide
643
- # @see Transaction#add_headers
644
645
  def add_headers(headers = nil, &block)
645
646
  return unless active?
646
647
  return unless Appsignal::Transaction.current?
@@ -677,6 +678,7 @@ module Appsignal
677
678
  # "User closed modal without actions"
678
679
  # )
679
680
  #
681
+ # @since 2.12.0
680
682
  # @param category [String] category of breadcrumb
681
683
  # e.g. "UI", "Network", "Navigation", "Console".
682
684
  # @param action [String] name of breadcrumb
@@ -686,10 +688,8 @@ module Appsignal
686
688
  # @option time [Time] time of breadcrumb, should respond to `.to_i` defaults to `Time.now.utc`
687
689
  # @return [void]
688
690
  #
689
- # @see Transaction#add_breadcrumb
690
691
  # @see https://docs.appsignal.com/ruby/instrumentation/breadcrumbs.html
691
692
  # Breadcrumb reference
692
- # @since 2.12.0
693
693
  def add_breadcrumb(category, action, message = "", metadata = {}, time = Time.now.utc)
694
694
  return unless active?
695
695
  return unless Appsignal::Transaction.current?
@@ -717,6 +717,7 @@ module Appsignal
717
717
  # # To be instrumented code
718
718
  # end
719
719
  #
720
+ # @since 1.3.0
720
721
  # @param name [String] Name of the instrumented event. Read our event
721
722
  # naming guide listed under "See also".
722
723
  # @param title [String, nil] Human readable name of the event.
@@ -730,13 +731,11 @@ module Appsignal
730
731
  # event.
731
732
  # @return [Object] Returns the block's return value.
732
733
  #
733
- # @see Appsignal::Transaction#instrument
734
734
  # @see .instrument_sql
735
735
  # @see https://docs.appsignal.com/ruby/instrumentation/instrumentation.html
736
736
  # AppSignal custom instrumentation guide
737
737
  # @see https://docs.appsignal.com/api/event-names.html
738
738
  # AppSignal event naming guide
739
- # @since 1.3.0
740
739
  def instrument(
741
740
  name,
742
741
  title = nil,
@@ -764,6 +763,7 @@ module Appsignal
764
763
  # # query value will replace 'foo..' with a question mark `?`.
765
764
  # end
766
765
  #
766
+ # @since 2.0.0
767
767
  # @param name [String] Name of the instrumented event. Read our event
768
768
  # naming guide listed under "See also".
769
769
  # @param title [String, nil] Human readable name of the event.
@@ -777,7 +777,6 @@ module Appsignal
777
777
  # AppSignal custom instrumentation guide
778
778
  # @see https://docs.appsignal.com/api/event-names.html
779
779
  # AppSignal event naming guide
780
- # @since 2.0.0
781
780
  def instrument_sql(name, title = nil, body = nil, &block)
782
781
  instrument(
783
782
  name,
@@ -810,9 +809,10 @@ module Appsignal
810
809
  #
811
810
  # # Only the "my_event.my_group" instrumentation event is reported.
812
811
  #
812
+ # @since 3.10.0
813
813
  # @yield block of code that shouldn't be instrumented.
814
814
  # @return [Object] Returns the return value of the block.
815
- # @since 3.10.0
815
+ #
816
816
  # @see https://docs.appsignal.com/ruby/instrumentation/ignore-instrumentation.html
817
817
  # Ignore instrumentation guide
818
818
  def ignore_instrumentation_events
@@ -3,37 +3,70 @@
3
3
  module Appsignal
4
4
  module Helpers
5
5
  module Metrics
6
- def set_gauge(key, value, tags = {})
6
+ # Report a gauge metric.
7
+ #
8
+ # @since 2.6.0
9
+ # @param name [String, Symbol] The name of the metric.
10
+ # @param value [Integer, Float] The value of the metric.
11
+ # @param tags [Hash] The tags for the metric. The Hash keys can be either
12
+ # a String or a Symbol. The tag values can be a String, Symbol,
13
+ # Integer, Float, TrueClass or FalseClass.
14
+ #
15
+ # @see https://docs.appsignal.com/metrics/custom.html
16
+ # Metrics documentation
17
+ def set_gauge(name, value, tags = {})
7
18
  Appsignal::Extension.set_gauge(
8
- key.to_s,
19
+ name.to_s,
9
20
  value.to_f,
10
21
  Appsignal::Utils::Data.generate(tags)
11
22
  )
12
23
  rescue RangeError
13
24
  Appsignal.internal_logger
14
- .warn("Gauge value #{value} for key '#{key}' is too big")
25
+ .warn("The gauge value '#{value}' for metric '#{name}' is too big")
15
26
  end
16
27
 
17
- def increment_counter(key, value = 1.0, tags = {})
28
+ # Report a counter metric.
29
+ #
30
+ # @since 2.6.0
31
+ # @param name [String, Symbol] The name of the metric.
32
+ # @param value [Integer, Float] The value of the metric.
33
+ # @param tags [Hash] The tags for the metric. The Hash keys can be either
34
+ # a String or a Symbol. The tag values can be a String, Symbol,
35
+ # Integer, Float, TrueClass or FalseClass.
36
+ #
37
+ # @see https://docs.appsignal.com/metrics/custom.html
38
+ # Metrics documentation
39
+ def increment_counter(name, value = 1.0, tags = {})
18
40
  Appsignal::Extension.increment_counter(
19
- key.to_s,
41
+ name.to_s,
20
42
  value.to_f,
21
43
  Appsignal::Utils::Data.generate(tags)
22
44
  )
23
45
  rescue RangeError
24
46
  Appsignal.internal_logger
25
- .warn("Counter value #{value} for key '#{key}' is too big")
47
+ .warn("The counter value '#{value}' for metric '#{name}' is too big")
26
48
  end
27
49
 
28
- def add_distribution_value(key, value, tags = {})
50
+ # Report a distribution metric.
51
+ #
52
+ # @since 2.6.0
53
+ # @param name [String, Symbol] The name of the metric.
54
+ # @param value [Integer, Float] The value of the metric.
55
+ # @param tags [Hash] The tags for the metric. The Hash keys can be either
56
+ # a String or a Symbol. The tag values can be a String, Symbol,
57
+ # Integer, Float, TrueClass or FalseClass.
58
+ #
59
+ # @see https://docs.appsignal.com/metrics/custom.html
60
+ # Metrics documentation
61
+ def add_distribution_value(name, value, tags = {})
29
62
  Appsignal::Extension.add_distribution_value(
30
- key.to_s,
63
+ name.to_s,
31
64
  value.to_f,
32
65
  Appsignal::Utils::Data.generate(tags)
33
66
  )
34
67
  rescue RangeError
35
68
  Appsignal.internal_logger
36
- .warn("Distribution value #{value} for key '#{key}' is too big")
69
+ .warn("The distribution value '#{value}' for metric '#{name}' is too big")
37
70
  end
38
71
  end
39
72
  end
@@ -4,6 +4,8 @@ module Appsignal
4
4
  module Rack
5
5
  # @api private
6
6
  class BodyWrapper
7
+ IGNORED_ERRORS = [Errno::EPIPE].freeze
8
+
7
9
  def self.wrap(original_body, appsignal_transaction)
8
10
  # The logic of how Rack treats a response body differs based on which methods
9
11
  # the body responds to. This means that to support the Rack 3.x spec in full
@@ -49,6 +51,8 @@ module Appsignal
49
51
  Appsignal.instrument("close_response_body.rack") { @body.close }
50
52
  end
51
53
  @body_already_closed = true
54
+ rescue *IGNORED_ERRORS # Do not report
55
+ raise
52
56
  rescue Exception => error # rubocop:disable Lint/RescueException
53
57
  @transaction.set_error(error)
54
58
  raise error
@@ -75,6 +79,8 @@ module Appsignal
75
79
  Appsignal.instrument("process_response_body.rack", "Process Rack response body (#each)") do
76
80
  @body.each(&blk)
77
81
  end
82
+ rescue *IGNORED_ERRORS # Do not report
83
+ raise
78
84
  rescue Exception => error # rubocop:disable Lint/RescueException
79
85
  @transaction.set_error(error)
80
86
  raise error
@@ -94,6 +100,8 @@ module Appsignal
94
100
  Appsignal.instrument("process_response_body.rack", "Process Rack response body (#call)") do
95
101
  @body.call(stream)
96
102
  end
103
+ rescue *IGNORED_ERRORS # Do not report
104
+ raise
97
105
  rescue Exception => error # rubocop:disable Lint/RescueException
98
106
  @transaction.set_error(error)
99
107
  raise error
@@ -118,6 +126,8 @@ module Appsignal
118
126
  ) do
119
127
  @body.to_ary
120
128
  end
129
+ rescue *IGNORED_ERRORS # Do not report
130
+ raise
121
131
  rescue Exception => error # rubocop:disable Lint/RescueException
122
132
  @transaction.set_error(error)
123
133
  raise error
@@ -134,6 +144,8 @@ module Appsignal
134
144
  ) do
135
145
  @body.to_path
136
146
  end
147
+ rescue *IGNORED_ERRORS # Do not report
148
+ raise
137
149
  rescue Exception => error # rubocop:disable Lint/RescueException
138
150
  @transaction.set_error(error)
139
151
  raise error
@@ -30,9 +30,7 @@ module Appsignal
30
30
  # Check if we already have a running transaction
31
31
  if Thread.current[:appsignal_transaction].nil?
32
32
  # If not, start a new transaction
33
- set_current_transaction(
34
- Appsignal::Transaction.new(SecureRandom.uuid, namespace)
35
- )
33
+ set_current_transaction(Appsignal::Transaction.new(namespace))
36
34
  else
37
35
  # Otherwise, log the issue about trying to start another transaction
38
36
  Appsignal.internal_logger.warn(
@@ -109,24 +107,22 @@ module Appsignal
109
107
  end
110
108
 
111
109
  # @api private
112
- attr_reader :ext, :transaction_id, :action, :namespace, :request, :paused, :tags, :options,
113
- :breadcrumbs, :is_duplicate, :error_blocks
110
+ attr_reader :transaction_id, :action, :namespace
114
111
 
115
112
  # Use {.create} to create new transactions.
116
113
  #
117
- # @param transaction_id [String] ID of the to be created transaction.
118
114
  # @param namespace [String] Namespace of the to be created transaction.
119
115
  # @see create
120
116
  # @api private
121
- def initialize(transaction_id, namespace, ext: nil)
122
- @transaction_id = transaction_id
117
+ def initialize(namespace, id: SecureRandom.uuid, ext: nil)
118
+ @transaction_id = id
123
119
  @action = nil
124
120
  @namespace = namespace
125
121
  @paused = false
126
122
  @discarded = false
127
123
  @tags = {}
128
124
  @breadcrumbs = []
129
- @store = Hash.new({})
125
+ @store = Hash.new { |hash, key| hash[key] = {} }
130
126
  @error_blocks = Hash.new { |hash, key| hash[key] = [] }
131
127
  @is_duplicate = false
132
128
  @error_set = nil
@@ -143,10 +139,17 @@ module Appsignal
143
139
  ) || Appsignal::Extension::MockTransaction.new
144
140
  end
145
141
 
142
+ # @api private
143
+ def duplicate?
144
+ @is_duplicate
145
+ end
146
+
147
+ # @api private
146
148
  def nil_transaction?
147
149
  false
148
150
  end
149
151
 
152
+ # @api private
150
153
  def complete
151
154
  if discarded?
152
155
  Appsignal.internal_logger.debug "Skipping transaction '#{transaction_id}' " \
@@ -161,9 +164,9 @@ module Appsignal
161
164
  # create duplicates for errors, which are always sampled.
162
165
  should_sample = true
163
166
 
164
- unless is_duplicate
167
+ unless duplicate?
165
168
  self.class.last_errors = @error_blocks.keys
166
- should_sample = ext.finish(0)
169
+ should_sample = @ext.finish(0)
167
170
  end
168
171
 
169
172
  @error_blocks.each do |error, blocks|
@@ -190,7 +193,7 @@ module Appsignal
190
193
  end
191
194
  end
192
195
  sample_data if should_sample
193
- ext.complete
196
+ @ext.complete
194
197
  end
195
198
 
196
199
  # @api private
@@ -240,7 +243,10 @@ module Appsignal
240
243
  # @yield This block is called when the transaction is sampled. The block's
241
244
  # return value will become the new parameters.
242
245
  # @return [void]
246
+ #
243
247
  # @see Helpers::Instrumentation#add_params
248
+ # @see https://docs.appsignal.com/guides/custom-data/sample-data.html
249
+ # Sample data guide
244
250
  def add_params(given_params = nil, &block)
245
251
  @params.add(given_params, &block)
246
252
  end
@@ -249,6 +255,7 @@ module Appsignal
249
255
  # @api private
250
256
  # @since 4.0.0
251
257
  # @return [void]
258
+ #
252
259
  # @see Helpers::Instrumentation#set_empty_params!
253
260
  def set_empty_params!
254
261
  @params.set_empty_value!
@@ -273,6 +280,7 @@ module Appsignal
273
280
  #
274
281
  # When this method is called multiple times, it will merge the tags.
275
282
  #
283
+ # @since 4.0.0
276
284
  # @param given_tags [Hash] Collection of tags.
277
285
  # @option given_tags [String, Symbol, Integer] :any
278
286
  # The name of the tag as a Symbol.
@@ -286,7 +294,7 @@ module Appsignal
286
294
  def add_tags(given_tags = {})
287
295
  @tags.merge!(given_tags)
288
296
  end
289
- alias :set_tags add_tags
297
+ alias :set_tags :add_tags
290
298
 
291
299
  # Add session data to the transaction.
292
300
  #
@@ -295,12 +303,12 @@ module Appsignal
295
303
  # When both the `given_session_data` and a block is given to this method,
296
304
  # the block is leading and the argument will _not_ be used.
297
305
  #
306
+ # @since 4.0.0
298
307
  # @param given_session_data [Hash] A hash containing session data.
299
308
  # @yield This block is called when the transaction is sampled. The block's
300
309
  # return value will become the new session data.
301
310
  # @return [void]
302
311
  #
303
- # @since 4.0.0
304
312
  # @see Helpers::Instrumentation#add_session_data
305
313
  # @see https://docs.appsignal.com/guides/custom-data/sample-data.html
306
314
  # Sample data guide
@@ -315,13 +323,13 @@ module Appsignal
315
323
  # the `given_session_data` argument is leading and the block will _not_ be
316
324
  # called.
317
325
  #
326
+ # @api private
327
+ # @since 4.0.0
318
328
  # @param given_session_data [Hash] A hash containing session data.
319
329
  # @yield This block is called when the transaction is sampled. The block's
320
330
  # return value will become the new session data.
321
331
  # @return [void]
322
332
  #
323
- # @api private
324
- # @since 4.0.0
325
333
  # @see #add_session_data
326
334
  # @see https://docs.appsignal.com/guides/custom-data/sample-data.html
327
335
  # Sample data guide
@@ -332,12 +340,12 @@ module Appsignal
332
340
 
333
341
  # Add headers to the transaction.
334
342
  #
343
+ # @since 4.0.0
335
344
  # @param given_headers [Hash] A hash containing headers.
336
345
  # @yield This block is called when the transaction is sampled. The block's
337
346
  # return value will become the new headers.
338
347
  # @return [void]
339
348
  #
340
- # @since 4.0.0
341
349
  # @see Helpers::Instrumentation#add_headers
342
350
  # @see https://docs.appsignal.com/guides/custom-data/sample-data.html
343
351
  # Sample data guide
@@ -351,13 +359,13 @@ module Appsignal
351
359
  # When both the `given_headers` and a block is given to this method,
352
360
  # the block is leading and the argument will _not_ be used.
353
361
  #
362
+ # @api private
363
+ # @since 4.0.0
354
364
  # @param given_headers [Hash] A hash containing headers.
355
365
  # @yield This block is called when the transaction is sampled. The block's
356
366
  # return value will become the new headers.
357
367
  # @return [void]
358
368
  #
359
- # @api private
360
- # @since 4.0.0
361
369
  # @see #add_headers
362
370
  # @see https://docs.appsignal.com/guides/custom-data/sample-data.html
363
371
  # Sample data guide
@@ -369,11 +377,12 @@ module Appsignal
369
377
  # Add custom data to the transaction.
370
378
  #
371
379
  # @since 4.0.0
380
+ # @param data [Hash/Array]
381
+ # @return [void]
382
+ #
372
383
  # @see Helpers::Instrumentation#add_custom_data
373
384
  # @see https://docs.appsignal.com/guides/custom-data/sample-data.html
374
385
  # Sample data guide
375
- # @param data [Hash/Array]
376
- # @return [void]
377
386
  def add_custom_data(data)
378
387
  @custom_data.add(data)
379
388
  end
@@ -415,11 +424,11 @@ module Appsignal
415
424
  # An action name is used to identify the location of a certain sample;
416
425
  # error and performance issues.
417
426
  #
427
+ # @since 2.2.0
418
428
  # @param action [String] the action name to set.
419
429
  # @return [void]
420
- # @see Appsignal.set_action
421
- # @see #set_action_if_nil
422
- # @since 2.2.0
430
+ #
431
+ # @see Appsignal::Helpers::Instrumentation#set_action
423
432
  def set_action(action)
424
433
  return unless action
425
434
 
@@ -437,10 +446,12 @@ module Appsignal
437
446
  # Appsignal.set_action_if_nil("bar")
438
447
  # # Transaction action will be "foo"
439
448
  #
449
+ # @api private
450
+ # @since 2.2.0
440
451
  # @param action [String]
441
452
  # @return [void]
453
+ #
442
454
  # @see #set_action
443
- # @since 2.2.0
444
455
  def set_action_if_nil(action)
445
456
  return if @action
446
457
 
@@ -459,9 +470,13 @@ module Appsignal
459
470
  # @example
460
471
  # transaction.set_namespace("background")
461
472
  #
473
+ # @since 2.2.0
462
474
  # @param namespace [String] namespace name to use for this transaction.
463
475
  # @return [void]
464
- # @since 2.2.0
476
+ #
477
+ # @see Appsignal::Helpers::Instrumentation#set_namespace
478
+ # @see https://docs.appsignal.com/guides/namespaces.html
479
+ # Grouping with namespaces guide
465
480
  def set_namespace(namespace)
466
481
  return unless namespace
467
482
 
@@ -493,7 +508,8 @@ module Appsignal
493
508
  @ext.set_metadata(key, value)
494
509
  end
495
510
 
496
- # @see Appsignal::Helpers::Instrumentation#add_error
511
+ # @api private
512
+ # @see Appsignal::Helpers::Instrumentation#report_error
497
513
  def add_error(error, &block)
498
514
  unless error.is_a?(Exception)
499
515
  Appsignal.internal_logger.error "Appsignal::Transaction#add_error: Cannot add error. " \
@@ -516,21 +532,19 @@ module Appsignal
516
532
  @error_blocks[error] << block
517
533
  @error_blocks[error].compact!
518
534
  end
519
-
520
535
  alias :set_error :add_error
521
-
522
536
  alias_method :add_exception, :add_error
523
537
 
524
- # @see Helpers::Instrumentation#instrument
525
538
  # @api private
539
+ # @see Helpers::Instrumentation#instrument
526
540
  def start_event
527
541
  return if paused?
528
542
 
529
543
  @ext.start_event(0)
530
544
  end
531
545
 
532
- # @see Helpers::Instrumentation#instrument
533
546
  # @api private
547
+ # @see Helpers::Instrumentation#instrument
534
548
  def finish_event(name, title, body, body_format = Appsignal::EventFormatter::DEFAULT)
535
549
  return if paused?
536
550
 
@@ -543,8 +557,8 @@ module Appsignal
543
557
  )
544
558
  end
545
559
 
546
- # @see Helpers::Instrumentation#instrument
547
560
  # @api private
561
+ # @see Helpers::Instrumentation#instrument
548
562
  def record_event(name, title, body, duration, body_format = Appsignal::EventFormatter::DEFAULT)
549
563
  return if paused?
550
564
 
@@ -558,6 +572,7 @@ module Appsignal
558
572
  )
559
573
  end
560
574
 
575
+ # @api private
561
576
  # @see Helpers::Instrumentation#instrument
562
577
  def instrument(name, title = nil, body = nil, body_format = Appsignal::EventFormatter::DEFAULT)
563
578
  start_event
@@ -574,10 +589,13 @@ module Appsignal
574
589
 
575
590
  protected
576
591
 
577
- attr_writer :is_duplicate, :tags, :custom_data, :breadcrumbs, :params, :session_data, :headers
592
+ attr_writer :is_duplicate, :tags, :custom_data, :breadcrumbs, :params,
593
+ :session_data, :headers
578
594
 
579
595
  private
580
596
 
597
+ attr_reader :breadcrumbs
598
+
581
599
  def _set_error(error)
582
600
  backtrace = cleaned_backtrace(error.backtrace)
583
601
  @ext.set_error(
@@ -663,11 +681,10 @@ module Appsignal
663
681
 
664
682
  def duplicate
665
683
  new_transaction_id = SecureRandom.uuid
666
-
667
684
  self.class.new(
668
- new_transaction_id,
669
685
  namespace,
670
- :ext => ext.duplicate(new_transaction_id)
686
+ :id => new_transaction_id,
687
+ :ext => @ext.duplicate(new_transaction_id)
671
688
  ).tap do |transaction|
672
689
  transaction.is_duplicate = true
673
690
  transaction.tags = @tags.dup
@@ -679,7 +696,6 @@ module Appsignal
679
696
  end
680
697
  end
681
698
 
682
- # @api private
683
699
  def params
684
700
  @params.value
685
701
  rescue => e
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Appsignal
4
- VERSION = "4.0.0.beta.2"
4
+ VERSION = "4.0.0"
5
5
  end
data/lib/appsignal.rb CHANGED
@@ -44,6 +44,7 @@ module Appsignal
44
44
  # @see Extension
45
45
  # @see extension_loaded?
46
46
  attr_accessor :extension_loaded
47
+
47
48
  # @!attribute [rw] internal_logger
48
49
  # Accessor for the internal AppSignal logger.
49
50
  #
@@ -937,6 +937,13 @@ describe Appsignal::CLI::Diagnose, :api_stub => true, :send_report => :yes_cli_i
937
937
  " loaders: \"MyApp\"\n" \
938
938
  " file: \"TestApp\"\n"
939
939
  )
940
+ # Outputs values from the DSL
941
+ expect(output).to include(
942
+ " ignore_actions: [\"Action from DSL\"]\n" \
943
+ " Sources:\n" \
944
+ " default: []\n" \
945
+ " dsl: [\"Action from DSL\"]\n"
946
+ )
940
947
 
941
948
  expect(received_report["app"]["rails"]).to be(true)
942
949
  expect(received_report["config"]["sources"]).to include(
@@ -947,6 +954,12 @@ describe Appsignal::CLI::Diagnose, :api_stub => true, :send_report => :yes_cli_i
947
954
  "name" => "MyApp"
948
955
  }
949
956
  )
957
+ # Includes values from the DSL
958
+ expect(received_report["config"]["sources"]).to include(
959
+ "dsl" => {
960
+ "ignore_actions" => ["Action from DSL"]
961
+ }
962
+ )
950
963
  end
951
964
 
952
965
  context "when there's a problem loading the app" do
@@ -963,7 +976,6 @@ describe Appsignal::CLI::Diagnose, :api_stub => true, :send_report => :yes_cli_i
963
976
  "ExampleStandardError: error message"
964
977
  )
965
978
 
966
- pp received_report["app"]
967
979
  expect(received_report["app"]["load_error"])
968
980
  .to eq("ExampleStandardError: error message\nline 1\nline 2")
969
981
  end
@@ -72,6 +72,18 @@ describe Appsignal::Rack::BodyWrapper do
72
72
  expect(transaction).to have_error("ExampleException", "error message")
73
73
  end
74
74
 
75
+ it "doesn't report EPIPE error" do
76
+ fake_body = double
77
+ expect(fake_body).to receive(:each).once.and_raise(Errno::EPIPE)
78
+
79
+ wrapped = described_class.wrap(fake_body, transaction)
80
+ expect do
81
+ expect { |b| wrapped.each(&b) }.to yield_control
82
+ end.to raise_error(Errno::EPIPE)
83
+
84
+ expect(transaction).to_not have_error
85
+ end
86
+
75
87
  it "closes the body and tracks an instrumentation event when it gets closed" do
76
88
  fake_body = double(:close => nil)
77
89
  expect(fake_body).to receive(:each).once.and_yield("a").and_yield("b").and_yield("c")
@@ -134,6 +146,17 @@ describe Appsignal::Rack::BodyWrapper do
134
146
  expect(transaction).to have_error("ExampleException", "error message")
135
147
  end
136
148
 
149
+ it "doesn't report EPIPE error" do
150
+ expect(fake_body).to receive(:each).once.and_raise(Errno::EPIPE)
151
+
152
+ wrapped = described_class.wrap(fake_body, transaction)
153
+ expect do
154
+ expect { |b| wrapped.each(&b) }.to yield_control
155
+ end.to raise_error(Errno::EPIPE)
156
+
157
+ expect(transaction).to_not have_error
158
+ end
159
+
137
160
  it "reads out the body in full using to_ary" do
138
161
  expect(fake_body).to receive(:to_ary).and_return(["one", "two", "three"])
139
162
 
@@ -207,6 +230,17 @@ describe Appsignal::Rack::BodyWrapper do
207
230
  expect(transaction).to have_error("ExampleException", "error message")
208
231
  end
209
232
 
233
+ it "doesn't report EPIPE error" do
234
+ expect(fake_body).to receive(:to_path).once.and_raise(Errno::EPIPE)
235
+
236
+ wrapped = described_class.wrap(fake_body, transaction)
237
+ expect do
238
+ wrapped.to_path
239
+ end.to raise_error(Errno::EPIPE)
240
+
241
+ expect(transaction).to_not have_error
242
+ end
243
+
210
244
  it "exposes to_path to the sender" do
211
245
  allow(fake_body).to receive(:to_path).and_return("/tmp/file.bin")
212
246
 
@@ -259,5 +293,19 @@ describe Appsignal::Rack::BodyWrapper do
259
293
 
260
294
  expect(transaction).to have_error("ExampleException", "error message")
261
295
  end
296
+
297
+ it "doesn't report EPIPE error" do
298
+ fake_rack_stream = double
299
+ expect(fake_body).to receive(:call)
300
+ .with(fake_rack_stream)
301
+ .and_raise(Errno::EPIPE)
302
+
303
+ wrapped = described_class.wrap(fake_body, transaction)
304
+ expect do
305
+ wrapped.call(fake_rack_stream)
306
+ end.to raise_error(Errno::EPIPE)
307
+
308
+ expect(transaction).to_not have_error
309
+ end
262
310
  end
263
311
  end
@@ -39,7 +39,7 @@ describe Appsignal::Transaction do
39
39
  let(:ext) { "some_ext" }
40
40
 
41
41
  it "assigns the extension transaction to the transaction" do
42
- expect(new_transaction(:ext => ext).ext).to be(ext)
42
+ expect(described_class.new("web", :ext => ext).ext).to be(ext)
43
43
  end
44
44
  end
45
45
 
@@ -338,11 +338,11 @@ describe Appsignal::Transaction do
338
338
  expect(original_transaction.ext).to_not eq(duplicate_transaction.ext)
339
339
  end
340
340
 
341
- it "sets is_duplicate set to true on the duplicate transaction" do
341
+ it "marks transaction as duplicate on the duplicate transaction" do
342
342
  original_transaction, duplicate_transaction = created_transactions
343
343
 
344
- expect(original_transaction.is_duplicate).to be(false)
345
- expect(duplicate_transaction.is_duplicate).to be(true)
344
+ expect(original_transaction.duplicate?).to be(false)
345
+ expect(duplicate_transaction.duplicate?).to be(true)
346
346
  end
347
347
  end
348
348
 
@@ -517,7 +517,7 @@ describe Appsignal::Transaction do
517
517
  it "changes the pause flag to true" do
518
518
  expect do
519
519
  transaction.pause!
520
- end.to change(transaction, :paused).from(false).to(true)
520
+ end.to change(transaction, :paused?).from(false).to(true)
521
521
  end
522
522
  end
523
523
 
@@ -527,7 +527,7 @@ describe Appsignal::Transaction do
527
527
  it "changes the pause flag to false" do
528
528
  expect do
529
529
  transaction.resume!
530
- end.to change(transaction, :paused).from(true).to(false)
530
+ end.to change(transaction, :paused?).from(true).to(false)
531
531
  end
532
532
  end
533
533
 
@@ -590,6 +590,13 @@ describe Appsignal::Transaction do
590
590
 
591
591
  expect(transaction.store("test")).to eql("transaction" => "value")
592
592
  end
593
+
594
+ it "has a default value of a Hash for store values" do
595
+ transaction.store("abc")["def"] = "123"
596
+
597
+ expect(transaction.store("abc")).to eq("def" => "123")
598
+ expect(transaction.store("xyz")).to eq({})
599
+ end
593
600
  end
594
601
 
595
602
  describe "#add_params" do
@@ -1157,7 +1157,7 @@ describe Appsignal do
1157
1157
  Appsignal::Extension.data_map_new
1158
1158
  ).and_raise(RangeError)
1159
1159
  expect(Appsignal.internal_logger).to receive(:warn)
1160
- .with("Gauge value 10 for key 'key' is too big")
1160
+ .with("The gauge value '10' for metric 'key' is too big")
1161
1161
 
1162
1162
  Appsignal.set_gauge("key", 10)
1163
1163
  end
@@ -1192,7 +1192,7 @@ describe Appsignal do
1192
1192
  expect(Appsignal::Extension).to receive(:increment_counter)
1193
1193
  .with("key", 10, Appsignal::Extension.data_map_new).and_raise(RangeError)
1194
1194
  expect(Appsignal.internal_logger).to receive(:warn)
1195
- .with("Counter value 10 for key 'key' is too big")
1195
+ .with("The counter value '10' for metric 'key' is too big")
1196
1196
 
1197
1197
  Appsignal.increment_counter("key", 10)
1198
1198
  end
@@ -1221,7 +1221,7 @@ describe Appsignal do
1221
1221
  expect(Appsignal::Extension).to receive(:add_distribution_value)
1222
1222
  .with("key", 10, Appsignal::Extension.data_map_new).and_raise(RangeError)
1223
1223
  expect(Appsignal.internal_logger).to receive(:warn)
1224
- .with("Distribution value 10 for key 'key' is too big")
1224
+ .with("The distribution value '10' for metric 'key' is too big")
1225
1225
 
1226
1226
  Appsignal.add_distribution_value("key", 10)
1227
1227
  end
@@ -3,3 +3,8 @@ require_relative "application"
3
3
 
4
4
  # Initialize the Rails application.
5
5
  MyApp::Application.initialize!
6
+
7
+ # Asserted from the diagnose spec
8
+ Appsignal.configure do |config|
9
+ config.ignore_actions = ["Action from DSL"]
10
+ end
@@ -16,7 +16,7 @@ module TransactionHelpers
16
16
  end
17
17
 
18
18
  def new_transaction(namespace = default_namespace, ext: nil)
19
- Appsignal::Transaction.new(SecureRandom.uuid, namespace, :ext => ext)
19
+ Appsignal::Transaction.new(namespace, :ext => ext)
20
20
  end
21
21
 
22
22
  def rack_request(env)
@@ -167,6 +167,10 @@ end
167
167
  module AppsignalTest
168
168
  module Transaction
169
169
  module ClassMethods
170
+ def self.extended(base)
171
+ base.attr_reader :ext, :error_blocks
172
+ end
173
+
170
174
  # Override the {Appsignal::Transaction.new} method so we can track which
171
175
  # transactions are created on the {Appsignal::Testing.transactions} list.
172
176
  #
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.0.0.beta.2
4
+ version: 4.0.0
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-08-19 00:00:00.000000000 Z
13
+ date: 2024-08-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rack