appsignal 3.12.6-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 +151 -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 +67 -0
- data/lib/appsignal/check_in.rb +46 -0
- 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 -414
- 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/http.rb +2 -7
- 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 +20 -62
- 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/{heartbeat_spec.rb → check_in_spec.rb} +45 -36
- 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/http_spec.rb +0 -21
- 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 +14 -23
- data/gemfiles/que_beta.gemfile +0 -5
- data/lib/appsignal/heartbeat.rb +0 -59
- data/lib/appsignal/helpers/heartbeats.rb +0 -44
- 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,170 +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
|
-
#
|
304
|
-
# @param tags [Hash, nil]
|
305
|
-
# @param namespace [String] the namespace for this error.
|
306
|
-
# @yield yields the given block.
|
307
|
-
# @return [Object] returns the return value of the given block.
|
308
|
-
def listen_for_error(
|
309
|
-
tags = nil,
|
310
|
-
namespace = Appsignal::Transaction::HTTP_REQUEST
|
311
|
-
)
|
312
|
-
stdout_and_logger_warning \
|
313
|
-
"The `Appsignal.listen_for_error` helper is deprecated. " \
|
314
|
-
"Please use `rescue => error` and `Appsignal.report_error` instead. " \
|
315
|
-
"Read our exception handling documentation: " \
|
316
|
-
"https://docs.appsignal.com/ruby/instrumentation/exception-handling.html"
|
317
|
-
yield
|
318
|
-
rescue Exception => error # rubocop:disable Lint/RescueException
|
319
|
-
send_error(error) do |transaction|
|
320
|
-
transaction.set_tags(tags) if tags
|
321
|
-
transaction.set_namespace(namespace) if namespace
|
322
|
-
end
|
323
|
-
raise error
|
324
|
-
end
|
325
|
-
alias :listen_for_exception :listen_for_error
|
326
|
-
|
327
161
|
# Send an error to AppSignal regardless of the context.
|
328
162
|
#
|
329
163
|
# Records and send the exception to AppSignal.
|
@@ -344,28 +178,15 @@ module Appsignal
|
|
344
178
|
# Appsignal.send_error(e)
|
345
179
|
# end
|
346
180
|
#
|
347
|
-
# @example Send an exception with tags. Deprecated method.
|
348
|
-
# begin
|
349
|
-
# raise "oh no!"
|
350
|
-
# rescue => e
|
351
|
-
# Appsignal.send_error(e, :key => "value")
|
352
|
-
# end
|
353
|
-
#
|
354
181
|
# @example Add more metadata to transaction
|
355
|
-
# Appsignal.send_error(e) do
|
356
|
-
#
|
357
|
-
#
|
358
|
-
#
|
359
|
-
#
|
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")
|
360
187
|
# end
|
361
188
|
#
|
362
189
|
# @param error [Exception] The error to send to AppSignal.
|
363
|
-
# @param tags [Hash{String, Symbol => String, Symbol, Integer}]
|
364
|
-
# Additional tags to add to the error. See also {.tag_request}.
|
365
|
-
# This parameter is deprecated. Use the block argument instead.
|
366
|
-
# @param namespace [String] The namespace in which the error occurred.
|
367
|
-
# See also {.set_namespace}.
|
368
|
-
# This parameter is deprecated. Use the block argument instead.
|
369
190
|
# @yield [transaction] yields block to allow modification of the
|
370
191
|
# transaction before it's send.
|
371
192
|
# @yieldparam transaction [Transaction] yields the AppSignal transaction
|
@@ -378,31 +199,7 @@ module Appsignal
|
|
378
199
|
# @see https://docs.appsignal.com/ruby/instrumentation/tagging.html
|
379
200
|
# Tagging guide
|
380
201
|
# @since 0.6.0
|
381
|
-
def send_error(
|
382
|
-
error,
|
383
|
-
tags = nil,
|
384
|
-
namespace = nil
|
385
|
-
)
|
386
|
-
if tags
|
387
|
-
call_location = caller(1..1).first
|
388
|
-
stdout_and_logger_warning \
|
389
|
-
"The tags argument for `Appsignal.send_error` is deprecated. " \
|
390
|
-
"Please use the block method to set tags instead.\n\n" \
|
391
|
-
" Appsignal.send_error(error) do |transaction|\n" \
|
392
|
-
" transaction.set_tags(#{tags})\n" \
|
393
|
-
" end\n\n" \
|
394
|
-
"Appsignal.send_error called on location: #{call_location}"
|
395
|
-
end
|
396
|
-
if namespace
|
397
|
-
call_location = caller(1..1).first
|
398
|
-
stdout_and_logger_warning \
|
399
|
-
"The namespace argument for `Appsignal.send_error` is deprecated. " \
|
400
|
-
"Please use the block method to set the namespace instead.\n\n" \
|
401
|
-
" Appsignal.send_error(error) do |transaction|\n" \
|
402
|
-
" transaction.set_namespace(#{namespace.inspect})\n" \
|
403
|
-
" end\n\n" \
|
404
|
-
"Appsignal.send_error called on location: #{call_location}"
|
405
|
-
end
|
202
|
+
def send_error(error, &block)
|
406
203
|
return unless active?
|
407
204
|
|
408
205
|
unless error.is_a?(Exception)
|
@@ -410,13 +207,13 @@ module Appsignal
|
|
410
207
|
"The given value is not an exception: #{error.inspect}"
|
411
208
|
return
|
412
209
|
end
|
210
|
+
|
413
211
|
transaction = Appsignal::Transaction.new(
|
414
212
|
SecureRandom.uuid,
|
415
|
-
|
213
|
+
Appsignal::Transaction::HTTP_REQUEST
|
416
214
|
)
|
417
|
-
transaction.
|
418
|
-
|
419
|
-
yield transaction if block_given?
|
215
|
+
transaction.set_error(error, &block)
|
216
|
+
|
420
217
|
transaction.complete
|
421
218
|
end
|
422
219
|
alias :send_exception :send_error
|
@@ -449,21 +246,15 @@ module Appsignal
|
|
449
246
|
# end
|
450
247
|
#
|
451
248
|
# @example Add more metadata to transaction
|
452
|
-
# Appsignal.set_error(e) do
|
453
|
-
#
|
454
|
-
#
|
455
|
-
#
|
456
|
-
#
|
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")
|
457
254
|
# end
|
458
255
|
#
|
459
256
|
# @param exception [Exception] The error to add to the current
|
460
257
|
# transaction.
|
461
|
-
# @param tags [Hash{String, Symbol => String, Symbol, Integer}]
|
462
|
-
# Additional tags to add to the error. See also {.tag_request}.
|
463
|
-
# This parameter is deprecated. Use the block argument instead.
|
464
|
-
# @param namespace [String] The namespace in which the error occurred.
|
465
|
-
# See also {.set_namespace}.
|
466
|
-
# This parameter is deprecated. Use the block argument instead.
|
467
258
|
# @yield [transaction] yields block to allow modification of the
|
468
259
|
# transaction.
|
469
260
|
# @yieldparam transaction [Transaction] yields the AppSignal transaction
|
@@ -475,27 +266,7 @@ module Appsignal
|
|
475
266
|
# @see https://docs.appsignal.com/ruby/instrumentation/exception-handling.html
|
476
267
|
# Exception handling guide
|
477
268
|
# @since 0.6.6
|
478
|
-
def set_error(exception
|
479
|
-
if tags
|
480
|
-
call_location = caller(1..1).first
|
481
|
-
stdout_and_logger_warning \
|
482
|
-
"The tags argument for `Appsignal.set_error` is deprecated. " \
|
483
|
-
"Please use the block method to set tags instead.\n\n" \
|
484
|
-
" Appsignal.set_error(error) do |transaction|\n" \
|
485
|
-
" transaction.set_tags(#{tags})\n" \
|
486
|
-
" end\n\n" \
|
487
|
-
"Appsignal.set_error called on location: #{call_location}"
|
488
|
-
end
|
489
|
-
if namespace
|
490
|
-
call_location = caller(1..1).first
|
491
|
-
stdout_and_logger_warning \
|
492
|
-
"The namespace argument for `Appsignal.set_error` is deprecated. " \
|
493
|
-
"Please use the block method to set the namespace instead.\n\n" \
|
494
|
-
" Appsignal.set_error(error) do |transaction|\n" \
|
495
|
-
" transaction.set_namespace(#{namespace.inspect})\n" \
|
496
|
-
" end\n\n" \
|
497
|
-
"Appsignal.set_error called on location: #{call_location}"
|
498
|
-
end
|
269
|
+
def set_error(exception)
|
499
270
|
unless exception.is_a?(Exception)
|
500
271
|
internal_logger.error "Appsignal.set_error: Cannot set error. " \
|
501
272
|
"The given value is not an exception: #{exception.inspect}"
|
@@ -505,8 +276,6 @@ module Appsignal
|
|
505
276
|
|
506
277
|
transaction = Appsignal::Transaction.current
|
507
278
|
transaction.set_error(exception)
|
508
|
-
transaction.set_tags(tags) if tags
|
509
|
-
transaction.set_namespace(namespace) if namespace
|
510
279
|
yield transaction if block_given?
|
511
280
|
end
|
512
281
|
alias :set_exception :set_error
|
@@ -533,11 +302,11 @@ module Appsignal
|
|
533
302
|
# end
|
534
303
|
#
|
535
304
|
# @example Add more metadata to transaction
|
536
|
-
# Appsignal.report_error(error) do
|
537
|
-
#
|
538
|
-
#
|
539
|
-
#
|
540
|
-
#
|
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")
|
541
310
|
# end
|
542
311
|
#
|
543
312
|
# @param exception [Exception] The error to add to the current
|
@@ -551,9 +320,9 @@ module Appsignal
|
|
551
320
|
# @see https://docs.appsignal.com/ruby/instrumentation/exception-handling.html
|
552
321
|
# Exception handling guide
|
553
322
|
# @since 3.10.0
|
554
|
-
def report_error(exception)
|
323
|
+
def report_error(exception, &block)
|
555
324
|
unless exception.is_a?(Exception)
|
556
|
-
internal_logger.error "Appsignal.report_error: Cannot
|
325
|
+
internal_logger.error "Appsignal.report_error: Cannot add error. " \
|
557
326
|
"The given value is not an exception: #{exception.inspect}"
|
558
327
|
return
|
559
328
|
end
|
@@ -570,12 +339,9 @@ module Appsignal
|
|
570
339
|
)
|
571
340
|
end
|
572
341
|
|
573
|
-
transaction.
|
574
|
-
yield transaction if block_given?
|
575
|
-
|
576
|
-
return if has_parent_transaction
|
342
|
+
transaction.add_error(exception, &block)
|
577
343
|
|
578
|
-
transaction.complete
|
344
|
+
transaction.complete unless has_parent_transaction
|
579
345
|
end
|
580
346
|
alias :report_exception :report_error
|
581
347
|
|
@@ -649,36 +415,56 @@ module Appsignal
|
|
649
415
|
Appsignal::Transaction.current.set_namespace(namespace)
|
650
416
|
end
|
651
417
|
|
652
|
-
#
|
418
|
+
# Add custom data to the current transaction.
|
653
419
|
#
|
654
420
|
# Add extra information about the request or background that cannot be
|
655
421
|
# expressed in tags, like nested data structures.
|
656
422
|
#
|
657
|
-
#
|
658
|
-
#
|
423
|
+
# If the root data type changes between calls of this method, the last
|
424
|
+
# method call is stored.
|
659
425
|
#
|
660
|
-
# @example
|
661
|
-
# Appsignal.
|
662
|
-
#
|
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([
|
663
436
|
# "array with data",
|
437
|
+
# "other value",
|
664
438
|
# :options => { :verbose => true }
|
665
439
|
# ])
|
666
440
|
#
|
667
|
-
# @
|
668
|
-
#
|
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
|
669
456
|
# @see https://docs.appsignal.com/guides/custom-data/sample-data.html
|
670
457
|
# Sample data guide
|
671
|
-
|
672
|
-
# @return [void]
|
673
|
-
def set_custom_data(data)
|
458
|
+
def add_custom_data(data)
|
674
459
|
return unless active?
|
675
460
|
return unless Appsignal::Transaction.current?
|
676
461
|
|
677
462
|
transaction = Appsignal::Transaction.current
|
678
|
-
transaction.
|
463
|
+
transaction.add_custom_data(data)
|
679
464
|
end
|
465
|
+
alias :set_custom_data :add_custom_data
|
680
466
|
|
681
|
-
#
|
467
|
+
# Add tags to the current transaction.
|
682
468
|
#
|
683
469
|
# Tags are extra bits of information that are added to transaction and
|
684
470
|
# appear on sample details pages on AppSignal.com.
|
@@ -686,221 +472,169 @@ module Appsignal
|
|
686
472
|
# When this method is called multiple times, it will merge the tags.
|
687
473
|
#
|
688
474
|
# @example
|
689
|
-
# Appsignal.
|
690
|
-
# Appsignal.
|
691
|
-
# Appsignal.
|
475
|
+
# Appsignal.add_tags(:locale => "en", :user_id => 1)
|
476
|
+
# Appsignal.add_tags("locale" => "en")
|
477
|
+
# Appsignal.add_tags("user_id" => 1)
|
692
478
|
#
|
693
479
|
# @example Nested hashes are not supported
|
694
480
|
# # Bad
|
695
|
-
# Appsignal.
|
481
|
+
# Appsignal.add_tags(:user => { :locale => "en" })
|
696
482
|
#
|
697
483
|
# @example in a Rails controller
|
698
484
|
# class SomeController < ApplicationController
|
699
|
-
# before_action :
|
485
|
+
# before_action :add_appsignal_tags
|
700
486
|
#
|
701
|
-
# def
|
702
|
-
# Appsignal.
|
487
|
+
# def add_appsignal_tags
|
488
|
+
# Appsignal.add_tags(:locale => I18n.locale)
|
703
489
|
# end
|
704
490
|
# end
|
705
491
|
#
|
706
|
-
# @
|
492
|
+
# @since 4.0.0
|
493
|
+
# @param tags [Hash] Collection of tags to add to the transaction.
|
707
494
|
# @option tags [String, Symbol, Integer] :any
|
708
495
|
# The name of the tag as a Symbol.
|
709
496
|
# @option tags [String, Symbol, Integer] "any"
|
710
497
|
# The name of the tag as a String.
|
711
498
|
# @return [void]
|
712
499
|
#
|
713
|
-
# @see Transaction
|
500
|
+
# @see Transaction#add_tags
|
714
501
|
# @see https://docs.appsignal.com/ruby/instrumentation/tagging.html
|
715
502
|
# Tagging guide
|
716
|
-
def
|
503
|
+
def add_tags(tags = {})
|
717
504
|
return unless active?
|
718
505
|
return unless Appsignal::Transaction.current?
|
719
506
|
|
720
507
|
transaction = Appsignal::Transaction.current
|
721
|
-
transaction.
|
508
|
+
transaction.add_tags(tags)
|
722
509
|
end
|
723
|
-
alias :
|
724
|
-
alias :
|
510
|
+
alias :tag_request :add_tags
|
511
|
+
alias :tag_job :add_tags
|
512
|
+
alias :set_tags :add_tags
|
725
513
|
|
726
|
-
#
|
514
|
+
# Add parameters to the current transaction.
|
727
515
|
#
|
728
|
-
# Parameters are automatically
|
729
|
-
# 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
|
730
518
|
# different parameters.
|
731
519
|
#
|
732
520
|
# To filter parameters, see our parameter filtering guide.
|
733
521
|
#
|
734
|
-
# When this method is called multiple times, it will overwrite the
|
735
|
-
# previously set value.
|
736
|
-
#
|
737
|
-
# When no parameters are set this way, the transaction will look for
|
738
|
-
# parameters in its request environment.
|
739
|
-
#
|
740
|
-
# A block can be given to this method to defer the fetching and parsing
|
741
|
-
# of the parameters until and only when the transaction is sampled.
|
742
|
-
#
|
743
522
|
# When both the `params` argument and a block is given to this method,
|
744
|
-
# the
|
523
|
+
# the block is leading and the argument will _not_ be used.
|
745
524
|
#
|
746
|
-
# @example
|
747
|
-
# Appsignal.
|
525
|
+
# @example Add parameters
|
526
|
+
# Appsignal.add_params("param1" => "value1")
|
527
|
+
# # The parameters include: { "param1" => "value1" }
|
748
528
|
#
|
749
|
-
# @example Calling `
|
750
|
-
# Appsignal.
|
751
|
-
# Appsignal.
|
752
|
-
# # The parameters
|
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" }
|
753
534
|
#
|
754
|
-
# @
|
755
|
-
#
|
756
|
-
# # Some slow code to parse parameters
|
757
|
-
# JSON.parse('{"param1": "value1"}')
|
758
|
-
# end
|
759
|
-
# # The parameters are: { "param1" => "value1" }
|
760
|
-
#
|
761
|
-
# @example Calling `set_params` with a parameter and a block
|
762
|
-
# Appsignal.set_params("argument" => "argument value") do
|
763
|
-
# # Some slow code to parse parameters
|
764
|
-
# JSON.parse('{"param1": "value1"}')
|
765
|
-
# end
|
766
|
-
# # The parameters are: { "argument" => "argument value" }
|
767
|
-
#
|
768
|
-
# @since 3.10.0
|
769
|
-
# @param params [Hash] The parameters to set on the transaction.
|
535
|
+
# @since 4.0.0
|
536
|
+
# @param params [Hash] The parameters to add to the transaction.
|
770
537
|
# @yield This block is called when the transaction is sampled. The block's
|
771
538
|
# return value will become the new parameters.
|
539
|
+
# @return [void]
|
540
|
+
#
|
772
541
|
# @see https://docs.appsignal.com/guides/custom-data/sample-data.html
|
773
542
|
# Sample data guide
|
774
543
|
# @see https://docs.appsignal.com/guides/filter-data/filter-parameters.html
|
775
544
|
# Parameter filtering guide
|
776
|
-
# @see Transaction#
|
777
|
-
|
778
|
-
def set_params(params = nil, &block)
|
545
|
+
# @see Transaction#add_params
|
546
|
+
def add_params(params = nil, &block)
|
779
547
|
return unless active?
|
780
548
|
return unless Appsignal::Transaction.current?
|
781
549
|
|
782
550
|
transaction = Appsignal::Transaction.current
|
783
|
-
transaction.
|
551
|
+
transaction.add_params(params, &block)
|
784
552
|
end
|
553
|
+
alias :set_params :add_params
|
785
554
|
|
786
|
-
#
|
555
|
+
# Add session data to the current transaction.
|
787
556
|
#
|
788
|
-
# Session data is automatically
|
557
|
+
# Session data is automatically added by most of our integrations. It
|
789
558
|
# should not be necessary to call this method unless you want to report
|
790
559
|
# different session data.
|
791
560
|
#
|
792
561
|
# To filter session data, see our session data filtering guide.
|
793
562
|
#
|
794
|
-
# When this method is called multiple times, it will overwrite the
|
795
|
-
# previously set value.
|
796
|
-
#
|
797
|
-
# A block can be given to this method to defer the fetching and parsing
|
798
|
-
# of the session data until and only when the transaction is sampled.
|
799
|
-
#
|
800
563
|
# When both the `session_data` argument and a block is given to this
|
801
|
-
# method, the
|
802
|
-
# be called.
|
564
|
+
# method, the bock is leading and the argument will _not_ be used.
|
803
565
|
#
|
804
|
-
# @example
|
805
|
-
# Appsignal.
|
566
|
+
# @example Add session data
|
567
|
+
# Appsignal.add_session_data("session" => "data")
|
568
|
+
# # The session data will include:
|
569
|
+
# # { "session" => "data" }
|
806
570
|
#
|
807
|
-
# @example Calling `
|
808
|
-
# Appsignal.
|
809
|
-
# Appsignal.
|
810
|
-
# # The session data
|
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" }
|
811
576
|
#
|
812
|
-
# @
|
813
|
-
#
|
814
|
-
# # Some slow code to parse session data
|
815
|
-
# JSON.parse('{"data": "value"}')
|
816
|
-
# end
|
817
|
-
# # The session data is: { "data" => "value" }
|
818
|
-
#
|
819
|
-
# @example Calling `set_session_data` with a session_data argument and a block
|
820
|
-
# Appsignal.set_session_data("argument" => "argument value") do
|
821
|
-
# # Some slow code to parse session data
|
822
|
-
# JSON.parse('{"data": "value"}')
|
823
|
-
# end
|
824
|
-
# # The session data is: { "argument" => "argument value" }
|
825
|
-
#
|
826
|
-
# @since 3.11.0
|
827
|
-
# @param session_data [Hash] The session data to set on the transaction.
|
577
|
+
# @since 4.0.0
|
578
|
+
# @param session_data [Hash] The session data to add to the transaction.
|
828
579
|
# @yield This block is called when the transaction is sampled. The block's
|
829
580
|
# return value will become the new session data.
|
581
|
+
# @return [void]
|
582
|
+
#
|
830
583
|
# @see https://docs.appsignal.com/guides/custom-data/sample-data.html
|
831
584
|
# Sample data guide
|
832
585
|
# @see https://docs.appsignal.com/guides/filter-data/filter-session-data.html
|
833
586
|
# Session data filtering guide
|
834
|
-
# @see Transaction#
|
835
|
-
|
836
|
-
def set_session_data(session_data = nil, &block)
|
587
|
+
# @see Transaction#add_session_data
|
588
|
+
def add_session_data(session_data = nil, &block)
|
837
589
|
return unless active?
|
838
590
|
return unless Appsignal::Transaction.current?
|
839
591
|
|
840
592
|
transaction = Appsignal::Transaction.current
|
841
|
-
transaction.
|
593
|
+
transaction.add_session_data(session_data, &block)
|
842
594
|
end
|
595
|
+
alias :set_session_data :add_session_data
|
843
596
|
|
844
|
-
#
|
845
|
-
#
|
846
|
-
# Request headers are automatically set by most of our integrations. It
|
847
|
-
# should not be necessary to call this method unless you want to report
|
848
|
-
# different request headers.
|
849
|
-
#
|
850
|
-
# To filter request headers, see our session data filtering guide.
|
597
|
+
# Add request headers to the current transaction.
|
851
598
|
#
|
852
|
-
#
|
853
|
-
#
|
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.
|
854
602
|
#
|
855
|
-
#
|
856
|
-
# of the request headers until and only when the transaction is sampled.
|
603
|
+
# To filter request headers, see our request header filtering guide.
|
857
604
|
#
|
858
605
|
# When both the `request_headers` argument and a block is given to this
|
859
|
-
# method, the
|
860
|
-
# _not_ be called.
|
861
|
-
#
|
862
|
-
# @example Set request headers
|
863
|
-
# Appsignal.set_headers(
|
864
|
-
# "PATH_INFO" => "/some-path",
|
865
|
-
# "HTTP_USER_AGENT" => "Firefox"
|
866
|
-
# )
|
606
|
+
# method, the block is leading and the argument will _not_ be used.
|
867
607
|
#
|
868
|
-
# @example
|
869
|
-
# Appsignal.
|
870
|
-
#
|
871
|
-
# #
|
608
|
+
# @example Add request headers
|
609
|
+
# Appsignal.add_headers("PATH_INFO" => "/some-path")
|
610
|
+
# # The request headers will include:
|
611
|
+
# # { "PATH_INFO" => "/some-path" }
|
872
612
|
#
|
873
|
-
# @example Calling `
|
874
|
-
# Appsignal.
|
875
|
-
#
|
876
|
-
#
|
877
|
-
#
|
878
|
-
# # The session data is: { "PATH_INFO" => "/some-path" }
|
879
|
-
#
|
880
|
-
# @example Calling `set_headers` with a headers argument and a block
|
881
|
-
# Appsignal.set_headers("PATH_INFO" => "/some-path") do
|
882
|
-
# # Some slow code to parse session data
|
883
|
-
# JSON.parse('{"PATH_INFO": "/block-path"}')
|
884
|
-
# end
|
885
|
-
# # 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" }
|
886
618
|
#
|
887
|
-
# @since
|
888
|
-
# @param headers [Hash] The request headers to
|
619
|
+
# @since 4.0.0
|
620
|
+
# @param headers [Hash] The request headers to add to the transaction.
|
889
621
|
# @yield This block is called when the transaction is sampled. The block's
|
890
622
|
# return value will become the new request headers.
|
623
|
+
# @return [void]
|
624
|
+
#
|
891
625
|
# @see https://docs.appsignal.com/guides/custom-data/sample-data.html
|
892
626
|
# Sample data guide
|
893
627
|
# @see https://docs.appsignal.com/guides/filter-data/filter-headers.html
|
894
628
|
# Request headers filtering guide
|
895
|
-
# @see Transaction#
|
896
|
-
|
897
|
-
def set_headers(headers = nil, &block)
|
629
|
+
# @see Transaction#add_headers
|
630
|
+
def add_headers(headers = nil, &block)
|
898
631
|
return unless active?
|
899
632
|
return unless Appsignal::Transaction.current?
|
900
633
|
|
901
634
|
transaction = Appsignal::Transaction.current
|
902
|
-
transaction.
|
635
|
+
transaction.add_headers(headers, &block)
|
903
636
|
end
|
637
|
+
alias :set_headers :add_headers
|
904
638
|
|
905
639
|
# Add breadcrumbs to the transaction.
|
906
640
|
#
|
@@ -1073,15 +807,6 @@ module Appsignal
|
|
1073
807
|
ensure
|
1074
808
|
Appsignal::Transaction.current&.resume!
|
1075
809
|
end
|
1076
|
-
|
1077
|
-
# @deprecated Use {.ignore_instrumentation_events} instead.
|
1078
|
-
# @since 0.8.7
|
1079
|
-
def without_instrumentation(&block)
|
1080
|
-
stdout_and_logger_warning \
|
1081
|
-
"The `Appsignal.without_instrumentation` helper is deprecated. " \
|
1082
|
-
"Please use `Appsignal.ignore_instrumentation_events` instead."
|
1083
|
-
ignore_instrumentation_events(&block)
|
1084
|
-
end
|
1085
810
|
end
|
1086
811
|
end
|
1087
812
|
end
|