appsignal 4.5.17 → 4.6.0

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.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +33 -0
  3. data/CLAUDE.md +177 -0
  4. data/README.md +17 -0
  5. data/appsignal.gemspec +1 -0
  6. data/build_matrix.yml +29 -0
  7. data/lib/appsignal/auth_check.rb +3 -3
  8. data/lib/appsignal/check_in/cron.rb +1 -1
  9. data/lib/appsignal/check_in/event.rb +1 -1
  10. data/lib/appsignal/check_in/scheduler.rb +3 -1
  11. data/lib/appsignal/check_in.rb +9 -6
  12. data/lib/appsignal/cli/diagnose.rb +1 -1
  13. data/lib/appsignal/cli.rb +1 -1
  14. data/lib/appsignal/config.rb +231 -30
  15. data/lib/appsignal/custom_marker.rb +3 -3
  16. data/lib/appsignal/environment.rb +7 -1
  17. data/lib/appsignal/event_formatter/action_view/render_formatter.rb +1 -1
  18. data/lib/appsignal/event_formatter/active_record/instantiation_formatter.rb +1 -1
  19. data/lib/appsignal/event_formatter/active_record/sql_formatter.rb +1 -1
  20. data/lib/appsignal/event_formatter/elastic_search/search_formatter.rb +1 -1
  21. data/lib/appsignal/event_formatter/faraday/request_formatter.rb +1 -1
  22. data/lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter.rb +1 -1
  23. data/lib/appsignal/event_formatter/rom/sql_formatter.rb +1 -1
  24. data/lib/appsignal/event_formatter/sequel/sql_formatter.rb +1 -1
  25. data/lib/appsignal/event_formatter/view_component/render_formatter.rb +1 -1
  26. data/lib/appsignal/event_formatter.rb +41 -3
  27. data/lib/appsignal/extension.rb +1 -1
  28. data/lib/appsignal/garbage_collection.rb +1 -1
  29. data/lib/appsignal/helpers/instrumentation.rb +82 -35
  30. data/lib/appsignal/helpers/metrics.rb +12 -9
  31. data/lib/appsignal/hooks/action_cable.rb +1 -1
  32. data/lib/appsignal/hooks/action_mailer.rb +1 -0
  33. data/lib/appsignal/hooks/active_job.rb +1 -1
  34. data/lib/appsignal/hooks/active_support_notifications.rb +1 -1
  35. data/lib/appsignal/hooks/at_exit.rb +1 -1
  36. data/lib/appsignal/hooks/celluloid.rb +1 -1
  37. data/lib/appsignal/hooks/data_mapper.rb +1 -1
  38. data/lib/appsignal/hooks/delayed_job.rb +1 -1
  39. data/lib/appsignal/hooks/dry_monitor.rb +1 -1
  40. data/lib/appsignal/hooks/excon.rb +1 -1
  41. data/lib/appsignal/hooks/gvl.rb +1 -1
  42. data/lib/appsignal/hooks/http.rb +1 -1
  43. data/lib/appsignal/hooks/mongo_ruby_driver.rb +1 -1
  44. data/lib/appsignal/hooks/mri.rb +1 -1
  45. data/lib/appsignal/hooks/net_http.rb +1 -1
  46. data/lib/appsignal/hooks/ownership.rb +1 -1
  47. data/lib/appsignal/hooks/passenger.rb +1 -1
  48. data/lib/appsignal/hooks/puma.rb +1 -1
  49. data/lib/appsignal/hooks/que.rb +1 -1
  50. data/lib/appsignal/hooks/rake.rb +1 -1
  51. data/lib/appsignal/hooks/redis.rb +1 -1
  52. data/lib/appsignal/hooks/redis_client.rb +1 -1
  53. data/lib/appsignal/hooks/resque.rb +1 -1
  54. data/lib/appsignal/hooks/sequel.rb +2 -1
  55. data/lib/appsignal/hooks/shoryuken.rb +1 -1
  56. data/lib/appsignal/hooks/sidekiq.rb +1 -0
  57. data/lib/appsignal/hooks/unicorn.rb +1 -1
  58. data/lib/appsignal/hooks/webmachine.rb +1 -1
  59. data/lib/appsignal/hooks.rb +5 -3
  60. data/lib/appsignal/integrations/action_cable.rb +1 -1
  61. data/lib/appsignal/integrations/active_support_notifications.rb +1 -1
  62. data/lib/appsignal/integrations/capistrano/capistrano_2_tasks.rb +1 -1
  63. data/lib/appsignal/integrations/data_mapper.rb +1 -1
  64. data/lib/appsignal/integrations/delayed_job_plugin.rb +1 -1
  65. data/lib/appsignal/integrations/dry_monitor.rb +1 -1
  66. data/lib/appsignal/integrations/excon.rb +1 -1
  67. data/lib/appsignal/integrations/http.rb +1 -1
  68. data/lib/appsignal/integrations/mongo_ruby_driver.rb +1 -1
  69. data/lib/appsignal/integrations/net_http.rb +1 -1
  70. data/lib/appsignal/integrations/object.rb +18 -2
  71. data/lib/appsignal/integrations/ownership.rb +1 -1
  72. data/lib/appsignal/integrations/puma.rb +1 -1
  73. data/lib/appsignal/integrations/que.rb +1 -1
  74. data/lib/appsignal/integrations/railtie.rb +2 -2
  75. data/lib/appsignal/integrations/rake.rb +2 -2
  76. data/lib/appsignal/integrations/redis.rb +1 -1
  77. data/lib/appsignal/integrations/redis_client.rb +1 -1
  78. data/lib/appsignal/integrations/resque.rb +2 -2
  79. data/lib/appsignal/integrations/shoryuken.rb +1 -1
  80. data/lib/appsignal/integrations/sidekiq.rb +3 -3
  81. data/lib/appsignal/integrations/unicorn.rb +1 -1
  82. data/lib/appsignal/integrations/webmachine.rb +1 -1
  83. data/lib/appsignal/internal_errors.rb +2 -2
  84. data/lib/appsignal/loaders.rb +1 -1
  85. data/lib/appsignal/logger.rb +36 -19
  86. data/lib/appsignal/marker.rb +1 -1
  87. data/lib/appsignal/probes/gvl.rb +4 -3
  88. data/lib/appsignal/probes/helpers.rb +1 -1
  89. data/lib/appsignal/probes/mri.rb +3 -3
  90. data/lib/appsignal/probes/sidekiq.rb +4 -3
  91. data/lib/appsignal/probes.rb +20 -15
  92. data/lib/appsignal/rack.rb +1 -1
  93. data/lib/appsignal/sample_data.rb +31 -12
  94. data/lib/appsignal/span.rb +1 -1
  95. data/lib/appsignal/system.rb +9 -8
  96. data/lib/appsignal/transaction.rb +72 -52
  97. data/lib/appsignal/transmitter.rb +1 -1
  98. data/lib/appsignal/utils.rb +1 -1
  99. data/lib/appsignal/version.rb +2 -1
  100. data/lib/appsignal.rb +22 -14
  101. data/lib/puma/plugin/appsignal.rb +1 -1
  102. data/sig/appsignal.rbi +2599 -0
  103. data/sig/appsignal.rbs +2420 -0
  104. metadata +20 -6
