Skip to content

Commit

Permalink
Refactor consumer transaction outcome
Browse files Browse the repository at this point in the history
  • Loading branch information
ErvalhouS authored and picandocodigo committed May 15, 2024
1 parent 3d74b19 commit f9f7e86
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions lib/elastic_apm/spies/racecar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,15 @@ def start_process_message(event)
start_process_transaction(event: event, kind: 'process_message')
end
def process_message(event)
transaction = ElasticAPM.current_transaction
error_present = !event.payload[:unrecoverable_delivery_error].nil?
transaction.outcome = error_present ? Transaction::Outcome::FAILURE : Transaction::Outcome::SUCCESS
transaction.done(error_present ? :error : :success)

record_outcome(event: event)
ElasticAPM.end_transaction
end

def start_process_batch(event)
start_process_transaction(event: event, kind: 'process_batch')
end
def process_batch(event)
transaction = ElasticAPM.current_transaction
error_present = !event.payload[:unrecoverable_delivery_error].nil?
transaction.outcome = error_present ? Transaction::Outcome::FAILURE : Transaction::Outcome::SUCCESS
transaction.done(error_present ? :error : :success)

record_outcome(event: event)
ElasticAPM.end_transaction
end

Expand All @@ -60,6 +52,13 @@ def start_process_transaction(event:, kind:)
ElasticAPM.start_transaction("#{event.payload[:consumer_class]}##{kind}", TYPE)
ElasticAPM.current_transaction.context.set_service(framework_name: 'racecar', framework_version: Racecar::VERSION)
end

def record_outcome(event:)
transaction = ElasticAPM.current_transaction
error_present = !event.payload[:unrecoverable_delivery_error].nil?
transaction.outcome = error_present ? Transaction::Outcome::FAILURE : Transaction::Outcome::SUCCESS
transaction.done(error_present ? :error : :success)
end
end

class ProducerSubscriber < ActiveSupport::Subscriber
Expand Down

0 comments on commit f9f7e86

Please sign in to comment.