Skip to content

Commit

Permalink
squash: add additional error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
arielvalentin committed Sep 28, 2023
1 parent 4c659cc commit ae8e4f2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def require_dependencies

def patch_activejob
::ActiveJob::Base.prepend(Patches::Base) unless ::ActiveJob::Base.ancestors.include?(Patches::Base)

Subscriber.install
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ module Base
def self.prepended(base)
base.class_eval do
attr_accessor :__otel_headers

around_perform do |_job, block|
block.call
rescue StandardError => e
begin
span = OpenTelemetry::Trace.current_span
span.record_exception(e)
span.status = OpenTelemetry::Trace::Status.error(e.message)
rescue StandardError => ignore
OpenTelemetry.handle_error(ignore)
end

raise e
end
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,20 @@
end
end

# describe 'exception handling' do
# it 'sets span status to error' do
# _{ ExceptionJob.perform_later }.must_raise StandardError, 'This job raises an exception'
# _(process_span.status.code).must_equal OpenTelemetry::Trace::Status::ERROR
# _(process_span.status.description).must_equal 'Unhandled exception of type: StandardError'
# end
describe 'exception handling' do
it 'sets span status to error' do
_ { ExceptionJob.perform_later }.must_raise StandardError, 'This job raises an exception'
_(process_span.status.code).must_equal OpenTelemetry::Trace::Status::ERROR
_(process_span.status.description).must_equal 'This job raises an exception'
end

# it 'records the exception' do
# _ { ExceptionJob.perform_now }.must_raise StandardError, 'This job raises an exception'
# _(process_span.events.first.name).must_equal 'exception'
# _(process_span.events.first.attributes['exception.type']).must_equal 'StandardError'
# _(process_span.events.first.attributes['exception.message']).must_equal 'This job raises an exception'
# end
# end
it 'records the exception' do
_ { ExceptionJob.perform_now }.must_raise StandardError, 'This job raises an exception'
_(process_span.events.first.name).must_equal 'exception'
_(process_span.events.first.attributes['exception.type']).must_equal 'StandardError'
_(process_span.events.first.attributes['exception.message']).must_equal 'This job raises an exception'
end
end

describe 'span kind' do
it 'sets correct span kinds for inline jobs' do
Expand Down

0 comments on commit ae8e4f2

Please sign in to comment.