Skip to content

Commit f9f7e86

Browse files
ErvalhouSpicandocodigo
authored andcommitted
Refactor consumer transaction outcome
1 parent 3d74b19 commit f9f7e86

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

lib/elastic_apm/spies/racecar.rb

+9-10
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,15 @@ def start_process_message(event)
3434
start_process_transaction(event: event, kind: 'process_message')
3535
end
3636
def process_message(event)
37-
transaction = ElasticAPM.current_transaction
38-
error_present = !event.payload[:unrecoverable_delivery_error].nil?
39-
transaction.outcome = error_present ? Transaction::Outcome::FAILURE : Transaction::Outcome::SUCCESS
40-
transaction.done(error_present ? :error : :success)
41-
37+
record_outcome(event: event)
4238
ElasticAPM.end_transaction
4339
end
4440

4541
def start_process_batch(event)
4642
start_process_transaction(event: event, kind: 'process_batch')
4743
end
4844
def process_batch(event)
49-
transaction = ElasticAPM.current_transaction
50-
error_present = !event.payload[:unrecoverable_delivery_error].nil?
51-
transaction.outcome = error_present ? Transaction::Outcome::FAILURE : Transaction::Outcome::SUCCESS
52-
transaction.done(error_present ? :error : :success)
53-
45+
record_outcome(event: event)
5446
ElasticAPM.end_transaction
5547
end
5648

@@ -60,6 +52,13 @@ def start_process_transaction(event:, kind:)
6052
ElasticAPM.start_transaction("#{event.payload[:consumer_class]}##{kind}", TYPE)
6153
ElasticAPM.current_transaction.context.set_service(framework_name: 'racecar', framework_version: Racecar::VERSION)
6254
end
55+
56+
def record_outcome(event:)
57+
transaction = ElasticAPM.current_transaction
58+
error_present = !event.payload[:unrecoverable_delivery_error].nil?
59+
transaction.outcome = error_present ? Transaction::Outcome::FAILURE : Transaction::Outcome::SUCCESS
60+
transaction.done(error_present ? :error : :success)
61+
end
6362
end
6463

6564
class ProducerSubscriber < ActiveSupport::Subscriber

0 commit comments

Comments
 (0)