appsignal 3.13.0-java → 4.0.0.beta.1-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +499 -487
- data/CHANGELOG.md +113 -0
- data/Rakefile +31 -7
- data/benchmark.rake +4 -6
- data/build_matrix.yml +45 -39
- data/ext/agent.rb +27 -27
- data/ext/appsignal_extension.c +25 -0
- data/gemfiles/rails-7.2.gemfile +11 -0
- data/lib/appsignal/check_in/cron.rb +2 -15
- data/lib/appsignal/cli/diagnose.rb +37 -28
- data/lib/appsignal/cli/install.rb +5 -1
- data/lib/appsignal/config.rb +57 -119
- data/lib/appsignal/demo.rb +2 -2
- data/lib/appsignal/extension/jruby.rb +14 -0
- data/lib/appsignal/helpers/instrumentation.rb +139 -417
- data/lib/appsignal/helpers/metrics.rb +0 -16
- data/lib/appsignal/hooks/action_cable.rb +8 -8
- data/lib/appsignal/hooks/active_job.rb +2 -2
- data/lib/appsignal/hooks/at_exit.rb +37 -0
- data/lib/appsignal/hooks.rb +1 -16
- data/lib/appsignal/integrations/action_cable.rb +2 -2
- data/lib/appsignal/integrations/capistrano/appsignal.cap +2 -4
- data/lib/appsignal/integrations/capistrano/capistrano_2_tasks.rb +1 -4
- data/lib/appsignal/integrations/delayed_job_plugin.rb +3 -3
- data/lib/appsignal/integrations/que.rb +2 -2
- data/lib/appsignal/integrations/railtie.rb +26 -59
- data/lib/appsignal/integrations/rake.rb +2 -2
- data/lib/appsignal/integrations/resque.rb +2 -2
- data/lib/appsignal/integrations/shoryuken.rb +4 -4
- data/lib/appsignal/integrations/sidekiq.rb +3 -3
- data/lib/appsignal/integrations/webmachine.rb +2 -2
- data/lib/appsignal/loaders.rb +1 -1
- data/lib/appsignal/probes.rb +0 -9
- data/lib/appsignal/rack/abstract_middleware.rb +4 -26
- data/lib/appsignal/rack/event_handler.rb +4 -4
- data/lib/appsignal/rack/rails_instrumentation.rb +1 -1
- data/lib/appsignal/rack.rb +0 -25
- data/lib/appsignal/sample_data.rb +95 -0
- data/lib/appsignal/transaction.rb +235 -361
- data/lib/appsignal/utils/rails_helper.rb +4 -0
- data/lib/appsignal/version.rb +1 -1
- data/lib/appsignal.rb +19 -71
- data/spec/lib/appsignal/auth_check_spec.rb +1 -1
- data/spec/lib/appsignal/capistrano2_spec.rb +1 -1
- data/spec/lib/appsignal/capistrano3_spec.rb +53 -13
- data/spec/lib/appsignal/check_in_spec.rb +1 -207
- data/spec/lib/appsignal/cli/demo_spec.rb +7 -27
- data/spec/lib/appsignal/cli/diagnose_spec.rb +145 -110
- data/spec/lib/appsignal/config_spec.rb +304 -379
- data/spec/lib/appsignal/extension_install_failure_spec.rb +5 -1
- data/spec/lib/appsignal/extension_spec.rb +5 -1
- data/spec/lib/appsignal/hooks/active_support_notifications/instrument_shared_examples.rb +1 -1
- data/spec/lib/appsignal/hooks/active_support_notifications/start_finish_shared_examples.rb +1 -2
- data/spec/lib/appsignal/hooks/active_support_notifications_spec.rb +1 -0
- data/spec/lib/appsignal/hooks/activejob_spec.rb +7 -12
- data/spec/lib/appsignal/hooks/at_exit_spec.rb +72 -0
- data/spec/lib/appsignal/hooks/gvl_spec.rb +10 -5
- data/spec/lib/appsignal/hooks/http_spec.rb +3 -3
- data/spec/lib/appsignal/hooks/net_http_spec.rb +3 -3
- data/spec/lib/appsignal/hooks/rake_spec.rb +6 -9
- data/spec/lib/appsignal/hooks/redis_client_spec.rb +5 -10
- data/spec/lib/appsignal/hooks/redis_spec.rb +4 -7
- data/spec/lib/appsignal/hooks/resque_spec.rb +3 -5
- data/spec/lib/appsignal/hooks_spec.rb +0 -41
- data/spec/lib/appsignal/integrations/data_mapper_spec.rb +29 -20
- data/spec/lib/appsignal/integrations/delayed_job_plugin_spec.rb +4 -9
- data/spec/lib/appsignal/integrations/railtie_spec.rb +179 -157
- data/spec/lib/appsignal/integrations/shoryuken_spec.rb +3 -5
- data/spec/lib/appsignal/integrations/sidekiq_spec.rb +48 -62
- data/spec/lib/appsignal/loaders/hanami_spec.rb +6 -9
- data/spec/lib/appsignal/loaders/padrino_spec.rb +6 -10
- data/spec/lib/appsignal/loaders/sinatra_spec.rb +6 -9
- data/spec/lib/appsignal/loaders_spec.rb +8 -1
- data/spec/lib/appsignal/marker_spec.rb +1 -1
- data/spec/lib/appsignal/probes_spec.rb +4 -83
- data/spec/lib/appsignal/rack/abstract_middleware_spec.rb +4 -63
- data/spec/lib/appsignal/rack/event_handler_spec.rb +18 -15
- data/spec/lib/appsignal/rack/rails_instrumentation_spec.rb +3 -11
- data/spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb +4 -5
- data/spec/lib/appsignal/sample_data_spec.rb +174 -0
- data/spec/lib/appsignal/transaction_spec.rb +791 -1031
- data/spec/lib/appsignal/transmitter_spec.rb +6 -8
- data/spec/lib/appsignal_spec.rb +294 -643
- data/spec/spec_helper.rb +1 -3
- data/spec/support/fixtures/projects/valid/config/appsignal.yml +4 -7
- data/spec/support/fixtures/projects/valid_with_rails_app/config/application.rb +16 -0
- data/spec/support/fixtures/projects/valid_with_rails_app/config/appsignal.yml +56 -0
- data/spec/support/fixtures/projects/valid_with_rails_app/config/environment.rb +5 -0
- data/spec/support/helpers/api_request_helper.rb +3 -2
- data/spec/support/helpers/config_helpers.rb +41 -11
- data/spec/support/helpers/dependency_helper.rb +8 -0
- data/spec/support/helpers/log_helpers.rb +1 -0
- data/spec/support/helpers/rails_helper.rb +6 -6
- data/spec/support/helpers/transaction_helpers.rb +2 -24
- data/spec/support/matchers/transaction.rb +3 -3
- data/spec/support/mocks/appsignal_mock.rb +3 -3
- data/spec/support/mocks/mock_probe.rb +2 -0
- data/spec/support/testing.rb +2 -2
- metadata +12 -22
- data/gemfiles/que_beta.gemfile +0 -5
- data/lib/appsignal/helpers/heartbeat.rb +0 -20
- data/lib/appsignal/integrations/grape.rb +0 -35
- data/lib/appsignal/integrations/hanami.rb +0 -13
- data/lib/appsignal/integrations/padrino.rb +0 -13
- data/lib/appsignal/integrations/sinatra.rb +0 -13
- data/lib/appsignal/rack/generic_instrumentation.rb +0 -22
- data/lib/appsignal/rack/streaming_listener.rb +0 -28
- data/spec/lib/appsignal/integrations/grape_spec.rb +0 -36
- data/spec/lib/appsignal/integrations/hanami_spec.rb +0 -17
- data/spec/lib/appsignal/integrations/padrino_spec.rb +0 -15
- data/spec/lib/appsignal/integrations/sinatra_spec.rb +0 -15
- data/spec/lib/appsignal/rack/generic_instrumentation_spec.rb +0 -81
- data/spec/lib/appsignal/rack/streaming_listener_spec.rb +0 -69
- data/spec/support/fixtures/projects/valid/config/environments/development.rb +0 -0
- data/spec/support/fixtures/projects/valid/config/environments/production.rb +0 -0
- data/spec/support/fixtures/projects/valid/config/environments/test.rb +0 -0
- data/spec/support/rails/my_app.rb +0 -6
- /data/spec/support/fixtures/projects/{valid/config/application.rb → valid_with_rails_app/log/.gitkeep} +0 -0
@@ -3,8 +3,6 @@
|
|
3
3
|
module Appsignal
|
4
4
|
module Helpers
|
5
5
|
module Instrumentation
|
6
|
-
include Appsignal::Utils::StdoutAndLoggerMessage
|
7
|
-
|
8
6
|
# Monitor a block of code with AppSignal.
|
9
7
|
#
|
10
8
|
# This is a helper to create an AppSignal transaction, track any errors
|
@@ -69,8 +67,8 @@ module Appsignal
|
|
69
67
|
# ) do
|
70
68
|
# # Some code
|
71
69
|
#
|
72
|
-
# Appsignal.
|
73
|
-
# Appsignal.
|
70
|
+
# Appsignal.add_tags(:tag1 => "value1", :tag2 => "value2")
|
71
|
+
# Appsignal.add_params(:param1 => "value1", :param2 => "value2")
|
74
72
|
# end
|
75
73
|
#
|
76
74
|
# @example Call monitor within monitor will do nothing
|
@@ -117,7 +115,7 @@ module Appsignal
|
|
117
115
|
if has_parent_transaction
|
118
116
|
callers = caller
|
119
117
|
Appsignal::Utils::StdoutAndLoggerMessage.warning \
|
120
|
-
"
|
118
|
+
"A transaction is active around this 'Appsignal.monitor' call. " \
|
121
119
|
"Calling `Appsignal.monitor` in another `Appsignal.monitor` block has no effect. " \
|
122
120
|
"The namespace and action are not updated for the active transaction." \
|
123
121
|
"Did you mean to use `Appsignal.instrument`? " \
|
@@ -160,173 +158,6 @@ module Appsignal
|
|
160
158
|
Appsignal.stop("monitor_and_stop")
|
161
159
|
end
|
162
160
|
|
163
|
-
# Creates an AppSignal transaction for the given block.
|
164
|
-
#
|
165
|
-
# If AppSignal is not {Appsignal.active?} it will still execute the
|
166
|
-
# block, but not create a transaction for it.
|
167
|
-
#
|
168
|
-
# A event is created for this transaction with the name given in the
|
169
|
-
# `name` argument. The event name must start with either `perform_job` or
|
170
|
-
# `process_action` to differentiate between the "web" and "background"
|
171
|
-
# namespace. Custom namespaces are not supported by this helper method.
|
172
|
-
#
|
173
|
-
# This helper method also captures any exception that occurs in the given
|
174
|
-
# block.
|
175
|
-
#
|
176
|
-
# @example
|
177
|
-
# Appsignal.monitor_transaction("perform_job.nightly_update") do
|
178
|
-
# # your code
|
179
|
-
# end
|
180
|
-
#
|
181
|
-
# @example with an environment
|
182
|
-
# Appsignal.monitor_transaction(
|
183
|
-
# "perform_job.nightly_update",
|
184
|
-
# :metadata => { "user_id" => 1 }
|
185
|
-
# ) do
|
186
|
-
# # your code
|
187
|
-
# end
|
188
|
-
#
|
189
|
-
# @param name [String] main event name.
|
190
|
-
# @param env [Hash<Symbol, Object>]
|
191
|
-
# @option env [Hash<Symbol/String, Object>] :params Params for the
|
192
|
-
# monitored request/job, see {Appsignal::Transaction#params=} for more
|
193
|
-
# information.
|
194
|
-
# @option env [String] :controller name of the controller in which the
|
195
|
-
# transaction was recorded.
|
196
|
-
# @option env [String] :class name of the Ruby class in which the
|
197
|
-
# transaction was recorded. If `:controller` is also given,
|
198
|
-
# `:controller` is used instead.
|
199
|
-
# @option env [String] :action name of the controller action in which the
|
200
|
-
# transaction was recorded.
|
201
|
-
# @option env [String] :method name of the Ruby method in which the
|
202
|
-
# transaction was recorded. If `:action` is also given, `:action`
|
203
|
-
# is used instead.
|
204
|
-
# @option env [Integer] :queue_start the moment the request/job was
|
205
|
-
# queued. Used to track how long requests/jobs were queued before being
|
206
|
-
# executed.
|
207
|
-
# @option env [Hash<Symbol/String, String/Fixnum>] :metadata Additional
|
208
|
-
# metadata for the transaction, see
|
209
|
-
# {Appsignal::Transaction#set_metadata} for more information.
|
210
|
-
# @yield the block to monitor.
|
211
|
-
# @raise [Exception] any exception that occurs within the given block is
|
212
|
-
# re-raised by this method.
|
213
|
-
# @return [Object] the value of the given block is returned.
|
214
|
-
# @since 0.10.0
|
215
|
-
def monitor_transaction(name, env = {}, &block)
|
216
|
-
stdout_and_logger_warning \
|
217
|
-
"The `Appsignal.monitor_transaction` helper is deprecated. " \
|
218
|
-
"Please use `Appsignal.monitor` and `Appsignal.instrument` instead. " \
|
219
|
-
"Read our instrumentation documentation: " \
|
220
|
-
"https://docs.appsignal.com/ruby/instrumentation/instrumentation.html"
|
221
|
-
_monitor_transaction(name, env, &block)
|
222
|
-
end
|
223
|
-
|
224
|
-
# @api private
|
225
|
-
def _monitor_transaction(name, env = {}, &block)
|
226
|
-
# Always verify input, even when Appsignal is not active.
|
227
|
-
# This makes it more likely invalid arguments get flagged in test/dev
|
228
|
-
# environments.
|
229
|
-
if name.start_with?("perform_job")
|
230
|
-
namespace = Appsignal::Transaction::BACKGROUND_JOB
|
231
|
-
request = Appsignal::Transaction::InternalGenericRequest.new(env)
|
232
|
-
elsif name.start_with?("process_action")
|
233
|
-
namespace = Appsignal::Transaction::HTTP_REQUEST
|
234
|
-
request = ::Rack::Request.new(env)
|
235
|
-
else
|
236
|
-
internal_logger.error "Unrecognized name '#{name}': names must " \
|
237
|
-
"start with either 'perform_job' (for jobs and tasks) or " \
|
238
|
-
"'process_action' (for HTTP requests)"
|
239
|
-
return yield
|
240
|
-
end
|
241
|
-
|
242
|
-
return yield unless active?
|
243
|
-
|
244
|
-
transaction = Appsignal::Transaction.create(
|
245
|
-
SecureRandom.uuid,
|
246
|
-
namespace,
|
247
|
-
request
|
248
|
-
)
|
249
|
-
begin
|
250
|
-
Appsignal.instrument(name, &block)
|
251
|
-
rescue Exception => error # rubocop:disable Lint/RescueException
|
252
|
-
transaction.set_error(error)
|
253
|
-
raise error
|
254
|
-
ensure
|
255
|
-
transaction.set_http_or_background_action(request.env)
|
256
|
-
queue_start = Appsignal::Rack::Utils.queue_start_from(request.env) ||
|
257
|
-
(env[:queue_start]&.to_i&.* 1_000)
|
258
|
-
transaction.set_queue_start(queue_start) if queue_start
|
259
|
-
Appsignal::Transaction.complete_current!
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
# Monitor a transaction, stop AppSignal and wait for this single
|
264
|
-
# transaction to be flushed.
|
265
|
-
#
|
266
|
-
# Useful for cases such as Rake tasks and Resque-like systems where a
|
267
|
-
# process is forked and immediately exits after the transaction finishes.
|
268
|
-
#
|
269
|
-
# @see monitor_transaction
|
270
|
-
def monitor_single_transaction(name, env = {}, &block)
|
271
|
-
stdout_and_logger_warning \
|
272
|
-
"The `Appsignal.monitor_single_transaction` helper is deprecated. " \
|
273
|
-
"Please use `Appsignal.monitor_and_stop` and `Appsignal.instrument` instead. " \
|
274
|
-
"Read our instrumentation documentation: " \
|
275
|
-
"https://docs.appsignal.com/ruby/instrumentation/instrumentation.html"
|
276
|
-
monitor_transaction(name, env, &block)
|
277
|
-
ensure
|
278
|
-
stop("monitor_single_transaction")
|
279
|
-
end
|
280
|
-
|
281
|
-
# Listen for an error to occur and send it to AppSignal.
|
282
|
-
#
|
283
|
-
# Uses {.send_error} to directly send the error in a separate
|
284
|
-
# transaction. Does not add the error to the current transaction.
|
285
|
-
#
|
286
|
-
# Make sure that AppSignal is integrated in your application beforehand.
|
287
|
-
# AppSignal won't record errors unless {Appsignal.active?} is `true`.
|
288
|
-
#
|
289
|
-
# @example
|
290
|
-
# # my_app.rb
|
291
|
-
# # setup AppSignal beforehand
|
292
|
-
#
|
293
|
-
# Appsignal.listen_for_error do
|
294
|
-
# # my code
|
295
|
-
# raise "foo"
|
296
|
-
# end
|
297
|
-
#
|
298
|
-
# @see Transaction.set_tags
|
299
|
-
# @see Transaction.set_namespace
|
300
|
-
# @see .send_error
|
301
|
-
# @see https://docs.appsignal.com/ruby/instrumentation/integrating-appsignal.html
|
302
|
-
# AppSignal integration guide
|
303
|
-
# @see https://docs.appsignal.com/ruby/instrumentation/exception-handling.html
|
304
|
-
# Exception handling guide
|
305
|
-
#
|
306
|
-
# @deprecated Use `rescue => error` with {.report_error} instead.
|
307
|
-
# @param tags [Hash, nil]
|
308
|
-
# @param namespace [String] the namespace for this error.
|
309
|
-
# @yield yields the given block.
|
310
|
-
# @return [Object] returns the return value of the given block.
|
311
|
-
def listen_for_error(
|
312
|
-
tags = nil,
|
313
|
-
namespace = Appsignal::Transaction::HTTP_REQUEST
|
314
|
-
)
|
315
|
-
stdout_and_logger_warning \
|
316
|
-
"The `Appsignal.listen_for_error` helper is deprecated. " \
|
317
|
-
"Please use `rescue => error` and `Appsignal.report_error` instead. " \
|
318
|
-
"Read our exception handling documentation: " \
|
319
|
-
"https://docs.appsignal.com/ruby/instrumentation/exception-handling.html"
|
320
|
-
yield
|
321
|
-
rescue Exception => error # rubocop:disable Lint/RescueException
|
322
|
-
send_error(error) do |transaction|
|
323
|
-
transaction.set_tags(tags) if tags
|
324
|
-
transaction.set_namespace(namespace) if namespace
|
325
|
-
end
|
326
|
-
raise error
|
327
|
-
end
|
328
|
-
alias :listen_for_exception :listen_for_error
|
329
|
-
|
330
161
|
# Send an error to AppSignal regardless of the context.
|
331
162
|
#
|
332
163
|
# Records and send the exception to AppSignal.
|
@@ -347,28 +178,15 @@ module Appsignal
|
|
347
178
|
# Appsignal.send_error(e)
|
348
179
|
# end
|
349
180
|
#
|
350
|
-
# @example Send an exception with tags. Deprecated method.
|
351
|
-
# begin
|
352
|
-
# raise "oh no!"
|
353
|
-
# rescue => e
|
354
|
-
# Appsignal.send_error(e, :key => "value")
|
355
|
-
# end
|
356
|
-
#
|
357
181
|
# @example Add more metadata to transaction
|
358
|
-
# Appsignal.send_error(e) do
|
359
|
-
#
|
360
|
-
#
|
361
|
-
#
|
362
|
-
#
|
182
|
+
# Appsignal.send_error(e) do
|
183
|
+
# Appsignal.set_namespace("my_namespace")
|
184
|
+
# Appsignal.set_action("my_action_name")
|
185
|
+
# Appsignal.add_params(:search_query => params[:search_query])
|
186
|
+
# Appsignal.add_tags(:key => "value")
|
363
187
|
# end
|
364
188
|
#
|
365
189
|
# @param error [Exception] The error to send to AppSignal.
|
366
|
-
# @param tags [Hash{String, Symbol => String, Symbol, Integer}]
|
367
|
-
# Additional tags to add to the error. See also {.tag_request}.
|
368
|
-
# This parameter is deprecated. Use the block argument instead.
|
369
|
-
# @param namespace [String] The namespace in which the error occurred.
|
370
|
-
# See also {.set_namespace}.
|
371
|
-
# This parameter is deprecated. Use the block argument instead.
|
372
190
|
# @yield [transaction] yields block to allow modification of the
|
373
191
|
# transaction before it's send.
|
374
192
|
# @yieldparam transaction [Transaction] yields the AppSignal transaction
|
@@ -381,31 +199,7 @@ module Appsignal
|
|
381
199
|
# @see https://docs.appsignal.com/ruby/instrumentation/tagging.html
|
382
200
|
# Tagging guide
|
383
201
|
# @since 0.6.0
|
384
|
-
def send_error(
|
385
|
-
error,
|
386
|
-
tags = nil,
|
387
|
-
namespace = nil
|
388
|
-
)
|
389
|
-
if tags
|
390
|
-
call_location = caller(1..1).first
|
391
|
-
stdout_and_logger_warning \
|
392
|
-
"The tags argument for `Appsignal.send_error` is deprecated. " \
|
393
|
-
"Please use the block method to set tags instead.\n\n" \
|
394
|
-
" Appsignal.send_error(error) do |transaction|\n" \
|
395
|
-
" transaction.set_tags(#{tags})\n" \
|
396
|
-
" end\n\n" \
|
397
|
-
"Appsignal.send_error called on location: #{call_location}"
|
398
|
-
end
|
399
|
-
if namespace
|
400
|
-
call_location = caller(1..1).first
|
401
|
-
stdout_and_logger_warning \
|
402
|
-
"The namespace argument for `Appsignal.send_error` is deprecated. " \
|
403
|
-
"Please use the block method to set the namespace instead.\n\n" \
|
404
|
-
" Appsignal.send_error(error) do |transaction|\n" \
|
405
|
-
" transaction.set_namespace(#{namespace.inspect})\n" \
|
406
|
-
" end\n\n" \
|
407
|
-
"Appsignal.send_error called on location: #{call_location}"
|
408
|
-
end
|
202
|
+
def send_error(error, &block)
|
409
203
|
return unless active?
|
410
204
|
|
411
205
|
unless error.is_a?(Exception)
|
@@ -413,13 +207,13 @@ module Appsignal
|
|
413
207
|
"The given value is not an exception: #{error.inspect}"
|
414
208
|
return
|
415
209
|
end
|
210
|
+
|
416
211
|
transaction = Appsignal::Transaction.new(
|
417
212
|
SecureRandom.uuid,
|
418
|
-
|
213
|
+
Appsignal::Transaction::HTTP_REQUEST
|
419
214
|
)
|
420
|
-
transaction.
|
421
|
-
|
422
|
-
yield transaction if block_given?
|
215
|
+
transaction.set_error(error, &block)
|
216
|
+
|
423
217
|
transaction.complete
|
424
218
|
end
|
425
219
|
alias :send_exception :send_error
|
@@ -452,21 +246,15 @@ module Appsignal
|
|
452
246
|
# end
|
453
247
|
#
|
454
248
|
# @example Add more metadata to transaction
|
455
|
-
# Appsignal.set_error(e) do
|
456
|
-
#
|
457
|
-
#
|
458
|
-
#
|
459
|
-
#
|
249
|
+
# Appsignal.set_error(e) do
|
250
|
+
# Appsignal.set_namespace("my_namespace")
|
251
|
+
# Appsignal.set_action("my_action_name")
|
252
|
+
# Appsignal.add_params(:search_query => params[:search_query])
|
253
|
+
# Appsignal.add_tags(:key => "value")
|
460
254
|
# end
|
461
255
|
#
|
462
256
|
# @param exception [Exception] The error to add to the current
|
463
257
|
# transaction.
|
464
|
-
# @param tags [Hash{String, Symbol => String, Symbol, Integer}]
|
465
|
-
# Additional tags to add to the error. See also {.tag_request}.
|
466
|
-
# This parameter is deprecated. Use the block argument instead.
|
467
|
-
# @param namespace [String] The namespace in which the error occurred.
|
468
|
-
# See also {.set_namespace}.
|
469
|
-
# This parameter is deprecated. Use the block argument instead.
|
470
258
|
# @yield [transaction] yields block to allow modification of the
|
471
259
|
# transaction.
|
472
260
|
# @yieldparam transaction [Transaction] yields the AppSignal transaction
|
@@ -478,27 +266,7 @@ module Appsignal
|
|
478
266
|
# @see https://docs.appsignal.com/ruby/instrumentation/exception-handling.html
|
479
267
|
# Exception handling guide
|
480
268
|
# @since 0.6.6
|
481
|
-
def set_error(exception
|
482
|
-
if tags
|
483
|
-
call_location = caller(1..1).first
|
484
|
-
stdout_and_logger_warning \
|
485
|
-
"The tags argument for `Appsignal.set_error` is deprecated. " \
|
486
|
-
"Please use the block method to set tags instead.\n\n" \
|
487
|
-
" Appsignal.set_error(error) do |transaction|\n" \
|
488
|
-
" transaction.set_tags(#{tags})\n" \
|
489
|
-
" end\n\n" \
|
490
|
-
"Appsignal.set_error called on location: #{call_location}"
|
491
|
-
end
|
492
|
-
if namespace
|
493
|
-
call_location = caller(1..1).first
|
494
|
-
stdout_and_logger_warning \
|
495
|
-
"The namespace argument for `Appsignal.set_error` is deprecated. " \
|
496
|
-
"Please use the block method to set the namespace instead.\n\n" \
|
497
|
-
" Appsignal.set_error(error) do |transaction|\n" \
|
498
|
-
" transaction.set_namespace(#{namespace.inspect})\n" \
|
499
|
-
" end\n\n" \
|
500
|
-
"Appsignal.set_error called on location: #{call_location}"
|
501
|
-
end
|
269
|
+
def set_error(exception)
|
502
270
|
unless exception.is_a?(Exception)
|
503
271
|
internal_logger.error "Appsignal.set_error: Cannot set error. " \
|
504
272
|
"The given value is not an exception: #{exception.inspect}"
|
@@ -508,8 +276,6 @@ module Appsignal
|
|
508
276
|
|
509
277
|
transaction = Appsignal::Transaction.current
|
510
278
|
transaction.set_error(exception)
|
511
|
-
transaction.set_tags(tags) if tags
|
512
|
-
transaction.set_namespace(namespace) if namespace
|
513
279
|
yield transaction if block_given?
|
514
280
|
end
|
515
281
|
alias :set_exception :set_error
|
@@ -536,11 +302,11 @@ module Appsignal
|
|
536
302
|
# end
|
537
303
|
#
|
538
304
|
# @example Add more metadata to transaction
|
539
|
-
# Appsignal.report_error(error) do
|
540
|
-
#
|
541
|
-
#
|
542
|
-
#
|
543
|
-
#
|
305
|
+
# Appsignal.report_error(error) do
|
306
|
+
# Appsignal.set_namespace("my_namespace")
|
307
|
+
# Appsignal.set_action("my_action_name")
|
308
|
+
# Appsignal.add_params(:search_query => params[:search_query])
|
309
|
+
# Appsignal.add_tags(:key => "value")
|
544
310
|
# end
|
545
311
|
#
|
546
312
|
# @param exception [Exception] The error to add to the current
|
@@ -554,9 +320,9 @@ module Appsignal
|
|
554
320
|
# @see https://docs.appsignal.com/ruby/instrumentation/exception-handling.html
|
555
321
|
# Exception handling guide
|
556
322
|
# @since 3.10.0
|
557
|
-
def report_error(exception)
|
323
|
+
def report_error(exception, &block)
|
558
324
|
unless exception.is_a?(Exception)
|
559
|
-
internal_logger.error "Appsignal.report_error: Cannot
|
325
|
+
internal_logger.error "Appsignal.report_error: Cannot add error. " \
|
560
326
|
"The given value is not an exception: #{exception.inspect}"
|
561
327
|
return
|
562
328
|
end
|
@@ -573,12 +339,9 @@ module Appsignal
|
|
573
339
|
)
|
574
340
|
end
|
575
341
|
|
576
|
-
transaction.
|
577
|
-
yield transaction if block_given?
|
578
|
-
|
579
|
-
return if has_parent_transaction
|
342
|
+
transaction.add_error(exception, &block)
|
580
343
|
|
581
|
-
transaction.complete
|
344
|
+
transaction.complete unless has_parent_transaction
|
582
345
|
end
|
583
346
|
alias :report_exception :report_error
|
584
347
|
|
@@ -652,36 +415,56 @@ module Appsignal
|
|
652
415
|
Appsignal::Transaction.current.set_namespace(namespace)
|
653
416
|
end
|
654
417
|
|
655
|
-
#
|
418
|
+
# Add custom data to the current transaction.
|
656
419
|
#
|
657
420
|
# Add extra information about the request or background that cannot be
|
658
421
|
# expressed in tags, like nested data structures.
|
659
422
|
#
|
660
|
-
#
|
661
|
-
#
|
423
|
+
# If the root data type changes between calls of this method, the last
|
424
|
+
# method call is stored.
|
662
425
|
#
|
663
|
-
# @example
|
664
|
-
# Appsignal.
|
665
|
-
#
|
426
|
+
# @example Add Hash data
|
427
|
+
# Appsignal.add_custom_data(:user => { :locale => "en" })
|
428
|
+
#
|
429
|
+
# @example Merges Hash data
|
430
|
+
# Appsignal.add_custom_data(:abc => "def")
|
431
|
+
# Appsignal.add_custom_data(:xyz => "...")
|
432
|
+
# # The custom data is: { :abc => "def", :xyz => "..." }
|
433
|
+
#
|
434
|
+
# @example Add Array data
|
435
|
+
# Appsignal.add_custom_data([
|
666
436
|
# "array with data",
|
437
|
+
# "other value",
|
667
438
|
# :options => { :verbose => true }
|
668
439
|
# ])
|
669
440
|
#
|
670
|
-
# @
|
671
|
-
#
|
441
|
+
# @example Merges Array data
|
442
|
+
# Appsignal.add_custom_data([1, 2, 3])
|
443
|
+
# Appsignal.add_custom_data([4, 5, 6])
|
444
|
+
# # The custom data is: [1, 2, 3, 4, 5, 6]
|
445
|
+
#
|
446
|
+
# @example Mixing of root data types is not supported
|
447
|
+
# Appsignal.add_custom_data(:abc => "def")
|
448
|
+
# Appsignal.add_custom_data([1, 2, 3])
|
449
|
+
# # The custom data is: [1, 2, 3]
|
450
|
+
#
|
451
|
+
# @since 4.0.0
|
452
|
+
# @param data [Hash/Array] Custom data to add to the transaction.
|
453
|
+
# @return [void]
|
454
|
+
#
|
455
|
+
# @see Transaction#add_custom_data
|
672
456
|
# @see https://docs.appsignal.com/guides/custom-data/sample-data.html
|
673
457
|
# Sample data guide
|
674
|
-
|
675
|
-
# @return [void]
|
676
|
-
def set_custom_data(data)
|
458
|
+
def add_custom_data(data)
|
677
459
|
return unless active?
|
678
460
|
return unless Appsignal::Transaction.current?
|
679
461
|
|
680
462
|
transaction = Appsignal::Transaction.current
|
681
|
-
transaction.
|
463
|
+
transaction.add_custom_data(data)
|
682
464
|
end
|
465
|
+
alias :set_custom_data :add_custom_data
|
683
466
|
|
684
|
-
#
|
467
|
+
# Add tags to the current transaction.
|
685
468
|
#
|
686
469
|
# Tags are extra bits of information that are added to transaction and
|
687
470
|
# appear on sample details pages on AppSignal.com.
|
@@ -689,221 +472,169 @@ module Appsignal
|
|
689
472
|
# When this method is called multiple times, it will merge the tags.
|
690
473
|
#
|
691
474
|
# @example
|
692
|
-
# Appsignal.
|
693
|
-
# Appsignal.
|
694
|
-
# Appsignal.
|
475
|
+
# Appsignal.add_tags(:locale => "en", :user_id => 1)
|
476
|
+
# Appsignal.add_tags("locale" => "en")
|
477
|
+
# Appsignal.add_tags("user_id" => 1)
|
695
478
|
#
|
696
479
|
# @example Nested hashes are not supported
|
697
480
|
# # Bad
|
698
|
-
# Appsignal.
|
481
|
+
# Appsignal.add_tags(:user => { :locale => "en" })
|
699
482
|
#
|
700
483
|
# @example in a Rails controller
|
701
484
|
# class SomeController < ApplicationController
|
702
|
-
# before_action :
|
485
|
+
# before_action :add_appsignal_tags
|
703
486
|
#
|
704
|
-
# def
|
705
|
-
# Appsignal.
|
487
|
+
# def add_appsignal_tags
|
488
|
+
# Appsignal.add_tags(:locale => I18n.locale)
|
706
489
|
# end
|
707
490
|
# end
|
708
491
|
#
|
709
|
-
# @
|
492
|
+
# @since 4.0.0
|
493
|
+
# @param tags [Hash] Collection of tags to add to the transaction.
|
710
494
|
# @option tags [String, Symbol, Integer] :any
|
711
495
|
# The name of the tag as a Symbol.
|
712
496
|
# @option tags [String, Symbol, Integer] "any"
|
713
497
|
# The name of the tag as a String.
|
714
498
|
# @return [void]
|
715
499
|
#
|
716
|
-
# @see Transaction
|
500
|
+
# @see Transaction#add_tags
|
717
501
|
# @see https://docs.appsignal.com/ruby/instrumentation/tagging.html
|
718
502
|
# Tagging guide
|
719
|
-
def
|
503
|
+
def add_tags(tags = {})
|
720
504
|
return unless active?
|
721
505
|
return unless Appsignal::Transaction.current?
|
722
506
|
|
723
507
|
transaction = Appsignal::Transaction.current
|
724
|
-
transaction.
|
508
|
+
transaction.add_tags(tags)
|
725
509
|
end
|
726
|
-
alias :
|
727
|
-
alias :
|
510
|
+
alias :tag_request :add_tags
|
511
|
+
alias :tag_job :add_tags
|
512
|
+
alias :set_tags :add_tags
|
728
513
|
|
729
|
-
#
|
514
|
+
# Add parameters to the current transaction.
|
730
515
|
#
|
731
|
-
# Parameters are automatically
|
732
|
-
# not be necessary to call this method unless you want to report
|
516
|
+
# Parameters are automatically added by most of our integrations. It
|
517
|
+
# should not be necessary to call this method unless you want to report
|
733
518
|
# different parameters.
|
734
519
|
#
|
735
520
|
# To filter parameters, see our parameter filtering guide.
|
736
521
|
#
|
737
|
-
# When this method is called multiple times, it will overwrite the
|
738
|
-
# previously set value.
|
739
|
-
#
|
740
|
-
# When no parameters are set this way, the transaction will look for
|
741
|
-
# parameters in its request environment.
|
742
|
-
#
|
743
|
-
# A block can be given to this method to defer the fetching and parsing
|
744
|
-
# of the parameters until and only when the transaction is sampled.
|
745
|
-
#
|
746
522
|
# When both the `params` argument and a block is given to this method,
|
747
|
-
# the
|
748
|
-
#
|
749
|
-
# @example Set parameters
|
750
|
-
# Appsignal.set_params("param1" => "value1")
|
751
|
-
#
|
752
|
-
# @example Calling `set_params` multiple times will only keep the last call
|
753
|
-
# Appsignal.set_params("param1" => "value1")
|
754
|
-
# Appsignal.set_params("param2" => "value2")
|
755
|
-
# # The parameters are: { "param2" => "value2" }
|
523
|
+
# the block is leading and the argument will _not_ be used.
|
756
524
|
#
|
757
|
-
# @example
|
758
|
-
# Appsignal.
|
759
|
-
#
|
760
|
-
# JSON.parse('{"param1": "value1"}')
|
761
|
-
# end
|
762
|
-
# # The parameters are: { "param1" => "value1" }
|
525
|
+
# @example Add parameters
|
526
|
+
# Appsignal.add_params("param1" => "value1")
|
527
|
+
# # The parameters include: { "param1" => "value1" }
|
763
528
|
#
|
764
|
-
# @example Calling `
|
765
|
-
# Appsignal.
|
766
|
-
#
|
767
|
-
#
|
768
|
-
#
|
769
|
-
# # The parameters are: { "argument" => "argument value" }
|
529
|
+
# @example Calling `add_params` multiple times will merge the values
|
530
|
+
# Appsignal.add_params("param1" => "value1")
|
531
|
+
# Appsignal.add_params("param2" => "value2")
|
532
|
+
# # The parameters include:
|
533
|
+
# # { "param1" => "value1", "param2" => "value2" }
|
770
534
|
#
|
771
|
-
# @since
|
772
|
-
# @param params [Hash] The parameters to
|
535
|
+
# @since 4.0.0
|
536
|
+
# @param params [Hash] The parameters to add to the transaction.
|
773
537
|
# @yield This block is called when the transaction is sampled. The block's
|
774
538
|
# return value will become the new parameters.
|
539
|
+
# @return [void]
|
540
|
+
#
|
775
541
|
# @see https://docs.appsignal.com/guides/custom-data/sample-data.html
|
776
542
|
# Sample data guide
|
777
543
|
# @see https://docs.appsignal.com/guides/filter-data/filter-parameters.html
|
778
544
|
# Parameter filtering guide
|
779
|
-
# @see Transaction#
|
780
|
-
|
781
|
-
def set_params(params = nil, &block)
|
545
|
+
# @see Transaction#add_params
|
546
|
+
def add_params(params = nil, &block)
|
782
547
|
return unless active?
|
783
548
|
return unless Appsignal::Transaction.current?
|
784
549
|
|
785
550
|
transaction = Appsignal::Transaction.current
|
786
|
-
transaction.
|
551
|
+
transaction.add_params(params, &block)
|
787
552
|
end
|
553
|
+
alias :set_params :add_params
|
788
554
|
|
789
|
-
#
|
555
|
+
# Add session data to the current transaction.
|
790
556
|
#
|
791
|
-
# Session data is automatically
|
557
|
+
# Session data is automatically added by most of our integrations. It
|
792
558
|
# should not be necessary to call this method unless you want to report
|
793
559
|
# different session data.
|
794
560
|
#
|
795
561
|
# To filter session data, see our session data filtering guide.
|
796
562
|
#
|
797
|
-
# When this method is called multiple times, it will overwrite the
|
798
|
-
# previously set value.
|
799
|
-
#
|
800
|
-
# A block can be given to this method to defer the fetching and parsing
|
801
|
-
# of the session data until and only when the transaction is sampled.
|
802
|
-
#
|
803
563
|
# When both the `session_data` argument and a block is given to this
|
804
|
-
# method, the
|
805
|
-
# be called.
|
806
|
-
#
|
807
|
-
# @example Set session data
|
808
|
-
# Appsignal.set_session_data("data" => "value")
|
809
|
-
#
|
810
|
-
# @example Calling `set_session_data` multiple times will only keep the last call
|
811
|
-
# Appsignal.set_session_data("data1" => "value1")
|
812
|
-
# Appsignal.set_session_data("data2" => "value2")
|
813
|
-
# # The session data is: { "data2" => "value2" }
|
564
|
+
# method, the bock is leading and the argument will _not_ be used.
|
814
565
|
#
|
815
|
-
# @example
|
816
|
-
# Appsignal.
|
817
|
-
#
|
818
|
-
#
|
819
|
-
# end
|
820
|
-
# # The session data is: { "data" => "value" }
|
566
|
+
# @example Add session data
|
567
|
+
# Appsignal.add_session_data("session" => "data")
|
568
|
+
# # The session data will include:
|
569
|
+
# # { "session" => "data" }
|
821
570
|
#
|
822
|
-
# @example Calling `
|
823
|
-
# Appsignal.
|
824
|
-
#
|
825
|
-
#
|
826
|
-
#
|
827
|
-
# # The session data is: { "argument" => "argument value" }
|
571
|
+
# @example Calling `add_session_data` multiple times merge the values
|
572
|
+
# Appsignal.add_session_data("session" => "data")
|
573
|
+
# Appsignal.add_session_data("other" => "value")
|
574
|
+
# # The session data will include:
|
575
|
+
# # { "session" => "data", "other" => "value" }
|
828
576
|
#
|
829
|
-
# @since
|
830
|
-
# @param session_data [Hash] The session data to
|
577
|
+
# @since 4.0.0
|
578
|
+
# @param session_data [Hash] The session data to add to the transaction.
|
831
579
|
# @yield This block is called when the transaction is sampled. The block's
|
832
580
|
# return value will become the new session data.
|
581
|
+
# @return [void]
|
582
|
+
#
|
833
583
|
# @see https://docs.appsignal.com/guides/custom-data/sample-data.html
|
834
584
|
# Sample data guide
|
835
585
|
# @see https://docs.appsignal.com/guides/filter-data/filter-session-data.html
|
836
586
|
# Session data filtering guide
|
837
|
-
# @see Transaction#
|
838
|
-
|
839
|
-
def set_session_data(session_data = nil, &block)
|
587
|
+
# @see Transaction#add_session_data
|
588
|
+
def add_session_data(session_data = nil, &block)
|
840
589
|
return unless active?
|
841
590
|
return unless Appsignal::Transaction.current?
|
842
591
|
|
843
592
|
transaction = Appsignal::Transaction.current
|
844
|
-
transaction.
|
593
|
+
transaction.add_session_data(session_data, &block)
|
845
594
|
end
|
595
|
+
alias :set_session_data :add_session_data
|
846
596
|
|
847
|
-
#
|
597
|
+
# Add request headers to the current transaction.
|
848
598
|
#
|
849
|
-
# Request headers are automatically
|
850
|
-
# should not be necessary to call this method unless you want to
|
851
|
-
# different request headers.
|
599
|
+
# Request headers are automatically added by most of our integrations. It
|
600
|
+
# should not be necessary to call this method unless you want to also
|
601
|
+
# report different request headers.
|
852
602
|
#
|
853
|
-
# To filter request headers, see our
|
854
|
-
#
|
855
|
-
# When this method is called multiple times, it will overwrite the
|
856
|
-
# previously set value.
|
857
|
-
#
|
858
|
-
# A block can be given to this method to defer the fetching and parsing
|
859
|
-
# of the request headers until and only when the transaction is sampled.
|
603
|
+
# To filter request headers, see our request header filtering guide.
|
860
604
|
#
|
861
605
|
# When both the `request_headers` argument and a block is given to this
|
862
|
-
# method, the
|
863
|
-
# _not_ be called.
|
864
|
-
#
|
865
|
-
# @example Set request headers
|
866
|
-
# Appsignal.set_headers(
|
867
|
-
# "PATH_INFO" => "/some-path",
|
868
|
-
# "HTTP_USER_AGENT" => "Firefox"
|
869
|
-
# )
|
606
|
+
# method, the block is leading and the argument will _not_ be used.
|
870
607
|
#
|
871
|
-
# @example
|
872
|
-
# Appsignal.
|
873
|
-
#
|
874
|
-
# #
|
608
|
+
# @example Add request headers
|
609
|
+
# Appsignal.add_headers("PATH_INFO" => "/some-path")
|
610
|
+
# # The request headers will include:
|
611
|
+
# # { "PATH_INFO" => "/some-path" }
|
875
612
|
#
|
876
|
-
# @example Calling `
|
877
|
-
# Appsignal.
|
878
|
-
#
|
879
|
-
#
|
880
|
-
#
|
881
|
-
# # The session data is: { "PATH_INFO" => "/some-path" }
|
882
|
-
#
|
883
|
-
# @example Calling `set_headers` with a headers argument and a block
|
884
|
-
# Appsignal.set_headers("PATH_INFO" => "/some-path") do
|
885
|
-
# # Some slow code to parse session data
|
886
|
-
# JSON.parse('{"PATH_INFO": "/block-path"}')
|
887
|
-
# end
|
888
|
-
# # The session data is: { "PATH_INFO" => "/some-path" }
|
613
|
+
# @example Calling `add_headers` multiple times merge the values
|
614
|
+
# Appsignal.add_headers("PATH_INFO" => "/some-path")
|
615
|
+
# Appsignal.add_headers("HTTP_USER_AGENT" => "Firefox")
|
616
|
+
# # The request headers will include:
|
617
|
+
# # { "PATH_INFO" => "/some-path", "HTTP_USER_AGENT" => "Firefox" }
|
889
618
|
#
|
890
|
-
# @since
|
891
|
-
# @param headers [Hash] The request headers to
|
619
|
+
# @since 4.0.0
|
620
|
+
# @param headers [Hash] The request headers to add to the transaction.
|
892
621
|
# @yield This block is called when the transaction is sampled. The block's
|
893
622
|
# return value will become the new request headers.
|
623
|
+
# @return [void]
|
624
|
+
#
|
894
625
|
# @see https://docs.appsignal.com/guides/custom-data/sample-data.html
|
895
626
|
# Sample data guide
|
896
627
|
# @see https://docs.appsignal.com/guides/filter-data/filter-headers.html
|
897
628
|
# Request headers filtering guide
|
898
|
-
# @see Transaction#
|
899
|
-
|
900
|
-
def set_headers(headers = nil, &block)
|
629
|
+
# @see Transaction#add_headers
|
630
|
+
def add_headers(headers = nil, &block)
|
901
631
|
return unless active?
|
902
632
|
return unless Appsignal::Transaction.current?
|
903
633
|
|
904
634
|
transaction = Appsignal::Transaction.current
|
905
|
-
transaction.
|
635
|
+
transaction.add_headers(headers, &block)
|
906
636
|
end
|
637
|
+
alias :set_headers :add_headers
|
907
638
|
|
908
639
|
# Add breadcrumbs to the transaction.
|
909
640
|
#
|
@@ -1076,15 +807,6 @@ module Appsignal
|
|
1076
807
|
ensure
|
1077
808
|
Appsignal::Transaction.current&.resume!
|
1078
809
|
end
|
1079
|
-
|
1080
|
-
# @deprecated Use {.ignore_instrumentation_events} instead.
|
1081
|
-
# @since 0.8.7
|
1082
|
-
def without_instrumentation(&block)
|
1083
|
-
stdout_and_logger_warning \
|
1084
|
-
"The `Appsignal.without_instrumentation` helper is deprecated. " \
|
1085
|
-
"Please use `Appsignal.ignore_instrumentation_events` instead."
|
1086
|
-
ignore_instrumentation_events(&block)
|
1087
|
-
end
|
1088
810
|
end
|
1089
811
|
end
|
1090
812
|
end
|