data/sig/appsignal.rbi ADDED
@@ -0,0 +1,2599 @@
1
+ # typed: strong
2
+ # AppSignal for Ruby gem's main module.
3
+ #
4
+ # Provides method to control the AppSignal instrumentation and the system
5
+ # agent. Also provides direct access to instrumentation helpers (from
6
+ # {Appsignal::Helpers::Instrumentation}) and metrics helpers (from
7
+ # {Appsignal::Helpers::Metrics}) for ease of use.
8
+ module Appsignal
9
+ extend Appsignal::Helpers::Metrics
10
+ extend Appsignal::Helpers::Instrumentation
11
+ VERSION = T.let("4.5.17", T.untyped)
12
+
13
+ class << self
14
+ # The loaded AppSignal configuration.
15
+ # Returns the current AppSignal configuration.
16
+ #
17
+ # Can return `nil` if no configuration has been set or automatically loaded
18
+ # by an automatic integration or by calling {.start}.
19
+ #
20
+ # ```ruby
21
+ # Appsignal.config
22
+ # ```
23
+ #
24
+ # _@see_ `configure`
25
+ #
26
+ # _@see_ `Config`
27
+ sig { returns(T.nilable(Config)) }
28
+ attr_reader :config
29
+
30
+ # Returns the error that was encountered while loading the `appsignal.rb`
31
+ # config file.
32
+ #
33
+ # It does not include any error that occurred while loading the
34
+ # `appsignal.yml` file.
35
+ #
36
+ # If the value is `nil`, no error was encountered or AppSignal wasn't
37
+ # started yet.
38
+ sig { returns(T.nilable(Exception)) }
39
+ attr_reader :config_error
40
+ end
41
+
42
+ # Start the AppSignal integration.
43
+ #
44
+ # Starts AppSignal with the given configuration. If no configuration is set
45
+ # yet it will try to automatically load the configuration using the
46
+ # environment loaded from environment variables and the currently working
47
+ # directory.
48
+ #
49
+ # This is not required for the automatic integrations AppSignal offers, but
50
+ # this is required for all non-automatic integrations and pure Ruby
51
+ # applications. For more information, see our [integrations
52
+ # list](https://docs.appsignal.com/ruby/integrations/) and our [Integrating
53
+ # AppSignal](https://docs.appsignal.com/ruby/instrumentation/integrating-appsignal.html)
54
+ # guide.
55
+ #
56
+ # ```ruby
57
+ # Appsignal.start
58
+ # ```
59
+ #
60
+ # with custom loaded configuration
61
+ # ```ruby
62
+ # Appsignal.configure(:production) do |config|
63
+ # config.ignore_actions = ["My action"]
64
+ # end
65
+ # Appsignal.start
66
+ # ```
67
+ sig { void }
68
+ def self.start; end
69
+
70
+ # Stop AppSignal's agent.
71
+ #
72
+ # Stops the AppSignal agent. Call this before the end of your program to
73
+ # make sure the agent is stopped as well.
74
+ #
75
+ # _@param_ `called_by` — Name of the thing that requested the agent to be stopped. Will be used in the AppSignal log file.
76
+ #
77
+ # ```ruby
78
+ # Appsignal.start
79
+ # # Run your application
80
+ # Appsignal.stop
81
+ # ```
82
+ sig { params(called_by: T.nilable(String)).void }
83
+ def self.stop(called_by = nil); end
84
+
85
+ # Configure the AppSignal Ruby gem using a DSL.
86
+ #
87
+ # Pass a block to the configure method to configure the Ruby gem.
88
+ #
89
+ # Each config option defined in our docs can be fetched, set and modified
90
+ # via a helper method in the given block.
91
+ #
92
+ # After AppSignal has started using {start}, the configuration can not be
93
+ # modified. Any calls to this helper will be ignored.
94
+ #
95
+ # This helper should not be used to configure multiple environments, like
96
+ # done in the YAML file. Configure the environment you want active when the
97
+ # application starts.
98
+ #
99
+ # _@param_ `env_param` — The environment to load.
100
+ #
101
+ # _@param_ `root_path` — The path to look the `config/appsignal.yml` config file in. Defaults to the current working directory.
102
+ #
103
+ # Configure AppSignal for the application
104
+ # ```ruby
105
+ # Appsignal.configure do |config|
106
+ # config.path = "/the/app/path"
107
+ # config.active = ENV["APP_ACTIVE"] == "true"
108
+ # config.push_api_key = File.read("appsignal_key.txt").chomp
109
+ # config.ignore_actions = ENDPOINTS.select { |e| e.public? }.map(&:name)
110
+ # config.request_headers << "MY_CUSTOM_HEADER"
111
+ # end
112
+ # ```
113
+ #
114
+ # Configure AppSignal for the application and select the environment
115
+ # ```ruby
116
+ # Appsignal.configure(:production) do |config|
117
+ # config.active = true
118
+ # end
119
+ # ```
120
+ #
121
+ # Automatically detects the app environment
122
+ # ```ruby
123
+ # # Tries to determine the app environment automatically from the
124
+ # # environment and the libraries it integrates with.
125
+ # ENV["RACK_ENV"] = "production"
126
+ #
127
+ # Appsignal.configure do |config|
128
+ # config.env # => "production"
129
+ # end
130
+ # ```
131
+ #
132
+ # Calling configure multiple times for different environments resets the configuration
133
+ # ```ruby
134
+ # Appsignal.configure(:development) do |config|
135
+ # config.ignore_actions = ["My action"]
136
+ # end
137
+ #
138
+ # Appsignal.configure(:production) do |config|
139
+ # config.ignore_actions # => []
140
+ # end
141
+ # ```
142
+ #
143
+ # Load config without a block
144
+ # ```ruby
145
+ # # This will require either ENV vars being set
146
+ # # or the config/appsignal.yml being present
147
+ # Appsignal.configure
148
+ # # Or for the environment given as an argument
149
+ # Appsignal.configure(:production)
150
+ # ```
151
+ #
152
+ # _@see_ `config`
153
+ #
154
+ # _@see_ `Config`
155
+ #
156
+ # _@see_ `https://docs.appsignal.com/ruby/configuration.html` — Configuration guide
157
+ #
158
+ # _@see_ `https://docs.appsignal.com/ruby/configuration/options.html` — Configuration options
159
+ sig { params(env_param: T.nilable(T.any(String, Symbol)), root_path: T.nilable(String), blk: T.proc.params(config_dsl: Appsignal::Config::ConfigDSL).void).void }
160
+ def self.configure(env_param = nil, root_path: nil, &blk); end
161
+
162
+ sig { void }
163
+ def self.forked; end
164
+
165
+ # Load an AppSignal integration.
166
+ #
167
+ # Load one of the supported integrations via our loader system.
168
+ # This will set config defaults and integratie with the library if
169
+ # AppSignal is active upon start.
170
+ #
171
+ # _@param_ `integration_name` — Name of the integration to load.
172
+ #
173
+ # Load Sinatra integrations
174
+ # ```ruby
175
+ # # First load the integration
176
+ # Appsignal.load(:sinatra)
177
+ # # Start AppSignal
178
+ # Appsignal.start
179
+ # ```
180
+ #
181
+ # Load Sinatra integrations and define custom config
182
+ # ```ruby
183
+ # # First load the integration
184
+ # Appsignal.load(:sinatra)
185
+ #
186
+ # # Customize config
187
+ # Appsignal.configure do |config|
188
+ # config.ignore_actions = ["GET /ping"]
189
+ # end
190
+ #
191
+ # # Start AppSignal
192
+ # Appsignal.start
193
+ # ```
194
+ sig { params(integration_name: T.any(String, Symbol)).void }
195
+ def self.load(integration_name); end
196
+
197
+ # Returns if the C-extension was loaded properly.
198
+ #
199
+ # _@see_ `Extension`
200
+ sig { returns(T::Boolean) }
201
+ def self.extension_loaded?; end
202
+
203
+ # Returns if {.start} has been called before with a valid config to start
204
+ # AppSignal.
205
+ #
206
+ # _@see_ `Extension`
207
+ sig { returns(T::Boolean) }
208
+ def self.started?; end
209
+
210
+ # Returns the active state of the AppSignal integration.
211
+ #
212
+ # Conditions apply for AppSignal to be marked as active:
213
+ #
214
+ # - There is a config set on the {.config} attribute.
215
+ # - The set config is active {Config.active?}.
216
+ # - The AppSignal Extension is loaded {.extension_loaded?}.
217
+ #
218
+ # This logic is used within instrument helper such as {.instrument} so it's
219
+ # not necessary to wrap {.instrument} calls with this method.
220
+ #
221
+ # Do this
222
+ # ```ruby
223
+ # Appsignal.instrument(..) do
224
+ # # Do this
225
+ # end
226
+ # ```
227
+ #
228
+ # Don't do this
229
+ # ```ruby
230
+ # if Appsignal.active?
231
+ # Appsignal.instrument(..) do
232
+ # # Don't do this
233
+ # end
234
+ # end
235
+ # ```
236
+ sig { returns(T::Boolean) }
237
+ def self.active?; end
238
+
239
+ # Check if the AppSignal Ruby gem has started successfully.
240
+ #
241
+ # If it has not (yet) started or encountered an error in the
242
+ # `config/appsignal.rb` config file during start up that prevented it from
243
+ # starting, it will raise a {Appsignal::NotStartedError}.
244
+ #
245
+ # If there an error raised from the config file, it will include it as the
246
+ # error cause of the raised error.
247
+ sig { void }
248
+ def self.check_if_started!; end
249
+
250
+ # Report a gauge metric.
251
+ #
252
+ # _@param_ `name` — The name of the metric.
253
+ #
254
+ # _@param_ `value` — The value of the metric.
255
+ #
256
+ # _@param_ `tags` — The tags for the metric. The Hash keys can be either a String or a Symbol. The tag values can be a String, Symbol, Integer, Float, TrueClass or FalseClass.
257
+ #
258
+ # _@see_ `https://docs.appsignal.com/metrics/custom.html` — Metrics documentation
259
+ sig { params(name: T.any(String, Symbol), value: T.any(Integer, Float), tags: T::Hash[String, Object]).void }
260
+ def self.set_gauge(name, value, tags = {}); end
261
+
262
+ # Report a counter metric.
263
+ #
264
+ # _@param_ `name` — The name of the metric.
265
+ #
266
+ # _@param_ `value` — The value of the metric.
267
+ #
268
+ # _@param_ `tags` — The tags for the metric. The Hash keys can be either a String or a Symbol. The tag values can be a String, Symbol, Integer, Float, TrueClass or FalseClass.
269
+ #
270
+ # _@see_ `https://docs.appsignal.com/metrics/custom.html` — Metrics documentation
271
+ sig { params(name: T.any(String, Symbol), value: T.any(Integer, Float), tags: T::Hash[String, Object]).void }
272
+ def self.increment_counter(name, value = 1.0, tags = {}); end
273
+
274
+ # Report a distribution metric.
275
+ #
276
+ # _@param_ `name` — The name of the metric.
277
+ #
278
+ # _@param_ `value` — The value of the metric.
279
+ #
280
+ # _@param_ `tags` — The tags for the metric. The Hash keys can be either a String or a Symbol. The tag values can be a String, Symbol, Integer, Float, TrueClass or FalseClass.
281
+ #
282
+ # _@see_ `https://docs.appsignal.com/metrics/custom.html` — Metrics documentation
283
+ sig { params(name: T.any(String, Symbol), value: T.any(Integer, Float), tags: T::Hash[String, Object]).void }
284
+ def self.add_distribution_value(name, value, tags = {}); end
285
+
286
+ # Monitor a block of code with AppSignal.
287
+ #
288
+ # This is a helper to create an AppSignal transaction, track any errors
289
+ # that may occur and complete the transaction.
290
+ #
291
+ # This helper is recommended to be used in Ruby scripts and parts of an
292
+ # app not already instrumented by AppSignal's automatic instrumentations.
293
+ #
294
+ # Use this helper in combination with our {.instrument} helper to track
295
+ # instrumentation events.
296
+ #
297
+ # If AppSignal is not active ({Appsignal.active?}) it will still execute
298
+ # the block, but not create a transaction for it.
299
+ #
300
+ # _@param_ `namespace` — The namespace to set on the new transaction. Defaults to the 'web' namespace. This will not update the active transaction's namespace if {.monitor} is called when another transaction is already active.
301
+ #
302
+ # _@param_ `action` — The action name for the transaction. The action name is required to be set for the transaction to be reported. The argument can be set to `nil` or `:set_later` if the action is set within the block with {#set_action}. This will not update the active transaction's action if {.monitor} is called when another transaction is already active.
303
+ #
304
+ # _@return_ — The value of the given block is returned.
305
+ # Returns `nil` if there already is a transaction active and no block
306
+ # was given.
307
+ #
308
+ # Instrument a block of code
309
+ # ```ruby
310
+ # Appsignal.monitor(
311
+ # :namespace => "my_namespace",
312
+ # :action => "MyClass#my_method"
313
+ # ) do
314
+ # # Some code
315
+ # end
316
+ # ```
317
+ #
318
+ # Instrument a block of code using the default namespace
319
+ # ```ruby
320
+ # Appsignal.monitor(
321
+ # :action => "MyClass#my_method"
322
+ # ) do
323
+ # # Some code
324
+ # end
325
+ # ```
326
+ #
327
+ # Instrument a block of code with an instrumentation event
328
+ # ```ruby
329
+ # Appsignal.monitor(
330
+ # :namespace => "my_namespace",
331
+ # :action => "MyClass#my_method"
332
+ # ) do
333
+ # Appsignal.instrument("some_event.some_group") do
334
+ # # Some code
335
+ # end
336
+ # end
337
+ # ```
338
+ #
339
+ # Set the action name in the monitor block
340
+ # ```ruby
341
+ # Appsignal.monitor(
342
+ # :action => nil
343
+ # ) do
344
+ # # Some code
345
+ #
346
+ # Appsignal.set_action("GET /resource/:id")
347
+ # end
348
+ # ```
349
+ #
350
+ # Set the action name in the monitor block
351
+ # ```ruby
352
+ # Appsignal.monitor(
353
+ # :action => :set_later # Explicit placeholder
354
+ # ) do
355
+ # # Some code
356
+ #
357
+ # Appsignal.set_action("GET /resource/:id")
358
+ # end
359
+ # ```
360
+ #
361
+ # Set custom metadata on the transaction
362
+ # ```ruby
363
+ # Appsignal.monitor(
364
+ # :namespace => "my_namespace",
365
+ # :action => "MyClass#my_method"
366
+ # ) do
367
+ # # Some code
368
+ #
369
+ # Appsignal.add_tags(:tag1 => "value1", :tag2 => "value2")
370
+ # Appsignal.add_params(:param1 => "value1", :param2 => "value2")
371
+ # end
372
+ # ```
373
+ #
374
+ # Call monitor within monitor will do nothing
375
+ # ```ruby
376
+ # Appsignal.monitor(
377
+ # :namespace => "my_namespace",
378
+ # :action => "MyClass#my_method"
379
+ # ) do
380
+ # # This will _not_ update the namespace and action name
381
+ # Appsignal.monitor(
382
+ # :namespace => "my_other_namespace",
383
+ # :action => "MyOtherClass#my_other_method"
384
+ # ) do
385
+ # # Some code
386
+ #
387
+ # # The reported namespace will be "my_namespace"
388
+ # # The reported action will be "MyClass#my_method"
389
+ # end
390
+ # end
391
+ # ```
392
+ #
393
+ # _@see_ `https://docs.appsignal.com/ruby/instrumentation/background-jobs.html` — Monitor guide
394
+ sig { params(action: T.any(String, Symbol, NilClass), namespace: T.nilable(T.any(String, Symbol)), blk: T.proc.returns(Object)).returns(T.nilable(Object)) }
395
+ def self.monitor(action:, namespace: nil, &blk); end
396
+
397
+ # Instrument a block of code and stop AppSignal.
398
+ #
399
+ # Useful for cases such as one-off scripts where there is no long running
400
+ # process active and the data needs to be sent after the process exists.
401
+ #
402
+ # Acts the same way as {.monitor}. See that method for more
403
+ # documentation.
404
+ #
405
+ # _@param_ `namespace` — The namespace to set on the new transaction. Defaults to the 'web' namespace. This will not update the active transaction's namespace if {.monitor} is called when another transaction is already active.
406
+ #
407
+ # _@param_ `action` — The action name for the transaction. The action name is required to be set for the transaction to be reported. The argument can be set to `nil` or `:set_later` if the action is set within the block with {#set_action}. This will not update the active transaction's action if {.monitor} is called when another transaction is already active.
408
+ #
409
+ # _@return_ — The value of the given block is returned.
410
+ #
411
+ # _@see_ `monitor`
412
+ sig { params(action: T.any(String, Symbol, NilClass), namespace: T.nilable(T.any(String, Symbol)), block: T.proc.returns(Object)).returns(T.nilable(Object)) }
413
+ def self.monitor_and_stop(action:, namespace: nil, &block); end
414
+
415
+ # Send an error to AppSignal regardless of the context.
416
+ #
417
+ # **We recommend using the {#report_error} helper instead.**
418
+ #
419
+ # Records and send the exception to AppSignal.
420
+ #
421
+ # This instrumentation helper does not require a transaction to be
422
+ # active, it starts a new transaction by itself.
423
+ #
424
+ # Use {.set_error} if your want to add an exception to the current
425
+ # transaction.
426
+ #
427
+ # **Note**: Does not do anything if AppSignal is not active or when the
428
+ # "error" is not a class extended from Ruby's Exception class.
429
+ #
430
+ # _@param_ `error` — The error to send to AppSignal.
431
+ #
432
+ # Send an exception
433
+ # ```ruby
434
+ # begin
435
+ # raise "oh no!"
436
+ # rescue => e
437
+ # Appsignal.send_error(e)
438
+ # end
439
+ # ```
440
+ #
441
+ # Add more metadata to transaction
442
+ # ```ruby
443
+ # Appsignal.send_error(e) do
444
+ # Appsignal.set_namespace("my_namespace")
445
+ # Appsignal.set_action("my_action_name")
446
+ # Appsignal.add_params(:search_query => params[:search_query])
447
+ # Appsignal.add_tags(:key => "value")
448
+ # end
449
+ # ```
450
+ #
451
+ # _@see_ `https://docs.appsignal.com/ruby/instrumentation/exception-handling.html` — Exception handling guide
452
+ sig { params(error: Exception, block: T.proc.params(transaction: Transaction).void).void }
453
+ def self.send_error(error, &block); end
454
+
455
+ # Set an error on the current transaction.
456
+ #
457
+ # **We recommend using the {#report_error} helper instead.**
458
+ #
459
+ # **Note**: Does not do anything if AppSignal is not active, no
460
+ # transaction is currently active or when the "error" is not a class
461
+ # extended from Ruby's Exception class.
462
+ #
463
+ # _@param_ `exception` — The error to add to the current transaction.
464
+ #
465
+ # Manual instrumentation of set_error.
466
+ # ```ruby
467
+ # # Manually starting AppSignal here
468
+ # # Manually starting a transaction here.
469
+ # begin
470
+ # raise "oh no!"
471
+ # rescue => e
472
+ # Appsignal.set_error(e)
473
+ # end
474
+ # # Manually completing the transaction here.
475
+ # # Manually stopping AppSignal here
476
+ # ```
477
+ #
478
+ # In a Rails application
479
+ # ```ruby
480
+ # class SomeController < ApplicationController
481
+ # # The AppSignal transaction is created by our integration for you.
482
+ # def create
483
+ # # Do something that breaks
484
+ # rescue => e
485
+ # Appsignal.set_error(e)
486
+ # end
487
+ # end
488
+ # ```
489
+ #
490
+ # Add more metadata to transaction
491
+ # ```ruby
492
+ # Appsignal.set_error(e) do
493
+ # Appsignal.set_namespace("my_namespace")
494
+ # Appsignal.set_action("my_action_name")
495
+ # Appsignal.add_params(:search_query => params[:search_query])
496
+ # Appsignal.add_tags(:key => "value")
497
+ # end
498
+ # ```
499
+ #
500
+ # _@see_ `https://docs.appsignal.com/ruby/instrumentation/exception-handling.html` — Exception handling guide
501
+ sig { params(exception: Exception, blk: T.proc.params(transaction: Transaction).void).void }
502
+ def self.set_error(exception, &blk); end
503
+
504
+ # Report an error to AppSignal.
505
+ #
506
+ # If a transaction is currently active, it will report the error on the
507
+ # current transaction. If no transaction is active, it will report the
508
+ # error on a new transaction.
509
+ #
510
+ # If a transaction is active and the transaction already has an error
511
+ # reported on it, it will report multiple errors, up to a maximum of 10
512
+ # errors.
513
+ #
514
+ # If a block is given to this method, the metadata set in this block will
515
+ # only be applied to the transaction created for the given error. The
516
+ # block will be called when the transaction is completed, which can be
517
+ # much later than when {#report_error} is called.
518
+ #
519
+ # **Note**: If AppSignal is not active, no error is reported.
520
+ #
521
+ # **Note**: If the given exception argument is not an Exception subclass,
522
+ # it will not be reported.
523
+ #
524
+ # _@param_ `exception` — The error to add to the current transaction.
525
+ #
526
+ # ```ruby
527
+ # class SomeController < ApplicationController
528
+ # def create
529
+ # # Do something that breaks
530
+ # rescue => error
531
+ # Appsignal.report_error(error)
532
+ # end
533
+ # end
534
+ # ```
535
+ #
536
+ # Add more metadata to transaction
537
+ # ```ruby
538
+ # Appsignal.report_error(error) do
539
+ # Appsignal.set_namespace("my_namespace")
540
+ # Appsignal.set_action("my_action_name")
541
+ # Appsignal.add_params(:search_query => params[:search_query])
542
+ # Appsignal.add_tags(:key => "value")
543
+ # end
544
+ # ```
545
+ #
546
+ # _@see_ `https://docs.appsignal.com/ruby/instrumentation/exception-handling.html` — Exception handling guide
547
+ sig { params(exception: Exception, block: T.proc.params(transaction: Transaction).void).void }
548
+ def self.report_error(exception, &block); end
549
+
550
+ # Set a custom action name for the current transaction.
551
+ #
552
+ # When using an integration such as the Rails or Sinatra AppSignal will
553
+ # try to find the action name from the controller or endpoint for you.
554
+ #
555
+ # If you want to customize the action name as it appears on AppSignal.com
556
+ # you can use this method. This overrides the action name AppSignal
557
+ # generates in an integration.
558
+ #
559
+ # _@param_ `action`
560
+ #
561
+ # in a Rails controller
562
+ # ```ruby
563
+ # class SomeController < ApplicationController
564
+ # before_action :set_appsignal_action
565
+ #
566
+ # def set_appsignal_action
567
+ # Appsignal.set_action("DynamicController#dynamic_method")
568
+ # end
569
+ # end
570
+ # ```
571
+ sig { params(action: String).void }
572
+ def self.set_action(action); end
573
+
574
+ # Set a custom namespace for the current transaction.
575
+ #
576
+ # When using an integration such as Rails or Sidekiq AppSignal will try
577
+ # to find a appropriate namespace for the transaction.
578
+ #
579
+ # A Rails controller will be automatically put in the "http_request"
580
+ # namespace, while a Sidekiq background job is put in the
581
+ # "background_job" namespace.
582
+ #
583
+ # Note: The "http_request" namespace gets transformed on AppSignal.com to
584
+ # "Web" and "background_job" gets transformed to "Background".
585
+ #
586
+ # If you want to customize the namespace in which transactions appear you
587
+ # can use this method. This overrides the namespace AppSignal uses by
588
+ # default.
589
+ #
590
+ # A common request we've seen is to split the administration panel from
591
+ # the main application.
592
+ #
593
+ # _@param_ `namespace`
594
+ #
595
+ # create a custom admin namespace
596
+ # ```ruby
597
+ # class AdminController < ApplicationController
598
+ # before_action :set_appsignal_namespace
599
+ #
600
+ # def set_appsignal_namespace
601
+ # Appsignal.set_namespace("admin")
602
+ # end
603
+ # end
604
+ # ```
605
+ #
606
+ # _@see_ `https://docs.appsignal.com/guides/namespaces.html` — Grouping with namespaces guide
607
+ sig { params(namespace: String).void }
608
+ def self.set_namespace(namespace); end
609
+
610
+ # Add custom data to the current transaction.
611
+ #
612
+ # Add extra information about the request or background that cannot be
613
+ # expressed in tags, like nested data structures.
614
+ #
615
+ # If the root data type changes between calls of this method, the last
616
+ # method call is stored.
617
+ #
618
+ # _@param_ `data` — Custom data to add to the transaction.
619
+ #
620
+ # Add Hash data
621
+ # ```ruby
622
+ # Appsignal.add_custom_data(:user => { :locale => "en" })
623
+ # ```
624
+ #
625
+ # Merges Hash data
626
+ # ```ruby
627
+ # Appsignal.add_custom_data(:abc => "def")
628
+ # Appsignal.add_custom_data(:xyz => "...")
629
+ # # The custom data is: { :abc => "def", :xyz => "..." }
630
+ # ```
631
+ #
632
+ # Add Array data
633
+ # ```ruby
634
+ # Appsignal.add_custom_data([
635
+ # "array with data",
636
+ # "other value",
637
+ # :options => { :verbose => true }
638
+ # ])
639
+ # ```
640
+ #
641
+ # Merges Array data
642
+ # ```ruby
643
+ # Appsignal.add_custom_data([1, 2, 3])
644
+ # Appsignal.add_custom_data([4, 5, 6])
645
+ # # The custom data is: [1, 2, 3, 4, 5, 6]
646
+ # ```
647
+ #
648
+ # Mixing of root data types is not supported
649
+ # ```ruby
650
+ # Appsignal.add_custom_data(:abc => "def")
651
+ # Appsignal.add_custom_data([1, 2, 3])
652
+ # # The custom data is: [1, 2, 3]
653
+ # ```
654
+ #
655
+ # _@see_ `https://docs.appsignal.com/guides/custom-data/sample-data.html` — Sample data guide
656
+ sig { params(data: T.any(T::Hash[Object, Object], T::Array[Object])).void }
657
+ def self.add_custom_data(data); end
658
+
659
+ # Add tags to the current transaction.
660
+ #
661
+ # Tags are extra bits of information that are added to transaction and
662
+ # appear on sample details pages on AppSignal.com.
663
+ #
664
+ # When this method is called multiple times, it will merge the tags.
665
+ #
666
+ # _@param_ `tags` — Collection of tags to add to the transaction.
667
+ #
668
+ # ```ruby
669
+ # Appsignal.add_tags(:locale => "en", :user_id => 1)
670
+ # Appsignal.add_tags("locale" => "en")
671
+ # Appsignal.add_tags("user_id" => 1)
672
+ # ```
673
+ #
674
+ # Nested hashes are not supported
675
+ # ```ruby
676
+ # # Bad
677
+ # Appsignal.add_tags(:user => { :locale => "en" })
678
+ # ```
679
+ #
680
+ # in a Rails controller
681
+ # ```ruby
682
+ # class SomeController < ApplicationController
683
+ # before_action :add_appsignal_tags
684
+ #
685
+ # def add_appsignal_tags
686
+ # Appsignal.add_tags(:locale => I18n.locale)
687
+ # end
688
+ # end
689
+ # ```
690
+ #
691
+ # _@see_ `https://docs.appsignal.com/ruby/instrumentation/tagging.html` — Tagging guide
692
+ sig { params(tags: T::Hash[Object, Object]).void }
693
+ def self.add_tags(tags = {}); end
694
+
695
+ # Add parameters to the current transaction.
696
+ #
697
+ # Parameters are automatically added by most of our integrations. It
698
+ # should not be necessary to call this method unless you want to report
699
+ # different parameters.
700
+ #
701
+ # This method accepts both Hash and Array parameter types:
702
+ # - Hash parameters will be merged when called multiple times
703
+ # - Array parameters will be concatenated when called multiple times
704
+ # - Mixing Hash and Array types will use the latest type (and log a warning)
705
+ #
706
+ # To filter parameters, see our parameter filtering guide.
707
+ #
708
+ # When both the `params` argument and a block is given to this method,
709
+ # the block is leading and the argument will _not_ be used.
710
+ #
711
+ # _@param_ `params` — The parameters to add to the transaction.
712
+ #
713
+ # Add Hash parameters
714
+ # ```ruby
715
+ # Appsignal.add_params("param1" => "value1")
716
+ # # The parameters include: { "param1" => "value1" }
717
+ # ```
718
+ #
719
+ # Add Array parameters
720
+ # ```ruby
721
+ # Appsignal.add_params(["item1", "item2"])
722
+ # # The parameters include: ["item1", "item2"]
723
+ # ```
724
+ #
725
+ # Calling `add_params` multiple times with Hashes merges values
726
+ # ```ruby
727
+ # Appsignal.add_params("param1" => "value1")
728
+ # Appsignal.add_params("param2" => "value2")
729
+ # # The parameters include:
730
+ # # { "param1" => "value1", "param2" => "value2" }
731
+ # ```
732
+ #
733
+ # Calling `add_params` multiple times with Arrays concatenates values
734
+ # ```ruby
735
+ # Appsignal.add_params(["item1"])
736
+ # Appsignal.add_params(["item2"])
737
+ # # The parameters include: ["item1", "item2"]
738
+ # ```
739
+ #
740
+ # _@see_ `https://docs.appsignal.com/guides/custom-data/sample-data.html` — Sample data guide
741
+ #
742
+ # _@see_ `https://docs.appsignal.com/guides/filter-data/filter-parameters.html` — Parameter filtering guide
743
+ sig { params(params: T.nilable(T.any(T::Hash[String, Object], T::Array[Object])), block: T.proc.returns(T.any(T::Hash[String, Object], T::Array[Object]))).void }
744
+ def self.add_params(params = nil, &block); end
745
+
746
+ # Mark the parameters sample data to be set as an empty value.
747
+ #
748
+ # Use this helper to unset request parameters / background job arguments
749
+ # and not report any for this transaction.
750
+ #
751
+ # If parameters would normally be added by AppSignal instrumentations of
752
+ # libraries, these parameters will not be added to the Transaction.
753
+ #
754
+ # Calling {#add_params} after this helper will add new parameters to the
755
+ # transaction.
756
+ #
757
+ # _@see_ `Transaction#set_empty_params!`
758
+ #
759
+ # _@see_ `Transaction#set_params_if_nil`
760
+ sig { void }
761
+ def self.set_empty_params!; end
762
+
763
+ # Add session data to the current transaction.
764
+ #
765
+ # Session data is automatically added by most of our integrations. It
766
+ # should not be necessary to call this method unless you want to report
767
+ # different session data.
768
+ #
769
+ # To filter session data, see our session data filtering guide.
770
+ #
771
+ # When both the `session_data` argument and a block is given to this
772
+ # method, the bock is leading and the argument will _not_ be used.
773
+ #
774
+ # _@param_ `session_data` — The session data to add to the transaction.
775
+ #
776
+ # Add session data
777
+ # ```ruby
778
+ # Appsignal.add_session_data("session" => "data")
779
+ # # The session data will include:
780
+ # # { "session" => "data" }
781
+ # ```
782
+ #
783
+ # Calling `add_session_data` multiple times merge the values
784
+ # ```ruby
785
+ # Appsignal.add_session_data("session" => "data")
786
+ # Appsignal.add_session_data("other" => "value")
787
+ # # The session data will include:
788
+ # # { "session" => "data", "other" => "value" }
789
+ # ```
790
+ #
791
+ # _@see_ `https://docs.appsignal.com/guides/custom-data/sample-data.html` — Sample data guide
792
+ #
793
+ # _@see_ `https://docs.appsignal.com/guides/filter-data/filter-session-data.html` — Session data filtering guide
794
+ sig { params(session_data: T.nilable(T::Hash[String, Object]), block: T.proc.returns(T::Hash[String, Object])).void }
795
+ def self.add_session_data(session_data = nil, &block); end
796
+
797
+ # Add request headers to the current transaction.
798
+ #
799
+ # Request headers are automatically added by most of our integrations. It
800
+ # should not be necessary to call this method unless you want to also
801
+ # report different request headers.
802
+ #
803
+ # To filter request headers, see our request header filtering guide.
804
+ #
805
+ # When both the `request_headers` argument and a block is given to this
806
+ # method, the block is leading and the argument will _not_ be used.
807
+ #
808
+ # _@param_ `headers` — The request headers to add to the transaction.
809
+ #
810
+ # Add request headers
811
+ # ```ruby
812
+ # Appsignal.add_headers("PATH_INFO" => "/some-path")
813
+ # # The request headers will include:
814
+ # # { "PATH_INFO" => "/some-path" }
815
+ # ```
816
+ #
817
+ # Calling `add_headers` multiple times merge the values
818
+ # ```ruby
819
+ # Appsignal.add_headers("PATH_INFO" => "/some-path")
820
+ # Appsignal.add_headers("HTTP_USER_AGENT" => "Firefox")
821
+ # # The request headers will include:
822
+ # # { "PATH_INFO" => "/some-path", "HTTP_USER_AGENT" => "Firefox" }
823
+ # ```
824
+ #
825
+ # _@see_ `https://docs.appsignal.com/guides/custom-data/sample-data.html` — Sample data guide
826
+ #
827
+ # _@see_ `https://docs.appsignal.com/guides/filter-data/filter-headers.html` — Request headers filtering guide
828
+ sig { params(headers: T.nilable(T::Hash[String, Object]), block: T.proc.returns(T::Hash[String, Object])).void }
829
+ def self.add_headers(headers = nil, &block); end
830
+
831
+ # Add breadcrumbs to the transaction.
832
+ #
833
+ # Breadcrumbs can be used to trace what path a user has taken
834
+ # before encountering an error.
835
+ #
836
+ # Only the last 20 added breadcrumbs will be saved.
837
+ #
838
+ # _@param_ `category` — category of breadcrumb e.g. "UI", "Network", "Navigation", "Console".
839
+ #
840
+ # _@param_ `action` — name of breadcrumb e.g "The user clicked a button", "HTTP 500 from http://blablabla.com"
841
+ #
842
+ # _@param_ `message` — optional message in string format
843
+ #
844
+ # _@param_ `metadata` — key/value metadata in <string, string> format
845
+ #
846
+ # _@param_ `time` — time of breadcrumb, should respond to `.to_i` defaults to `Time.now.utc`
847
+ #
848
+ # ```ruby
849
+ # Appsignal.add_breadcrumb(
850
+ # "Navigation",
851
+ # "http://blablabla.com",
852
+ # "",
853
+ # { :response => 200 },
854
+ # Time.now.utc
855
+ # )
856
+ # Appsignal.add_breadcrumb(
857
+ # "Network",
858
+ # "[GET] http://blablabla.com",
859
+ # "",
860
+ # { :response => 500 }
861
+ # )
862
+ # Appsignal.add_breadcrumb(
863
+ # "UI",
864
+ # "closed modal(change_password)",
865
+ # "User closed modal without actions"
866
+ # )
867
+ # ```
868
+ #
869
+ # _@see_ `https://docs.appsignal.com/ruby/instrumentation/breadcrumbs.html` — Breadcrumb reference
870
+ sig do
871
+ params(
872
+ category: String,
873
+ action: String,
874
+ message: String,
875
+ metadata: T::Hash[String, String],
876
+ time: Time
877
+ ).void
878
+ end
879
+ def self.add_breadcrumb(category, action, message = "", metadata = {}, time = Time.now.utc); end
880
+
881
+ # Instrument helper for AppSignal.
882
+ #
883
+ # For more help, read our custom instrumentation guide, listed under "See
884
+ # also".
885
+ #
886
+ # _@param_ `name` — Name of the instrumented event. Read our event naming guide listed under "See also".
887
+ #
888
+ # _@param_ `title` — Human readable name of the event.
889
+ #
890
+ # _@param_ `body` — Value of importance for the event, such as the server against an API call is made.
891
+ #
892
+ # _@param_ `body_format` — Enum for the type of event that is instrumented. Accepted values are {EventFormatter::DEFAULT} and {EventFormatter::SQL_BODY_FORMAT}, but we recommend you use {.instrument_sql} instead of {EventFormatter::SQL_BODY_FORMAT}.
893
+ #
894
+ # _@return_ — Returns the block's return value.
895
+ #
896
+ # Simple instrumentation
897
+ # ```ruby
898
+ # Appsignal.instrument("fetch.issue_fetcher") do
899
+ # # To be instrumented code
900
+ # end
901
+ # ```
902
+ #
903
+ # Instrumentation with title and body
904
+ # ```ruby
905
+ # Appsignal.instrument(
906
+ # "fetch.issue_fetcher",
907
+ # "Fetching issue",
908
+ # "GitHub API"
909
+ # ) do
910
+ # # To be instrumented code
911
+ # end
912
+ # ```
913
+ #
914
+ # _@see_ `.instrument_sql`
915
+ #
916
+ # _@see_ `https://docs.appsignal.com/ruby/instrumentation/instrumentation.html` — AppSignal custom instrumentation guide
917
+ #
918
+ # _@see_ `https://docs.appsignal.com/api/event-names.html` — AppSignal event naming guide
919
+ sig do
920
+ params(
921
+ name: String,
922
+ title: T.nilable(String),
923
+ body: T.nilable(String),
924
+ body_format: Integer,
925
+ block: T.untyped
926
+ ).returns(Object)
927
+ end
928
+ def self.instrument(name, title = nil, body = nil, body_format = Appsignal::EventFormatter::DEFAULT, &block); end
929
+
930
+ # Instrumentation helper for SQL queries.
931
+ #
932
+ # This helper filters out values from SQL queries so you don't have to.
933
+ #
934
+ # _@param_ `name` — Name of the instrumented event. Read our event naming guide listed under "See also".
935
+ #
936
+ # _@param_ `title` — Human readable name of the event.
937
+ #
938
+ # _@param_ `body` — SQL query that's being executed.
939
+ #
940
+ # _@return_ — Returns the block's return value.
941
+ #
942
+ # SQL query instrumentation
943
+ # ```ruby
944
+ # body = "SELECT * FROM ..."
945
+ # Appsignal.instrument_sql("perform.query", nil, body) do
946
+ # # To be instrumented code
947
+ # end
948
+ # ```
949
+ #
950
+ # SQL query instrumentation
951
+ # ```ruby
952
+ # body = "WHERE email = 'foo@..'"
953
+ # Appsignal.instrument_sql("perform.query", nil, body) do
954
+ # # query value will replace 'foo..' with a question mark `?`.
955
+ # end
956
+ # ```
957
+ #
958
+ # _@see_ `.instrument`
959
+ #
960
+ # _@see_ `https://docs.appsignal.com/ruby/instrumentation/instrumentation.html` — AppSignal custom instrumentation guide
961
+ #
962
+ # _@see_ `https://docs.appsignal.com/api/event-names.html` — AppSignal event naming guide
963
+ sig do
964
+ params(
965
+ name: String,
966
+ title: T.nilable(String),
967
+ body: T.nilable(String),
968
+ block: T.untyped
969
+ ).returns(Object)
970
+ end
971
+ def self.instrument_sql(name, title = nil, body = nil, &block); end
972
+
973
+ # Convenience method for ignoring instrumentation events in a block of
974
+ # code.
975
+ #
976
+ # - This helper ignores events, like those created
977
+ # `Appsignal.instrument`, within this block.
978
+ # This includes custom instrumentation and events recorded by AppSignal
979
+ # integrations for requests, database queries, view rendering, etc.
980
+ # - The time spent in the block is still reported on the transaction.
981
+ # - Errors and metrics are reported from within this block.
982
+ #
983
+ # _@return_ — Returns the return value of the block.
984
+ # Return nil if the block returns nil or no block is given.
985
+ #
986
+ # ```ruby
987
+ # Appsignal.instrument "my_event.my_group" do
988
+ # # Complex code here
989
+ # end
990
+ # Appsignal.ignore_instrumentation_events do
991
+ # Appsignal.instrument "my_ignored_event.my_ignored_group" do
992
+ # # Complex code here
993
+ # end
994
+ # end
995
+ #
996
+ # # Only the "my_event.my_group" instrumentation event is reported.
997
+ # ```
998
+ #
999
+ # _@see_ `https://docs.appsignal.com/ruby/instrumentation/ignore-instrumentation.html` — Ignore instrumentation guide
1000
+ sig { params(blk: T.proc.returns(Object)).returns(T.nilable(Object)) }
1001
+ def self.ignore_instrumentation_events(&blk); end
1002
+
1003
+ # {Appsignal::Demo} is a way to send demonstration / test samples for a
1004
+ # exception and a performance issue.
1005
+ #
1006
+ # @example Send example transactions
1007
+ # Appsignal::Demo.transmit
1008
+ #
1009
+ # @since 2.0.0
1010
+ # @see Appsignal::CLI::Demo
1011
+ # @api private
1012
+ class Demo
1013
+ # Starts AppSignal and transmits the demonstration samples to AppSignal
1014
+ # using the loaded configuration.
1015
+ #
1016
+ # _@return_ — - returns `false` if Appsignal is not active.
1017
+ sig { returns(T::Boolean) }
1018
+ def self.transmit; end
1019
+
1020
+ # Error type used to create demonstration exception.
1021
+ class TestError < StandardError
1022
+ end
1023
+ end
1024
+
1025
+ class Config
1026
+ # Check if the configuration is valid.
1027
+ #
1028
+ # _@return_ — True if the configuration is valid, false otherwise.
1029
+ sig { returns(T::Boolean) }
1030
+ def valid?; end
1031
+
1032
+ # Check if AppSignal is active for the current environment.
1033
+ #
1034
+ # _@return_ — True if active for the current environment.
1035
+ sig { returns(T::Boolean) }
1036
+ def active_for_env?; end
1037
+
1038
+ # Check if AppSignal is active.
1039
+ #
1040
+ # _@return_ — True if valid and active for the current environment.
1041
+ sig { returns(T::Boolean) }
1042
+ def active?; end
1043
+
1044
+ sig { returns(T::Boolean) }
1045
+ def yml_config_file?; end
1046
+
1047
+ # Configuration DSL for use in configuration blocks.
1048
+ #
1049
+ # This class provides a Domain Specific Language for configuring AppSignal
1050
+ # within the `Appsignal.configure` block. It provides getter and setter
1051
+ # methods for all configuration options.
1052
+ #
1053
+ # @example Using the configuration DSL
1054
+ # Appsignal.configure do |config|
1055
+ # config.name = "My App"
1056
+ # config.active = true
1057
+ # config.push_api_key = "your-api-key"
1058
+ # config.ignore_actions = ["StatusController#health"]
1059
+ # end
1060
+ #
1061
+ # @see AppSignal Ruby gem configuration
1062
+ # https://docs.appsignal.com/ruby/configuration.html
1063
+ class ConfigDSL
1064
+ # Returns the application's root path.
1065
+ #
1066
+ # _@return_ — The root path of the application
1067
+ sig { returns(String) }
1068
+ def app_path; end
1069
+
1070
+ # Returns the current environment name.
1071
+ #
1072
+ # _@return_ — The environment name (e.g., "production", "development")
1073
+ sig { returns(String) }
1074
+ def env; end
1075
+
1076
+ # Returns true if the given environment name matches the loaded
1077
+ # environment name.
1078
+ #
1079
+ # _@param_ `given_env`
1080
+ sig { params(given_env: T.any(String, Symbol)).returns(T.any(TrueClass, FalseClass)) }
1081
+ def env?(given_env); end
1082
+
1083
+ # Activates AppSignal if the current environment matches any of the given environments.
1084
+ #
1085
+ # _@param_ `envs` — List of environment names to activate for
1086
+ #
1087
+ # _@return_ — true if AppSignal was activated, false otherwise
1088
+ #
1089
+ # Activate for production and staging
1090
+ # ```ruby
1091
+ # config.activate_if_environment(:production, :staging)
1092
+ # ```
1093
+ sig { params(envs: T::Array[T.any(String, Symbol)]).returns(T::Boolean) }
1094
+ def activate_if_environment(*envs); end
1095
+
1096
+ # _@return_ — Error reporting mode for ActiveJob ("all", "discard" or "none")
1097
+ sig { returns(String) }
1098
+ attr_accessor :activejob_report_errors
1099
+
1100
+ # _@return_ — The application name
1101
+ sig { returns(String) }
1102
+ attr_accessor :name
1103
+
1104
+ # _@return_ — The host to the agent binds to for its HTTP server
1105
+ sig { returns(String) }
1106
+ attr_accessor :bind_address
1107
+
1108
+ # _@return_ — Path to the CA certificate file
1109
+ sig { returns(String) }
1110
+ attr_accessor :ca_file_path
1111
+
1112
+ # _@return_ — Override for the detected hostname
1113
+ sig { returns(String) }
1114
+ attr_accessor :hostname
1115
+
1116
+ # _@return_ — Role of the host for grouping in metrics
1117
+ sig { returns(String) }
1118
+ attr_accessor :host_role
1119
+
1120
+ # _@return_ — HTTP proxy URL
1121
+ sig { returns(String) }
1122
+ attr_accessor :http_proxy
1123
+
1124
+ # _@return_ — Log destination ("file" or "stdout")
1125
+ sig { returns(String) }
1126
+ attr_accessor :log
1127
+
1128
+ # _@return_ — AppSignal internal logger
1129
+ # log level ("error", "warn", "info", "debug", "trace")
1130
+ sig { returns(String) }
1131
+ attr_accessor :log_level
1132
+
1133
+ # _@return_ — Path to the log directory
1134
+ sig { returns(String) }
1135
+ attr_accessor :log_path
1136
+
1137
+ # _@return_ — Endpoint for log transmission
1138
+ sig { returns(String) }
1139
+ attr_accessor :logging_endpoint
1140
+
1141
+ # _@return_ — Push API endpoint URL
1142
+ sig { returns(String) }
1143
+ attr_accessor :endpoint
1144
+
1145
+ # _@return_ — AppSignal Push API key
1146
+ sig { returns(String) }
1147
+ attr_accessor :push_api_key
1148
+
1149
+ # _@return_ — Error reporting mode for Sidekiq ("all", "discard" or "none")
1150
+ sig { returns(String) }
1151
+ attr_accessor :sidekiq_report_errors
1152
+
1153
+ # _@return_ — Port for StatsD metrics
1154
+ sig { returns(String) }
1155
+ attr_accessor :statsd_port
1156
+
1157
+ # _@return_ — Port for Nginx metrics collection
1158
+ sig { returns(String) }
1159
+ attr_accessor :nginx_port
1160
+
1161
+ # _@return_ — Override for the agent working directory
1162
+ sig { returns(String) }
1163
+ attr_accessor :working_directory_path
1164
+
1165
+ # _@return_ — Application revision identifier
1166
+ sig { returns(String) }
1167
+ attr_accessor :revision
1168
+
1169
+ # _@return_ — Activate AppSignal for the loaded environment
1170
+ sig { returns(T::Boolean) }
1171
+ attr_accessor :active
1172
+
1173
+ # _@return_ — Configure whether allocation tracking is enabled
1174
+ sig { returns(T::Boolean) }
1175
+ attr_accessor :enable_allocation_tracking
1176
+
1177
+ # _@return_ — Configure whether the at_exit reporter is enabled
1178
+ sig { returns(T::Boolean) }
1179
+ attr_accessor :enable_at_exit_reporter
1180
+
1181
+ # _@return_ — Configure whether host metrics collection is enabled
1182
+ sig { returns(T::Boolean) }
1183
+ attr_accessor :enable_host_metrics
1184
+
1185
+ # _@return_ — Configure whether minutely probes are enabled
1186
+ sig { returns(T::Boolean) }
1187
+ attr_accessor :enable_minutely_probes
1188
+
1189
+ # _@return_ — Configure whether the StatsD metrics endpoint on the agent is enabled
1190
+ sig { returns(T::Boolean) }
1191
+ attr_accessor :enable_statsd
1192
+
1193
+ # _@return_ — Configure whether the agent's NGINX metrics endpoint is enabled
1194
+ sig { returns(T::Boolean) }
1195
+ attr_accessor :enable_nginx_metrics
1196
+
1197
+ # _@return_ — Configure whether the GVL global timer instrumentationis enabled
1198
+ sig { returns(T::Boolean) }
1199
+ attr_accessor :enable_gvl_global_timer
1200
+
1201
+ # _@return_ — Configure whether GVL waiting threads instrumentation is enabled
1202
+ sig { returns(T::Boolean) }
1203
+ attr_accessor :enable_gvl_waiting_threads
1204
+
1205
+ # _@return_ — Configure whether Rails error reporter integration is enabled
1206
+ sig { returns(T::Boolean) }
1207
+ attr_accessor :enable_rails_error_reporter
1208
+
1209
+ # _@return_ — Configure whether Rake performance instrumentation is enabled
1210
+ sig { returns(T::Boolean) }
1211
+ attr_accessor :enable_rake_performance_instrumentation
1212
+
1213
+ # _@return_ — Configure whether files created by AppSignal should be world accessible
1214
+ sig { returns(T::Boolean) }
1215
+ attr_accessor :files_world_accessible
1216
+
1217
+ # _@return_ — Configure whether to instrument requests made with the http.rb gem
1218
+ sig { returns(T::Boolean) }
1219
+ attr_accessor :instrument_http_rb
1220
+
1221
+ # _@return_ — Configure whether to instrument requests made with Net::HTTP
1222
+ sig { returns(T::Boolean) }
1223
+ attr_accessor :instrument_net_http
1224
+
1225
+ # _@return_ — Configure whether to instrument the Ownership gem
1226
+ sig { returns(T::Boolean) }
1227
+ attr_accessor :instrument_ownership
1228
+
1229
+ # _@return_ — Configure whether to instrument Redis queries
1230
+ sig { returns(T::Boolean) }
1231
+ attr_accessor :instrument_redis
1232
+
1233
+ # _@return_ — Configure whether to instrument Sequel queries
1234
+ sig { returns(T::Boolean) }
1235
+ attr_accessor :instrument_sequel
1236
+
1237
+ # _@return_ — Configure whether the Ownership gem instrumentation should set namespace
1238
+ sig { returns(T::Boolean) }
1239
+ attr_accessor :ownership_set_namespace
1240
+
1241
+ # _@return_ — Configure whether the application is running in a container
1242
+ sig { returns(T::Boolean) }
1243
+ attr_accessor :running_in_container
1244
+
1245
+ # _@return_ — Configure whether to send environment metadata
1246
+ sig { returns(T::Boolean) }
1247
+ attr_accessor :send_environment_metadata
1248
+
1249
+ # _@return_ — Configure whether to send request parameters
1250
+ sig { returns(T::Boolean) }
1251
+ attr_accessor :send_params
1252
+
1253
+ # _@return_ — Configure whether to send request session data
1254
+ sig { returns(T::Boolean) }
1255
+ attr_accessor :send_session_data
1256
+
1257
+ # _@return_ — Custom DNS servers to use
1258
+ sig { returns(T::Array[String]) }
1259
+ attr_accessor :dns_servers
1260
+
1261
+ # _@return_ — Metadata keys to filter from trace data
1262
+ sig { returns(T::Array[String]) }
1263
+ attr_accessor :filter_metadata
1264
+
1265
+ # _@return_ — Keys of parameter to filter
1266
+ sig { returns(T::Array[String]) }
1267
+ attr_accessor :filter_parameters
1268
+
1269
+ # _@return_ — Request session data keys to filter
1270
+ sig { returns(T::Array[String]) }
1271
+ attr_accessor :filter_session_data
1272
+
1273
+ # _@return_ — Ignore traces by action names
1274
+ sig { returns(T::Array[String]) }
1275
+ attr_accessor :ignore_actions
1276
+
1277
+ # _@return_ — List of errors to not report
1278
+ sig { returns(T::Array[String]) }
1279
+ attr_accessor :ignore_errors
1280
+
1281
+ # _@return_ — Ignore log messages by substrings
1282
+ sig { returns(T::Array[String]) }
1283
+ attr_accessor :ignore_logs
1284
+
1285
+ # _@return_ — Ignore traces by namespaces
1286
+ sig { returns(T::Array[String]) }
1287
+ attr_accessor :ignore_namespaces
1288
+
1289
+ # _@return_ — HTTP request headers to include in error reports
1290
+ sig { returns(T::Array[String]) }
1291
+ attr_accessor :request_headers
1292
+
1293
+ # _@return_ — CPU count override for metrics collection
1294
+ sig { returns(Float) }
1295
+ attr_accessor :cpu_count
1296
+ end
1297
+ end
1298
+
1299
+ # Logger that flushes logs to the AppSignal logging service.
1300
+ #
1301
+ # @see https://docs.appsignal.com/logging/platforms/integrations/ruby.html
1302
+ # AppSignal Ruby logging documentation.
1303
+ class Logger < ::Logger
1304
+ # Create a new logger instance
1305
+ #
1306
+ # _@param_ `group` — Name of the group for this logger.
1307
+ #
1308
+ # _@param_ `level` — Minimum log level to report. Log lines below this level will be ignored.
1309
+ #
1310
+ # _@param_ `format` — Format to use to parse log line attributes.
1311
+ #
1312
+ # _@param_ `attributes` — Default attributes for all log lines.
1313
+ sig do
1314
+ params(
1315
+ group: String,
1316
+ level: Integer,
1317
+ format: Integer,
1318
+ attributes: T::Hash[String, String]
1319
+ ).void
1320
+ end
1321
+ def initialize(group, level: INFO, format: PLAINTEXT, attributes: {}); end
1322
+
1323
+ # Sets the formatter for this logger and all broadcasted loggers.
1324
+ #
1325
+ # _@param_ `formatter` — The formatter to use for log messages.
1326
+ sig { params(formatter: Proc).returns(Proc) }
1327
+ def formatter=(formatter); end
1328
+
1329
+ # Log a debug level message
1330
+ #
1331
+ # _@param_ `message` — Message to log
1332
+ #
1333
+ # _@param_ `attributes` — Attributes to tag the log with
1334
+ sig { params(message: T.nilable(String), attributes: T::Hash[String, Object], block: T.untyped).void }
1335
+ def debug(message = nil, attributes = {}, &block); end
1336
+
1337
+ # Log an info level message
1338
+ #
1339
+ # _@param_ `message` — Message to log
1340
+ #
1341
+ # _@param_ `attributes` — Attributes to tag the log with
1342
+ sig { params(message: T.nilable(String), attributes: T::Hash[String, Object], block: T.untyped).void }
1343
+ def info(message = nil, attributes = {}, &block); end
1344
+
1345
+ # Log a warn level message
1346
+ #
1347
+ # _@param_ `message` — Message to log
1348
+ #
1349
+ # _@param_ `attributes` — Attributes to tag the log with
1350
+ sig { params(message: T.nilable(String), attributes: T::Hash[String, Object], block: T.untyped).void }
1351
+ def warn(message = nil, attributes = {}, &block); end
1352
+
1353
+ # Log an error level message
1354
+ #
1355
+ # _@param_ `message` — Message to log
1356
+ #
1357
+ # _@param_ `attributes` — Attributes to tag the log with
1358
+ sig { params(message: T.nilable(T.any(String, Exception)), attributes: T::Hash[String, Object], block: T.untyped).void }
1359
+ def error(message = nil, attributes = {}, &block); end
1360
+
1361
+ # Log a fatal level message
1362
+ #
1363
+ # _@param_ `message` — Message to log
1364
+ #
1365
+ # _@param_ `attributes` — Attributes to tag the log with
1366
+ sig { params(message: T.nilable(T.any(String, Exception)), attributes: T::Hash[String, Object], block: T.untyped).void }
1367
+ def fatal(message = nil, attributes = {}, &block); end
1368
+
1369
+ # Log an info level message
1370
+ #
1371
+ # Returns the number of characters written.
1372
+ #
1373
+ # _@param_ `message` — Message to log
1374
+ sig { params(message: String).returns(Integer) }
1375
+ def <<(message); end
1376
+
1377
+ # Temporarily silences the logger to a specified level while executing a block.
1378
+ #
1379
+ # When using ActiveSupport::TaggedLogging without the broadcast feature,
1380
+ # the passed logger is required to respond to the `silence` method.
1381
+ #
1382
+ # Reference links:
1383
+ #
1384
+ # - https://github.com/rails/rails/blob/e11ebc04cfbe41c06cdfb70ee5a9fdbbd98bb263/activesupport/lib/active_support/logger.rb#L60-L76
1385
+ # - https://github.com/rails/rails/blob/e11ebc04cfbe41c06cdfb70ee5a9fdbbd98bb263/activesupport/lib/active_support/logger_silence.rb
1386
+ #
1387
+ # _@param_ `severity` — The minimum severity level to log during the block.
1388
+ #
1389
+ # _@return_ — The return value of the block.
1390
+ sig { params(severity: Integer, block: T.untyped).returns(Object) }
1391
+ def silence(severity = ERROR, &block); end
1392
+
1393
+ # Adds a logger to broadcast log messages to.
1394
+ #
1395
+ # _@param_ `logger` — The logger to add to the broadcast list.
1396
+ sig { params(logger: Logger).returns(T::Array[Logger]) }
1397
+ def broadcast_to(logger); end
1398
+
1399
+ # Logging severity threshold
1400
+ sig { returns(Integer) }
1401
+ attr_reader :level
1402
+ end
1403
+
1404
+ module Probes
1405
+ # Register a new minutely probe.
1406
+ #
1407
+ # Supported probe types are:
1408
+ #
1409
+ # - Lambda - A lambda is an object that listens to a `call` method call.
1410
+ # This `call` method is called every minute.
1411
+ # - Class - A class object is an object that listens to a `new` and
1412
+ # `call` method call. The `new` method is called when the minutely
1413
+ # probe thread is started to initialize all probes. This allows probes
1414
+ # to load dependencies once beforehand. Their `call` method is called
1415
+ # every minute.
1416
+ # - Class instance - A class instance object is an object that listens to
1417
+ # a `call` method call. The `call` method is called every minute.
1418
+ #
1419
+ # _@param_ `name` — Name of the probe. Can be used with {ProbeCollection#[]}. This name will be used in errors in the log and allows overwriting of probes by registering new ones with the same name.
1420
+ #
1421
+ # _@param_ `probe` — Any object that listens to the `call` method will be used as a probe.
1422
+ #
1423
+ # Register a new probe
1424
+ # ```ruby
1425
+ # Appsignal::Probes.register :my_probe, lambda {}
1426
+ # ```
1427
+ #
1428
+ # Overwrite an existing registered probe
1429
+ # ```ruby
1430
+ # Appsignal::Probes.register :my_probe, lambda {}
1431
+ # Appsignal::Probes.register :my_probe, lambda { puts "hello" }
1432
+ # ```
1433
+ #
1434
+ # Add a lambda as a probe
1435
+ # ```ruby
1436
+ # Appsignal::Probes.register :my_probe, lambda { puts "hello" }
1437
+ # # "hello" # printed every minute
1438
+ # ```
1439
+ #
1440
+ # Add a probe instance
1441
+ # ```ruby
1442
+ # class MyProbe
1443
+ # def initialize
1444
+ # puts "started"
1445
+ # end
1446
+ #
1447
+ # def call
1448
+ # puts "called"
1449
+ # end
1450
+ # end
1451
+ #
1452
+ # Appsignal::Probes.register :my_probe, MyProbe.new
1453
+ # # "started" # printed immediately
1454
+ # # "called" # printed every minute
1455
+ # ```
1456
+ #
1457
+ # Add a probe class
1458
+ # ```ruby
1459
+ # class MyProbe
1460
+ # def initialize
1461
+ # # Add things that only need to be done on start up for this probe
1462
+ # require "some/library/dependency"
1463
+ # @cache = {} # initialize a local cache variable
1464
+ # puts "started"
1465
+ # end
1466
+ #
1467
+ # def call
1468
+ # puts "called"
1469
+ # end
1470
+ # end
1471
+ #
1472
+ # Appsignal::Probes.register :my_probe, MyProbe
1473
+ # Appsignal::Probes.start # This is called for you
1474
+ # # "started" # Printed on Appsignal::Probes.start
1475
+ # # "called" # Repeated every minute
1476
+ # ```
1477
+ sig { params(name: T.any(Symbol, String), probe: Object).void }
1478
+ def self.register(name, probe); end
1479
+
1480
+ # Unregister a probe that's registered with {register}.
1481
+ # Can also be used to unregister automatically registered probes by the
1482
+ # gem.
1483
+ #
1484
+ # _@param_ `name` — Name of the probe used to {register} the probe.
1485
+ #
1486
+ # Unregister probes
1487
+ # ```ruby
1488
+ # # First register a probe
1489
+ # Appsignal::Probes.register :my_probe, lambda {}
1490
+ #
1491
+ # # Then unregister a probe if needed
1492
+ # Appsignal::Probes.unregister :my_probe
1493
+ # ```
1494
+ sig { params(name: T.any(Symbol, String)).void }
1495
+ def self.unregister(name); end
1496
+
1497
+ sig { void }
1498
+ def self.start; end
1499
+
1500
+ # Returns if the probes thread has been started. If the value is false or
1501
+ # nil, it has not been started yet.
1502
+ sig { returns(T.nilable(T::Boolean)) }
1503
+ def self.started?; end
1504
+
1505
+ # Stop the minutely probes mechanism. Stop the thread and clear all probe
1506
+ # instances.
1507
+ sig { void }
1508
+ def self.stop; end
1509
+ end
1510
+
1511
+ module CheckIn
1512
+ # Track cron check-ins.
1513
+ #
1514
+ # Track the execution of scheduled processes by sending a cron check-in.
1515
+ #
1516
+ # To track the duration of a piece of code, pass a block to {.cron}
1517
+ # to report both when the process starts, and when it finishes.
1518
+ #
1519
+ # If an exception is raised within the block, the finish event will not
1520
+ # be reported, triggering a notification about the missing cron check-in.
1521
+ # The exception will bubble outside of the cron check-in block.
1522
+ #
1523
+ # _@param_ `identifier` — identifier of the cron check-in to report.
1524
+ #
1525
+ # _@return_ — returns the block value.
1526
+ #
1527
+ # Send a cron check-in
1528
+ # ```ruby
1529
+ # Appsignal::CheckIn.cron("send_invoices")
1530
+ # ```
1531
+ #
1532
+ # Send a cron check-in with duration
1533
+ # ```ruby
1534
+ # Appsignal::CheckIn.cron("send_invoices") do
1535
+ # # your code
1536
+ # end
1537
+ # ```
1538
+ #
1539
+ # _@see_ `https://docs.appsignal.com/check-ins/cron`
1540
+ sig { params(identifier: String, blk: T.proc.returns(Object)).returns(Object) }
1541
+ def self.cron(identifier, &blk); end
1542
+
1543
+ # Track heartbeat check-ins.
1544
+ #
1545
+ # Track the execution of long-lived processes by sending a heartbeat
1546
+ # check-in.
1547
+ #
1548
+ # _@param_ `identifier` — identifier of the heartbeat check-in to report.
1549
+ #
1550
+ # _@param_ `continuous` — whether the heartbeats should be sent continuously during the lifetime of the process. Defaults to `false`.
1551
+ #
1552
+ # Send a heartbeat check-in
1553
+ # ```ruby
1554
+ # Appsignal::CheckIn.heartbeat("main_loop")
1555
+ # ```
1556
+ #
1557
+ # _@see_ `https://docs.appsignal.com/check-ins/heartbeat`
1558
+ sig { params(identifier: String, continuous: T::Boolean).void }
1559
+ def self.heartbeat(identifier, continuous: false); end
1560
+ end
1561
+
1562
+ class Transaction
1563
+ HTTP_REQUEST = T.let("http_request", T.untyped)
1564
+ BACKGROUND_JOB = T.let("background_job", T.untyped)
1565
+
1566
+ # Create a new transaction and set it as the currently active
1567
+ # transaction.
1568
+ #
1569
+ # _@param_ `namespace` — Namespace of the to be created transaction.
1570
+ sig { params(namespace: String).returns(Transaction) }
1571
+ def self.create(namespace); end
1572
+
1573
+ # Returns currently active transaction or a {NilTransaction} if none is
1574
+ # active.
1575
+ #
1576
+ # _@see_ `.current?`
1577
+ sig { returns(T.any(Appsignal::Transaction, Appsignal::Transaction::NilTransaction)) }
1578
+ def self.current; end
1579
+
1580
+ # Returns if any transaction is currently active or not. A
1581
+ # {NilTransaction} is not considered an active transaction.
1582
+ #
1583
+ # _@see_ `.current`
1584
+ sig { returns(T::Boolean) }
1585
+ def self.current?; end
1586
+
1587
+ # Complete the currently active transaction and unset it as the active
1588
+ # transaction.
1589
+ sig { void }
1590
+ def self.complete_current!; end
1591
+
1592
+ # Add parameters to the transaction.
1593
+ #
1594
+ # When this method is called multiple times, it will merge the request parameters.
1595
+ #
1596
+ # When both the `given_params` and a block is given to this method, the
1597
+ # block is leading and the argument will _not_ be used.
1598
+ #
1599
+ # _@param_ `given_params` — The parameters to set on the transaction.
1600
+ #
1601
+ # _@see_ `Helpers::Instrumentation#add_params`
1602
+ #
1603
+ # _@see_ `https://docs.appsignal.com/guides/custom-data/sample-data.html` — Sample data guide
1604
+ sig { params(given_params: T.nilable(T.any(T::Hash[String, Object], T::Array[Object])), block: T.proc.returns(T.any(T::Hash[String, Object], T::Array[Object]))).void }
1605
+ def add_params(given_params = nil, &block); end
1606
+
1607
+ # Add tags to the transaction.
1608
+ #
1609
+ # When this method is called multiple times, it will merge the tags.
1610
+ #
1611
+ # _@param_ `given_tags` — Collection of tags.
1612
+ #
1613
+ # _@see_ `Helpers::Instrumentation#add_tags`
1614
+ #
1615
+ # _@see_ `https://docs.appsignal.com/ruby/instrumentation/tagging.html` — Tagging guide
1616
+ sig { params(given_tags: T::Hash[String, Object]).void }
1617
+ def add_tags(given_tags = {}); end
1618
+
1619
+ # Add session data to the transaction.
1620
+ #
1621
+ # When this method is called multiple times, it will merge the session data.
1622
+ #
1623
+ # When both the `given_session_data` and a block is given to this method,
1624
+ # the block is leading and the argument will _not_ be used.
1625
+ #
1626
+ # _@param_ `given_session_data` — A hash containing session data.
1627
+ #
1628
+ # _@see_ `Helpers::Instrumentation#add_session_data`
1629
+ #
1630
+ # _@see_ `https://docs.appsignal.com/guides/custom-data/sample-data.html` — Sample data guide
1631
+ sig { params(given_session_data: T.nilable(T::Hash[String, Object]), block: T.proc.returns(T::Hash[String, Object])).void }
1632
+ def add_session_data(given_session_data = nil, &block); end
1633
+
1634
+ # Add headers to the transaction.
1635
+ #
1636
+ # _@param_ `given_headers` — A hash containing headers.
1637
+ #
1638
+ # _@see_ `Helpers::Instrumentation#add_headers`
1639
+ #
1640
+ # _@see_ `https://docs.appsignal.com/guides/custom-data/sample-data.html` — Sample data guide
1641
+ sig { params(given_headers: T.nilable(T::Hash[String, Object]), block: T.proc.returns(T::Hash[String, Object])).void }
1642
+ def add_headers(given_headers = nil, &block); end
1643
+
1644
+ # Add custom data to the transaction.
1645
+ #
1646
+ # _@param_ `data` — Custom data to add to the transaction.
1647
+ #
1648
+ # _@see_ `Helpers::Instrumentation#add_custom_data`
1649
+ #
1650
+ # _@see_ `https://docs.appsignal.com/guides/custom-data/sample-data.html` — Sample data guide
1651
+ sig { params(data: T.any(T::Hash[Object, Object], T::Array[Object])).void }
1652
+ def add_custom_data(data); end
1653
+
1654
+ # Add breadcrumbs to the transaction.
1655
+ #
1656
+ # _@param_ `category` — category of breadcrumb e.g. "UI", "Network", "Navigation", "Console".
1657
+ #
1658
+ # _@param_ `action` — name of breadcrumb e.g "The user clicked a button", "HTTP 500 from http://blablabla.com"
1659
+ #
1660
+ # _@param_ `message` — optional message in string format
1661
+ #
1662
+ # _@param_ `metadata` — key/value metadata in <string, string> format
1663
+ #
1664
+ # _@param_ `time` — time of breadcrumb, should respond to `.to_i` defaults to `Time.now.utc`
1665
+ #
1666
+ # _@see_ `Appsignal.add_breadcrumb`
1667
+ #
1668
+ # _@see_ `https://docs.appsignal.com/ruby/instrumentation/breadcrumbs.html` — Breadcrumb reference
1669
+ sig do
1670
+ params(
1671
+ category: String,
1672
+ action: String,
1673
+ message: String,
1674
+ metadata: T::Hash[String, String],
1675
+ time: Time
1676
+ ).void
1677
+ end
1678
+ def add_breadcrumb(category, action, message = "", metadata = {}, time = Time.now.utc); end
1679
+
1680
+ # Set an action name for the transaction.
1681
+ #
1682
+ # An action name is used to identify the location of a certain sample;
1683
+ # error and performance issues.
1684
+ #
1685
+ # _@param_ `action` — the action name to set.
1686
+ #
1687
+ # _@see_ `Appsignal::Helpers::Instrumentation#set_action`
1688
+ sig { params(action: String).void }
1689
+ def set_action(action); end
1690
+
1691
+ # Set the namespace for this transaction.
1692
+ #
1693
+ # Useful to split up parts of an application into certain namespaces. For
1694
+ # example: http requests, background jobs and administration panel
1695
+ # controllers.
1696
+ #
1697
+ # Note: The "http_request" namespace gets transformed on AppSignal.com to
1698
+ # "Web" and "background_job" gets transformed to "Background".
1699
+ #
1700
+ # _@param_ `namespace` — namespace name to use for this transaction.
1701
+ #
1702
+ # ```ruby
1703
+ # transaction.set_namespace("background")
1704
+ # ```
1705
+ #
1706
+ # _@see_ `Appsignal::Helpers::Instrumentation#set_namespace`
1707
+ #
1708
+ # _@see_ `https://docs.appsignal.com/guides/namespaces.html` — Grouping with namespaces guide
1709
+ sig { params(namespace: String).void }
1710
+ def set_namespace(namespace); end
1711
+
1712
+ # Set queue start time for transaction.
1713
+ #
1714
+ # _@param_ `start` — Queue start time in milliseconds.
1715
+ sig { params(start: Integer).void }
1716
+ def set_queue_start(start); end
1717
+ end
1718
+
1719
+ # Custom markers are used on AppSignal.com to indicate events in an
1720
+ # application, to give additional context on graph timelines.
1721
+ #
1722
+ # This helper class will send a request to the AppSignal public endpoint to
1723
+ # create a Custom marker for the application on AppSignal.com.
1724
+ #
1725
+ # @see https://docs.appsignal.com/api/public-endpoint/custom-markers.html
1726
+ # Public Endpoint API markers endpoint documentation
1727
+ # @see https://docs.appsignal.com/appsignal/terminology.html#markers
1728
+ # Terminology: Markers
1729
+ class CustomMarker
1730
+ # _@param_ `icon` — icon to use for the marker, like an emoji.
1731
+ #
1732
+ # _@param_ `message` — name of the user that is creating the marker.
1733
+ #
1734
+ # _@param_ `created_at` — A Ruby time object or a valid ISO8601 timestamp.
1735
+ sig { params(icon: T.nilable(String), message: T.nilable(String), created_at: T.nilable(T.any(Time, String))).returns(T::Boolean) }
1736
+ def self.report(icon: nil, message: nil, created_at: nil); end
1737
+ end
1738
+
1739
+ # Keeps track of formatters for types event that we can use to get
1740
+ # the title and body of an event. Formatters should inherit from this class
1741
+ # and implement a format(payload) method which returns an array with the title
1742
+ # and body.
1743
+ #
1744
+ # When implementing a formatter remember that it cannot keep separate state per
1745
+ # event, the same object will be called intermittently in a threaded environment.
1746
+ # So only keep global configuration as state and pass the payload around as an
1747
+ # argument if you need to use helper methods.
1748
+ class EventFormatter
1749
+ DEFAULT = T.let(0, T.untyped)
1750
+ SQL_BODY_FORMAT = T.let(1, T.untyped)
1751
+
1752
+ # Registers an event formatter for a specific event name.
1753
+ #
1754
+ # _@param_ `name` — The name of the event to register the formatter for.
1755
+ #
1756
+ # _@param_ `formatter` — The formatter class that implements the `format(payload)` method.
1757
+ #
1758
+ # Register a custom formatter
1759
+ # ```ruby
1760
+ # class CustomFormatter < Appsignal::EventFormatter
1761
+ # def format(payload)
1762
+ # ["Custom event", payload[:body]]
1763
+ # end
1764
+ # end
1765
+ #
1766
+ # Appsignal::EventFormatter.register("my.event", CustomFormatter)
1767
+ # ```
1768
+ #
1769
+ # _@see_ `#unregister`
1770
+ #
1771
+ # _@see_ `#registered?`
1772
+ sig { params(name: T.any(String, Symbol), formatter: T.nilable(Class)).void }
1773
+ def self.register(name, formatter = nil); end
1774
+
1775
+ # Unregisters an event formatter for a specific event name.
1776
+ #
1777
+ # _@param_ `name` — The name of the event to unregister the formatter for.
1778
+ #
1779
+ # _@param_ `formatter` — The formatter class to unregister. Defaults to `self`.
1780
+ #
1781
+ # Unregister a custom formatter
1782
+ # ```ruby
1783
+ # Appsignal::EventFormatter.unregister("my.event", CustomFormatter)
1784
+ # ```
1785
+ #
1786
+ # _@see_ `#register`
1787
+ #
1788
+ # _@see_ `#registered?`
1789
+ sig { params(name: T.any(String, Symbol), formatter: Class).void }
1790
+ def self.unregister(name, formatter = self); end
1791
+
1792
+ # Checks if an event formatter is registered for a specific event name.
1793
+ #
1794
+ # _@param_ `name` — The name of the event to check.
1795
+ #
1796
+ # _@param_ `klass` — The specific formatter class to check for. Optional.
1797
+ #
1798
+ # _@return_ — true if a formatter is registered, false otherwise.
1799
+ #
1800
+ # _@see_ `#register`
1801
+ #
1802
+ # _@see_ `#unregister`
1803
+ sig { params(name: T.any(String, Symbol), klass: T.nilable(Class)).returns(T::Boolean) }
1804
+ def self.registered?(name, klass = nil); end
1805
+ end
1806
+
1807
+ module Helpers
1808
+ module Metrics
1809
+ # Report a gauge metric.
1810
+ #
1811
+ # _@param_ `name` — The name of the metric.
1812
+ #
1813
+ # _@param_ `value` — The value of the metric.
1814
+ #
1815
+ # _@param_ `tags` — The tags for the metric. The Hash keys can be either a String or a Symbol. The tag values can be a String, Symbol, Integer, Float, TrueClass or FalseClass.
1816
+ #
1817
+ # _@see_ `https://docs.appsignal.com/metrics/custom.html` — Metrics documentation
1818
+ sig { params(name: T.any(String, Symbol), value: T.any(Integer, Float), tags: T::Hash[String, Object]).void }
1819
+ def set_gauge(name, value, tags = {}); end
1820
+
1821
+ # Report a counter metric.
1822
+ #
1823
+ # _@param_ `name` — The name of the metric.
1824
+ #
1825
+ # _@param_ `value` — The value of the metric.
1826
+ #
1827
+ # _@param_ `tags` — The tags for the metric. The Hash keys can be either a String or a Symbol. The tag values can be a String, Symbol, Integer, Float, TrueClass or FalseClass.
1828
+ #
1829
+ # _@see_ `https://docs.appsignal.com/metrics/custom.html` — Metrics documentation
1830
+ sig { params(name: T.any(String, Symbol), value: T.any(Integer, Float), tags: T::Hash[String, Object]).void }
1831
+ def increment_counter(name, value = 1.0, tags = {}); end
1832
+
1833
+ # Report a distribution metric.
1834
+ #
1835
+ # _@param_ `name` — The name of the metric.
1836
+ #
1837
+ # _@param_ `value` — The value of the metric.
1838
+ #
1839
+ # _@param_ `tags` — The tags for the metric. The Hash keys can be either a String or a Symbol. The tag values can be a String, Symbol, Integer, Float, TrueClass or FalseClass.
1840
+ #
1841
+ # _@see_ `https://docs.appsignal.com/metrics/custom.html` — Metrics documentation
1842
+ sig { params(name: T.any(String, Symbol), value: T.any(Integer, Float), tags: T::Hash[String, Object]).void }
1843
+ def add_distribution_value(name, value, tags = {}); end
1844
+ end
1845
+
1846
+ module Instrumentation
1847
+ # Monitor a block of code with AppSignal.
1848
+ #
1849
+ # This is a helper to create an AppSignal transaction, track any errors
1850
+ # that may occur and complete the transaction.
1851
+ #
1852
+ # This helper is recommended to be used in Ruby scripts and parts of an
1853
+ # app not already instrumented by AppSignal's automatic instrumentations.
1854
+ #
1855
+ # Use this helper in combination with our {.instrument} helper to track
1856
+ # instrumentation events.
1857
+ #
1858
+ # If AppSignal is not active ({Appsignal.active?}) it will still execute
1859
+ # the block, but not create a transaction for it.
1860
+ #
1861
+ # _@param_ `namespace` — The namespace to set on the new transaction. Defaults to the 'web' namespace. This will not update the active transaction's namespace if {.monitor} is called when another transaction is already active.
1862
+ #
1863
+ # _@param_ `action` — The action name for the transaction. The action name is required to be set for the transaction to be reported. The argument can be set to `nil` or `:set_later` if the action is set within the block with {#set_action}. This will not update the active transaction's action if {.monitor} is called when another transaction is already active.
1864
+ #
1865
+ # _@return_ — The value of the given block is returned.
1866
+ # Returns `nil` if there already is a transaction active and no block
1867
+ # was given.
1868
+ #
1869
+ # Instrument a block of code
1870
+ # ```ruby
1871
+ # Appsignal.monitor(
1872
+ # :namespace => "my_namespace",
1873
+ # :action => "MyClass#my_method"
1874
+ # ) do
1875
+ # # Some code
1876
+ # end
1877
+ # ```
1878
+ #
1879
+ # Instrument a block of code using the default namespace
1880
+ # ```ruby
1881
+ # Appsignal.monitor(
1882
+ # :action => "MyClass#my_method"
1883
+ # ) do
1884
+ # # Some code
1885
+ # end
1886
+ # ```
1887
+ #
1888
+ # Instrument a block of code with an instrumentation event
1889
+ # ```ruby
1890
+ # Appsignal.monitor(
1891
+ # :namespace => "my_namespace",
1892
+ # :action => "MyClass#my_method"
1893
+ # ) do
1894
+ # Appsignal.instrument("some_event.some_group") do
1895
+ # # Some code
1896
+ # end
1897
+ # end
1898
+ # ```
1899
+ #
1900
+ # Set the action name in the monitor block
1901
+ # ```ruby
1902
+ # Appsignal.monitor(
1903
+ # :action => nil
1904
+ # ) do
1905
+ # # Some code
1906
+ #
1907
+ # Appsignal.set_action("GET /resource/:id")
1908
+ # end
1909
+ # ```
1910
+ #
1911
+ # Set the action name in the monitor block
1912
+ # ```ruby
1913
+ # Appsignal.monitor(
1914
+ # :action => :set_later # Explicit placeholder
1915
+ # ) do
1916
+ # # Some code
1917
+ #
1918
+ # Appsignal.set_action("GET /resource/:id")
1919
+ # end
1920
+ # ```
1921
+ #
1922
+ # Set custom metadata on the transaction
1923
+ # ```ruby
1924
+ # Appsignal.monitor(
1925
+ # :namespace => "my_namespace",
1926
+ # :action => "MyClass#my_method"
1927
+ # ) do
1928
+ # # Some code
1929
+ #
1930
+ # Appsignal.add_tags(:tag1 => "value1", :tag2 => "value2")
1931
+ # Appsignal.add_params(:param1 => "value1", :param2 => "value2")
1932
+ # end
1933
+ # ```
1934
+ #
1935
+ # Call monitor within monitor will do nothing
1936
+ # ```ruby
1937
+ # Appsignal.monitor(
1938
+ # :namespace => "my_namespace",
1939
+ # :action => "MyClass#my_method"
1940
+ # ) do
1941
+ # # This will _not_ update the namespace and action name
1942
+ # Appsignal.monitor(
1943
+ # :namespace => "my_other_namespace",
1944
+ # :action => "MyOtherClass#my_other_method"
1945
+ # ) do
1946
+ # # Some code
1947
+ #
1948
+ # # The reported namespace will be "my_namespace"
1949
+ # # The reported action will be "MyClass#my_method"
1950
+ # end
1951
+ # end
1952
+ # ```
1953
+ #
1954
+ # _@see_ `https://docs.appsignal.com/ruby/instrumentation/background-jobs.html` — Monitor guide
1955
+ sig { params(action: T.any(String, Symbol, NilClass), namespace: T.nilable(T.any(String, Symbol)), blk: T.proc.returns(Object)).returns(T.nilable(Object)) }
1956
+ def monitor(action:, namespace: nil, &blk); end
1957
+
1958
+ # Instrument a block of code and stop AppSignal.
1959
+ #
1960
+ # Useful for cases such as one-off scripts where there is no long running
1961
+ # process active and the data needs to be sent after the process exists.
1962
+ #
1963
+ # Acts the same way as {.monitor}. See that method for more
1964
+ # documentation.
1965
+ #
1966
+ # _@param_ `namespace` — The namespace to set on the new transaction. Defaults to the 'web' namespace. This will not update the active transaction's namespace if {.monitor} is called when another transaction is already active.
1967
+ #
1968
+ # _@param_ `action` — The action name for the transaction. The action name is required to be set for the transaction to be reported. The argument can be set to `nil` or `:set_later` if the action is set within the block with {#set_action}. This will not update the active transaction's action if {.monitor} is called when another transaction is already active.
1969
+ #
1970
+ # _@return_ — The value of the given block is returned.
1971
+ #
1972
+ # _@see_ `monitor`
1973
+ sig { params(action: T.any(String, Symbol, NilClass), namespace: T.nilable(T.any(String, Symbol)), block: T.proc.returns(Object)).returns(T.nilable(Object)) }
1974
+ def monitor_and_stop(action:, namespace: nil, &block); end
1975
+
1976
+ # Send an error to AppSignal regardless of the context.
1977
+ #
1978
+ # **We recommend using the {#report_error} helper instead.**
1979
+ #
1980
+ # Records and send the exception to AppSignal.
1981
+ #
1982
+ # This instrumentation helper does not require a transaction to be
1983
+ # active, it starts a new transaction by itself.
1984
+ #
1985
+ # Use {.set_error} if your want to add an exception to the current
1986
+ # transaction.
1987
+ #
1988
+ # **Note**: Does not do anything if AppSignal is not active or when the
1989
+ # "error" is not a class extended from Ruby's Exception class.
1990
+ #
1991
+ # _@param_ `error` — The error to send to AppSignal.
1992
+ #
1993
+ # Send an exception
1994
+ # ```ruby
1995
+ # begin
1996
+ # raise "oh no!"
1997
+ # rescue => e
1998
+ # Appsignal.send_error(e)
1999
+ # end
2000
+ # ```
2001
+ #
2002
+ # Add more metadata to transaction
2003
+ # ```ruby
2004
+ # Appsignal.send_error(e) do
2005
+ # Appsignal.set_namespace("my_namespace")
2006
+ # Appsignal.set_action("my_action_name")
2007
+ # Appsignal.add_params(:search_query => params[:search_query])
2008
+ # Appsignal.add_tags(:key => "value")
2009
+ # end
2010
+ # ```
2011
+ #
2012
+ # _@see_ `https://docs.appsignal.com/ruby/instrumentation/exception-handling.html` — Exception handling guide
2013
+ sig { params(error: Exception, block: T.proc.params(transaction: Transaction).void).void }
2014
+ def send_error(error, &block); end
2015
+
2016
+ # Set an error on the current transaction.
2017
+ #
2018
+ # **We recommend using the {#report_error} helper instead.**
2019
+ #
2020
+ # **Note**: Does not do anything if AppSignal is not active, no
2021
+ # transaction is currently active or when the "error" is not a class
2022
+ # extended from Ruby's Exception class.
2023
+ #
2024
+ # _@param_ `exception` — The error to add to the current transaction.
2025
+ #
2026
+ # Manual instrumentation of set_error.
2027
+ # ```ruby
2028
+ # # Manually starting AppSignal here
2029
+ # # Manually starting a transaction here.
2030
+ # begin
2031
+ # raise "oh no!"
2032
+ # rescue => e
2033
+ # Appsignal.set_error(e)
2034
+ # end
2035
+ # # Manually completing the transaction here.
2036
+ # # Manually stopping AppSignal here
2037
+ # ```
2038
+ #
2039
+ # In a Rails application
2040
+ # ```ruby
2041
+ # class SomeController < ApplicationController
2042
+ # # The AppSignal transaction is created by our integration for you.
2043
+ # def create
2044
+ # # Do something that breaks
2045
+ # rescue => e
2046
+ # Appsignal.set_error(e)
2047
+ # end
2048
+ # end
2049
+ # ```
2050
+ #
2051
+ # Add more metadata to transaction
2052
+ # ```ruby
2053
+ # Appsignal.set_error(e) do
2054
+ # Appsignal.set_namespace("my_namespace")
2055
+ # Appsignal.set_action("my_action_name")
2056
+ # Appsignal.add_params(:search_query => params[:search_query])
2057
+ # Appsignal.add_tags(:key => "value")
2058
+ # end
2059
+ # ```
2060
+ #
2061
+ # _@see_ `https://docs.appsignal.com/ruby/instrumentation/exception-handling.html` — Exception handling guide
2062
+ sig { params(exception: Exception, blk: T.proc.params(transaction: Transaction).void).void }
2063
+ def set_error(exception, &blk); end
2064
+
2065
+ # Report an error to AppSignal.
2066
+ #
2067
+ # If a transaction is currently active, it will report the error on the
2068
+ # current transaction. If no transaction is active, it will report the
2069
+ # error on a new transaction.
2070
+ #
2071
+ # If a transaction is active and the transaction already has an error
2072
+ # reported on it, it will report multiple errors, up to a maximum of 10
2073
+ # errors.
2074
+ #
2075
+ # If a block is given to this method, the metadata set in this block will
2076
+ # only be applied to the transaction created for the given error. The
2077
+ # block will be called when the transaction is completed, which can be
2078
+ # much later than when {#report_error} is called.
2079
+ #
2080
+ # **Note**: If AppSignal is not active, no error is reported.
2081
+ #
2082
+ # **Note**: If the given exception argument is not an Exception subclass,
2083
+ # it will not be reported.
2084
+ #
2085
+ # _@param_ `exception` — The error to add to the current transaction.
2086
+ #
2087
+ # ```ruby
2088
+ # class SomeController < ApplicationController
2089
+ # def create
2090
+ # # Do something that breaks
2091
+ # rescue => error
2092
+ # Appsignal.report_error(error)
2093
+ # end
2094
+ # end
2095
+ # ```
2096
+ #
2097
+ # Add more metadata to transaction
2098
+ # ```ruby
2099
+ # Appsignal.report_error(error) do
2100
+ # Appsignal.set_namespace("my_namespace")
2101
+ # Appsignal.set_action("my_action_name")
2102
+ # Appsignal.add_params(:search_query => params[:search_query])
2103
+ # Appsignal.add_tags(:key => "value")
2104
+ # end
2105
+ # ```
2106
+ #
2107
+ # _@see_ `https://docs.appsignal.com/ruby/instrumentation/exception-handling.html` — Exception handling guide
2108
+ sig { params(exception: Exception, block: T.proc.params(transaction: Transaction).void).void }
2109
+ def report_error(exception, &block); end
2110
+
2111
+ # Set a custom action name for the current transaction.
2112
+ #
2113
+ # When using an integration such as the Rails or Sinatra AppSignal will
2114
+ # try to find the action name from the controller or endpoint for you.
2115
+ #
2116
+ # If you want to customize the action name as it appears on AppSignal.com
2117
+ # you can use this method. This overrides the action name AppSignal
2118
+ # generates in an integration.
2119
+ #
2120
+ # _@param_ `action`
2121
+ #
2122
+ # in a Rails controller
2123
+ # ```ruby
2124
+ # class SomeController < ApplicationController
2125
+ # before_action :set_appsignal_action
2126
+ #
2127
+ # def set_appsignal_action
2128
+ # Appsignal.set_action("DynamicController#dynamic_method")
2129
+ # end
2130
+ # end
2131
+ # ```
2132
+ sig { params(action: String).void }
2133
+ def set_action(action); end
2134
+
2135
+ # Set a custom namespace for the current transaction.
2136
+ #
2137
+ # When using an integration such as Rails or Sidekiq AppSignal will try
2138
+ # to find a appropriate namespace for the transaction.
2139
+ #
2140
+ # A Rails controller will be automatically put in the "http_request"
2141
+ # namespace, while a Sidekiq background job is put in the
2142
+ # "background_job" namespace.
2143
+ #
2144
+ # Note: The "http_request" namespace gets transformed on AppSignal.com to
2145
+ # "Web" and "background_job" gets transformed to "Background".
2146
+ #
2147
+ # If you want to customize the namespace in which transactions appear you
2148
+ # can use this method. This overrides the namespace AppSignal uses by
2149
+ # default.
2150
+ #
2151
+ # A common request we've seen is to split the administration panel from
2152
+ # the main application.
2153
+ #
2154
+ # _@param_ `namespace`
2155
+ #
2156
+ # create a custom admin namespace
2157
+ # ```ruby
2158
+ # class AdminController < ApplicationController
2159
+ # before_action :set_appsignal_namespace
2160
+ #
2161
+ # def set_appsignal_namespace
2162
+ # Appsignal.set_namespace("admin")
2163
+ # end
2164
+ # end
2165
+ # ```
2166
+ #
2167
+ # _@see_ `https://docs.appsignal.com/guides/namespaces.html` — Grouping with namespaces guide
2168
+ sig { params(namespace: String).void }
2169
+ def set_namespace(namespace); end
2170
+
2171
+ # Add custom data to the current transaction.
2172
+ #
2173
+ # Add extra information about the request or background that cannot be
2174
+ # expressed in tags, like nested data structures.
2175
+ #
2176
+ # If the root data type changes between calls of this method, the last
2177
+ # method call is stored.
2178
+ #
2179
+ # _@param_ `data` — Custom data to add to the transaction.
2180
+ #
2181
+ # Add Hash data
2182
+ # ```ruby
2183
+ # Appsignal.add_custom_data(:user => { :locale => "en" })
2184
+ # ```
2185
+ #
2186
+ # Merges Hash data
2187
+ # ```ruby
2188
+ # Appsignal.add_custom_data(:abc => "def")
2189
+ # Appsignal.add_custom_data(:xyz => "...")
2190
+ # # The custom data is: { :abc => "def", :xyz => "..." }
2191
+ # ```
2192
+ #
2193
+ # Add Array data
2194
+ # ```ruby
2195
+ # Appsignal.add_custom_data([
2196
+ # "array with data",
2197
+ # "other value",
2198
+ # :options => { :verbose => true }
2199
+ # ])
2200
+ # ```
2201
+ #
2202
+ # Merges Array data
2203
+ # ```ruby
2204
+ # Appsignal.add_custom_data([1, 2, 3])
2205
+ # Appsignal.add_custom_data([4, 5, 6])
2206
+ # # The custom data is: [1, 2, 3, 4, 5, 6]
2207
+ # ```
2208
+ #
2209
+ # Mixing of root data types is not supported
2210
+ # ```ruby
2211
+ # Appsignal.add_custom_data(:abc => "def")
2212
+ # Appsignal.add_custom_data([1, 2, 3])
2213
+ # # The custom data is: [1, 2, 3]
2214
+ # ```
2215
+ #
2216
+ # _@see_ `https://docs.appsignal.com/guides/custom-data/sample-data.html` — Sample data guide
2217
+ sig { params(data: T.any(T::Hash[Object, Object], T::Array[Object])).void }
2218
+ def add_custom_data(data); end
2219
+
2220
+ # Add tags to the current transaction.
2221
+ #
2222
+ # Tags are extra bits of information that are added to transaction and
2223
+ # appear on sample details pages on AppSignal.com.
2224
+ #
2225
+ # When this method is called multiple times, it will merge the tags.
2226
+ #
2227
+ # _@param_ `tags` — Collection of tags to add to the transaction.
2228
+ #
2229
+ # ```ruby
2230
+ # Appsignal.add_tags(:locale => "en", :user_id => 1)
2231
+ # Appsignal.add_tags("locale" => "en")
2232
+ # Appsignal.add_tags("user_id" => 1)
2233
+ # ```
2234
+ #
2235
+ # Nested hashes are not supported
2236
+ # ```ruby
2237
+ # # Bad
2238
+ # Appsignal.add_tags(:user => { :locale => "en" })
2239
+ # ```
2240
+ #
2241
+ # in a Rails controller
2242
+ # ```ruby
2243
+ # class SomeController < ApplicationController
2244
+ # before_action :add_appsignal_tags
2245
+ #
2246
+ # def add_appsignal_tags
2247
+ # Appsignal.add_tags(:locale => I18n.locale)
2248
+ # end
2249
+ # end
2250
+ # ```
2251
+ #
2252
+ # _@see_ `https://docs.appsignal.com/ruby/instrumentation/tagging.html` — Tagging guide
2253
+ sig { params(tags: T::Hash[Object, Object]).void }
2254
+ def add_tags(tags = {}); end
2255
+
2256
+ # Add parameters to the current transaction.
2257
+ #
2258
+ # Parameters are automatically added by most of our integrations. It
2259
+ # should not be necessary to call this method unless you want to report
2260
+ # different parameters.
2261
+ #
2262
+ # This method accepts both Hash and Array parameter types:
2263
+ # - Hash parameters will be merged when called multiple times
2264
+ # - Array parameters will be concatenated when called multiple times
2265
+ # - Mixing Hash and Array types will use the latest type (and log a warning)
2266
+ #
2267
+ # To filter parameters, see our parameter filtering guide.
2268
+ #
2269
+ # When both the `params` argument and a block is given to this method,
2270
+ # the block is leading and the argument will _not_ be used.
2271
+ #
2272
+ # _@param_ `params` — The parameters to add to the transaction.
2273
+ #
2274
+ # Add Hash parameters
2275
+ # ```ruby
2276
+ # Appsignal.add_params("param1" => "value1")
2277
+ # # The parameters include: { "param1" => "value1" }
2278
+ # ```
2279
+ #
2280
+ # Add Array parameters
2281
+ # ```ruby
2282
+ # Appsignal.add_params(["item1", "item2"])
2283
+ # # The parameters include: ["item1", "item2"]
2284
+ # ```
2285
+ #
2286
+ # Calling `add_params` multiple times with Hashes merges values
2287
+ # ```ruby
2288
+ # Appsignal.add_params("param1" => "value1")
2289
+ # Appsignal.add_params("param2" => "value2")
2290
+ # # The parameters include:
2291
+ # # { "param1" => "value1", "param2" => "value2" }
2292
+ # ```
2293
+ #
2294
+ # Calling `add_params` multiple times with Arrays concatenates values
2295
+ # ```ruby
2296
+ # Appsignal.add_params(["item1"])
2297
+ # Appsignal.add_params(["item2"])
2298
+ # # The parameters include: ["item1", "item2"]
2299
+ # ```
2300
+ #
2301
+ # _@see_ `https://docs.appsignal.com/guides/custom-data/sample-data.html` — Sample data guide
2302
+ #
2303
+ # _@see_ `https://docs.appsignal.com/guides/filter-data/filter-parameters.html` — Parameter filtering guide
2304
+ sig { params(params: T.nilable(T.any(T::Hash[String, Object], T::Array[Object])), block: T.proc.returns(T.any(T::Hash[String, Object], T::Array[Object]))).void }
2305
+ def add_params(params = nil, &block); end
2306
+
2307
+ # Mark the parameters sample data to be set as an empty value.
2308
+ #
2309
+ # Use this helper to unset request parameters / background job arguments
2310
+ # and not report any for this transaction.
2311
+ #
2312
+ # If parameters would normally be added by AppSignal instrumentations of
2313
+ # libraries, these parameters will not be added to the Transaction.
2314
+ #
2315
+ # Calling {#add_params} after this helper will add new parameters to the
2316
+ # transaction.
2317
+ #
2318
+ # _@see_ `Transaction#set_empty_params!`
2319
+ #
2320
+ # _@see_ `Transaction#set_params_if_nil`
2321
+ sig { void }
2322
+ def set_empty_params!; end
2323
+
2324
+ # Add session data to the current transaction.
2325
+ #
2326
+ # Session data is automatically added by most of our integrations. It
2327
+ # should not be necessary to call this method unless you want to report
2328
+ # different session data.
2329
+ #
2330
+ # To filter session data, see our session data filtering guide.
2331
+ #
2332
+ # When both the `session_data` argument and a block is given to this
2333
+ # method, the bock is leading and the argument will _not_ be used.
2334
+ #
2335
+ # _@param_ `session_data` — The session data to add to the transaction.
2336
+ #
2337
+ # Add session data
2338
+ # ```ruby
2339
+ # Appsignal.add_session_data("session" => "data")
2340
+ # # The session data will include:
2341
+ # # { "session" => "data" }
2342
+ # ```
2343
+ #
2344
+ # Calling `add_session_data` multiple times merge the values
2345
+ # ```ruby
2346
+ # Appsignal.add_session_data("session" => "data")
2347
+ # Appsignal.add_session_data("other" => "value")
2348
+ # # The session data will include:
2349
+ # # { "session" => "data", "other" => "value" }
2350
+ # ```
2351
+ #
2352
+ # _@see_ `https://docs.appsignal.com/guides/custom-data/sample-data.html` — Sample data guide
2353
+ #
2354
+ # _@see_ `https://docs.appsignal.com/guides/filter-data/filter-session-data.html` — Session data filtering guide
2355
+ sig { params(session_data: T.nilable(T::Hash[String, Object]), block: T.proc.returns(T::Hash[String, Object])).void }
2356
+ def add_session_data(session_data = nil, &block); end
2357
+
2358
+ # Add request headers to the current transaction.
2359
+ #
2360
+ # Request headers are automatically added by most of our integrations. It
2361
+ # should not be necessary to call this method unless you want to also
2362
+ # report different request headers.
2363
+ #
2364
+ # To filter request headers, see our request header filtering guide.
2365
+ #
2366
+ # When both the `request_headers` argument and a block is given to this
2367
+ # method, the block is leading and the argument will _not_ be used.
2368
+ #
2369
+ # _@param_ `headers` — The request headers to add to the transaction.
2370
+ #
2371
+ # Add request headers
2372
+ # ```ruby
2373
+ # Appsignal.add_headers("PATH_INFO" => "/some-path")
2374
+ # # The request headers will include:
2375
+ # # { "PATH_INFO" => "/some-path" }
2376
+ # ```
2377
+ #
2378
+ # Calling `add_headers` multiple times merge the values
2379
+ # ```ruby
2380
+ # Appsignal.add_headers("PATH_INFO" => "/some-path")
2381
+ # Appsignal.add_headers("HTTP_USER_AGENT" => "Firefox")
2382
+ # # The request headers will include:
2383
+ # # { "PATH_INFO" => "/some-path", "HTTP_USER_AGENT" => "Firefox" }
2384
+ # ```
2385
+ #
2386
+ # _@see_ `https://docs.appsignal.com/guides/custom-data/sample-data.html` — Sample data guide
2387
+ #
2388
+ # _@see_ `https://docs.appsignal.com/guides/filter-data/filter-headers.html` — Request headers filtering guide
2389
+ sig { params(headers: T.nilable(T::Hash[String, Object]), block: T.proc.returns(T::Hash[String, Object])).void }
2390
+ def add_headers(headers = nil, &block); end
2391
+
2392
+ # Add breadcrumbs to the transaction.
2393
+ #
2394
+ # Breadcrumbs can be used to trace what path a user has taken
2395
+ # before encountering an error.
2396
+ #
2397
+ # Only the last 20 added breadcrumbs will be saved.
2398
+ #
2399
+ # _@param_ `category` — category of breadcrumb e.g. "UI", "Network", "Navigation", "Console".
2400
+ #
2401
+ # _@param_ `action` — name of breadcrumb e.g "The user clicked a button", "HTTP 500 from http://blablabla.com"
2402
+ #
2403
+ # _@param_ `message` — optional message in string format
2404
+ #
2405
+ # _@param_ `metadata` — key/value metadata in <string, string> format
2406
+ #
2407
+ # _@param_ `time` — time of breadcrumb, should respond to `.to_i` defaults to `Time.now.utc`
2408
+ #
2409
+ # ```ruby
2410
+ # Appsignal.add_breadcrumb(
2411
+ # "Navigation",
2412
+ # "http://blablabla.com",
2413
+ # "",
2414
+ # { :response => 200 },
2415
+ # Time.now.utc
2416
+ # )
2417
+ # Appsignal.add_breadcrumb(
2418
+ # "Network",
2419
+ # "[GET] http://blablabla.com",
2420
+ # "",
2421
+ # { :response => 500 }
2422
+ # )
2423
+ # Appsignal.add_breadcrumb(
2424
+ # "UI",
2425
+ # "closed modal(change_password)",
2426
+ # "User closed modal without actions"
2427
+ # )
2428
+ # ```
2429
+ #
2430
+ # _@see_ `https://docs.appsignal.com/ruby/instrumentation/breadcrumbs.html` — Breadcrumb reference
2431
+ sig do
2432
+ params(
2433
+ category: String,
2434
+ action: String,
2435
+ message: String,
2436
+ metadata: T::Hash[String, String],
2437
+ time: Time
2438
+ ).void
2439
+ end
2440
+ def add_breadcrumb(category, action, message = "", metadata = {}, time = Time.now.utc); end
2441
+
2442
+ # Instrument helper for AppSignal.
2443
+ #
2444
+ # For more help, read our custom instrumentation guide, listed under "See
2445
+ # also".
2446
+ #
2447
+ # _@param_ `name` — Name of the instrumented event. Read our event naming guide listed under "See also".
2448
+ #
2449
+ # _@param_ `title` — Human readable name of the event.
2450
+ #
2451
+ # _@param_ `body` — Value of importance for the event, such as the server against an API call is made.
2452
+ #
2453
+ # _@param_ `body_format` — Enum for the type of event that is instrumented. Accepted values are {EventFormatter::DEFAULT} and {EventFormatter::SQL_BODY_FORMAT}, but we recommend you use {.instrument_sql} instead of {EventFormatter::SQL_BODY_FORMAT}.
2454
+ #
2455
+ # _@return_ — Returns the block's return value.
2456
+ #
2457
+ # Simple instrumentation
2458
+ # ```ruby
2459
+ # Appsignal.instrument("fetch.issue_fetcher") do
2460
+ # # To be instrumented code
2461
+ # end
2462
+ # ```
2463
+ #
2464
+ # Instrumentation with title and body
2465
+ # ```ruby
2466
+ # Appsignal.instrument(
2467
+ # "fetch.issue_fetcher",
2468
+ # "Fetching issue",
2469
+ # "GitHub API"
2470
+ # ) do
2471
+ # # To be instrumented code
2472
+ # end
2473
+ # ```
2474
+ #
2475
+ # _@see_ `.instrument_sql`
2476
+ #
2477
+ # _@see_ `https://docs.appsignal.com/ruby/instrumentation/instrumentation.html` — AppSignal custom instrumentation guide
2478
+ #
2479
+ # _@see_ `https://docs.appsignal.com/api/event-names.html` — AppSignal event naming guide
2480
+ sig do
2481
+ params(
2482
+ name: String,
2483
+ title: T.nilable(String),
2484
+ body: T.nilable(String),
2485
+ body_format: Integer,
2486
+ block: T.untyped
2487
+ ).returns(Object)
2488
+ end
2489
+ def instrument(name, title = nil, body = nil, body_format = Appsignal::EventFormatter::DEFAULT, &block); end
2490
+
2491
+ # Instrumentation helper for SQL queries.
2492
+ #
2493
+ # This helper filters out values from SQL queries so you don't have to.
2494
+ #
2495
+ # _@param_ `name` — Name of the instrumented event. Read our event naming guide listed under "See also".
2496
+ #
2497
+ # _@param_ `title` — Human readable name of the event.
2498
+ #
2499
+ # _@param_ `body` — SQL query that's being executed.
2500
+ #
2501
+ # _@return_ — Returns the block's return value.
2502
+ #
2503
+ # SQL query instrumentation
2504
+ # ```ruby
2505
+ # body = "SELECT * FROM ..."
2506
+ # Appsignal.instrument_sql("perform.query", nil, body) do
2507
+ # # To be instrumented code
2508
+ # end
2509
+ # ```
2510
+ #
2511
+ # SQL query instrumentation
2512
+ # ```ruby
2513
+ # body = "WHERE email = 'foo@..'"
2514
+ # Appsignal.instrument_sql("perform.query", nil, body) do
2515
+ # # query value will replace 'foo..' with a question mark `?`.
2516
+ # end
2517
+ # ```
2518
+ #
2519
+ # _@see_ `.instrument`
2520
+ #
2521
+ # _@see_ `https://docs.appsignal.com/ruby/instrumentation/instrumentation.html` — AppSignal custom instrumentation guide
2522
+ #
2523
+ # _@see_ `https://docs.appsignal.com/api/event-names.html` — AppSignal event naming guide
2524
+ sig do
2525
+ params(
2526
+ name: String,
2527
+ title: T.nilable(String),
2528
+ body: T.nilable(String),
2529
+ block: T.untyped
2530
+ ).returns(Object)
2531
+ end
2532
+ def instrument_sql(name, title = nil, body = nil, &block); end
2533
+
2534
+ # Convenience method for ignoring instrumentation events in a block of
2535
+ # code.
2536
+ #
2537
+ # - This helper ignores events, like those created
2538
+ # `Appsignal.instrument`, within this block.
2539
+ # This includes custom instrumentation and events recorded by AppSignal
2540
+ # integrations for requests, database queries, view rendering, etc.
2541
+ # - The time spent in the block is still reported on the transaction.
2542
+ # - Errors and metrics are reported from within this block.
2543
+ #
2544
+ # _@return_ — Returns the return value of the block.
2545
+ # Return nil if the block returns nil or no block is given.
2546
+ #
2547
+ # ```ruby
2548
+ # Appsignal.instrument "my_event.my_group" do
2549
+ # # Complex code here
2550
+ # end
2551
+ # Appsignal.ignore_instrumentation_events do
2552
+ # Appsignal.instrument "my_ignored_event.my_ignored_group" do
2553
+ # # Complex code here
2554
+ # end
2555
+ # end
2556
+ #
2557
+ # # Only the "my_event.my_group" instrumentation event is reported.
2558
+ # ```
2559
+ #
2560
+ # _@see_ `https://docs.appsignal.com/ruby/instrumentation/ignore-instrumentation.html` — Ignore instrumentation guide
2561
+ sig { params(blk: T.proc.returns(Object)).returns(T.nilable(Object)) }
2562
+ def ignore_instrumentation_events(&blk); end
2563
+ end
2564
+ end
2565
+
2566
+ class InternalError < StandardError
2567
+ end
2568
+
2569
+ class NotStartedError < Appsignal::InternalError
2570
+ sig { returns(String) }
2571
+ def message; end
2572
+ end
2573
+ end
2574
+
2575
+ # Extensions to Object for AppSignal method instrumentation.
2576
+ #
2577
+ # @see https://docs.appsignal.com/ruby/instrumentation/method-instrumentation.html
2578
+ # Method instrumentation documentation.
2579
+ class Object < BasicObject
2580
+ # Instruments a class method with AppSignal monitoring.
2581
+ #
2582
+ # _@param_ `method_name` — The name of the class method to instrument.
2583
+ #
2584
+ # _@param_ `options` — Options for instrumentation.
2585
+ #
2586
+ # _@see_ `https://docs.appsignal.com/ruby/instrumentation/method-instrumentation.html` — Method instrumentation documentation.
2587
+ sig { params(method_name: Symbol, options: T::Hash[Symbol, String]).returns(Symbol) }
2588
+ def self.appsignal_instrument_class_method(method_name, options = {}); end
2589
+
2590
+ # Instruments an instance method with AppSignal monitoring.
2591
+ #
2592
+ # _@param_ `method_name` — The name of the instance method to instrument.
2593
+ #
2594
+ # _@param_ `options` — Options for instrumentation.
2595
+ #
2596
+ # _@see_ `https://docs.appsignal.com/ruby/instrumentation/method-instrumentation.html` — Method instrumentation documentation.
2597
+ sig { params(method_name: Symbol, options: T::Hash[Symbol, String]).returns(Symbol) }
2598
+ def self.appsignal_instrument_method(method_name, options = {}); end
2599
+ end