24
24
require 'racecar'
25
25
module ElasticAPM
26
26
RSpec . describe 'Spy: Racecar' , :intercept do
27
+ let ( :instrumentation_payload ) {
28
+ { consumer_class : 'SpecConsumer' ,
29
+ topic : 'spec_topic' ,
30
+ partition : '0' ,
31
+ offset : '1' ,
32
+ create_time : Time . now ,
33
+ key : '1' ,
34
+ value : { key : 'value' } ,
35
+ headers : { key : 'value' } }
36
+ }
27
37
it 'captures the instrumentation' do
28
38
with_agent do
29
- instrumentation_payload = {
30
- consumer_class : 'SpecConsumer' ,
31
- topic : 'spec_topic' ,
32
- partition : '0' ,
33
- offset : '1' ,
34
- create_time : Time . now ,
35
- key : '1' ,
36
- value : { key : 'value' } ,
37
- headers : { key : 'value' }
38
- }
39
39
ActiveSupport ::Notifications . instrument ( 'start_process_message.racecar' , instrumentation_payload )
40
40
ActiveSupport ::Notifications . instrument ( 'process_message.racecar' , instrumentation_payload ) do
41
41
# this is the body of the racecar consumer #process method
@@ -47,6 +47,41 @@ module ElasticAPM
47
47
expect ( first_transaction . context . service . framework . name ) . to eq ( 'racecar' )
48
48
end
49
49
end
50
+
51
+ describe 'transaction outcome' do
52
+ it 'records success when no delivery error happen' do
53
+ with_agent do
54
+ ActiveSupport ::Notifications . instrument ( 'start_process_message.racecar' , instrumentation_payload )
55
+ ActiveSupport ::Notifications . instrument ( 'process_message.racecar' , instrumentation_payload ) do
56
+ # this is the body of the racecar consumer #process method
57
+ end
58
+ first_transaction = @intercepted . transactions . first
59
+ expect ( first_transaction . outcome ) . to eq ( Transaction ::Outcome ::SUCCESS )
60
+ end
61
+ end
62
+ it 'records failure when with a unrecoverable delivery error' do
63
+ instrumentation_payload [ :unrecoverable_delivery_error ] = true
64
+ with_agent do
65
+ ActiveSupport ::Notifications . instrument ( 'start_process_message.racecar' , instrumentation_payload )
66
+ ActiveSupport ::Notifications . instrument ( 'process_message.racecar' , instrumentation_payload ) do
67
+ # this is the body of the racecar consumer #process method
68
+ end
69
+ first_transaction = @intercepted . transactions . first
70
+ expect ( first_transaction . outcome ) . to eq ( Transaction ::Outcome ::FAILURE )
71
+ end
72
+ end
73
+ it 'records failure when with a recoverable delivery error' do
74
+ instrumentation_payload [ :unrecoverable_delivery_error ] = false
75
+ with_agent do
76
+ ActiveSupport ::Notifications . instrument ( 'start_process_message.racecar' , instrumentation_payload )
77
+ ActiveSupport ::Notifications . instrument ( 'process_message.racecar' , instrumentation_payload ) do
78
+ # this is the body of the racecar consumer #process method
79
+ end
80
+ first_transaction = @intercepted . transactions . first
81
+ expect ( first_transaction . outcome ) . to eq ( Transaction ::Outcome ::FAILURE )
82
+ end
83
+ end
84
+ end
50
85
end
51
86
end
52
87
0 commit comments