File tree Expand file tree Collapse file tree 3 files changed +73
-0
lines changed Expand file tree Collapse file tree 3 files changed +73
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ module API
13
13
require_relative './sdk/tracing'
14
14
require_relative './sdk/custom_metrics'
15
15
require_relative './sdk/current_trace'
16
+ require_relative './sdk/logging' # to make sure it is loaded <- not very elegant
16
17
17
18
extend AppOpticsAPM ::SDK ::Tracing
18
19
extend AppOpticsAPM ::SDK ::CustomMetrics
Original file line number Diff line number Diff line change
1
+ # Copyright (c) 2019 SolarWinds, LLC.
2
+ # All rights reserved.
3
+ #
4
+
5
+ module AppOpticsAPM
6
+ module SDK
7
+ module Logging
8
+
9
+ # Log an information event in the current span
10
+ #
11
+ # a possible use-case is to collect extra information during the execution of a request
12
+ #
13
+ # === Arguments:
14
+ # * +opts+ - (optional) hash containing key/value pairs that will be reported with this span.
15
+ #
16
+ def log_info ( opts )
17
+ AppOpticsAPM ::API . log_info ( AppOpticsAPM . layer , opts )
18
+ end
19
+
20
+ # Log an exception/error event in the current span
21
+ #
22
+ # this may be helpful to track problems while rescuing an exception
23
+ #
24
+ # === Arguments:
25
+ # * +exception+ - an exception, must respond to :message and :backtrace
26
+ # * +opts+ - (optional) hash containing key/value pairs that will be reported with this span.
27
+ #
28
+ def log_exception ( exception , opts )
29
+ AppOpticsAPM ::API . log_exception ( AppOpticsAPM . layer , exception , opts )
30
+ end
31
+
32
+ end
33
+
34
+ extend Logging
35
+
36
+ end
37
+ end
Original file line number Diff line number Diff line change @@ -409,6 +409,41 @@ def computation_with_appoptics(n)
409
409
end
410
410
end
411
411
412
+ describe 'log events' do
413
+ before do
414
+ clear_all_traces
415
+ end
416
+
417
+ after do
418
+ clear_all_traces
419
+ AppOpticsAPM ::Context . clear
420
+ end
421
+
422
+ it 'SDK should log exceptions' do
423
+ AppOpticsAPM ::SDK . start_trace ( 'test_01' ) do
424
+ AppOpticsAPM ::SDK . log_exception ( StandardError . new , { the : 'exception' } )
425
+ end
426
+
427
+ traces = get_all_traces
428
+ traces . size == 3
429
+
430
+ traces [ 1 ] [ 'Label' ] . must_equal 'error'
431
+ traces [ 1 ] [ 'the' ] . must_equal 'exception'
432
+ end
433
+
434
+ it 'SDK should log info' do
435
+ AppOpticsAPM ::SDK . start_trace ( 'test_01' ) do
436
+ AppOpticsAPM ::SDK . log_info ( { the : 'information' } )
437
+ end
438
+
439
+ traces = get_all_traces
440
+ traces . size == 3
441
+
442
+ traces [ 1 ] [ 'Label' ] . must_equal 'info'
443
+ traces [ 1 ] [ 'the' ] . must_equal 'information'
444
+ end
445
+ end
446
+
412
447
describe 'set_transaction_name' do
413
448
414
449
it 'should not set the transaction name if the arg is not a string or an empty string' do
You can’t perform that action at this time.
0 commit comments