Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,15 @@ def update(...)
end

def update!(...)
tracer.in_span("#{self.class}#update!") do
record_invalid = nil
result = tracer.in_span("#{self.class}#update!") do
super
rescue ::ActiveRecord::RecordInvalid => e
record_invalid = e
end
raise record_invalid if record_invalid

result
end

def update_column(...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ def create(...)
end

def create!(...)
tracer.in_span("#{self}.create!") do
record_invalid = nil
result = tracer.in_span("#{self}.create!") do
super
rescue ::ActiveRecord::RecordInvalid => e
record_invalid = e
end
raise record_invalid if record_invalid

result
end

def update(...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ def save(...)
end

def save!(...)
tracer.in_span("#{self.class}#save!") do
record_invalid = nil
result = tracer.in_span("#{self.class}#save!") do
super
rescue ::ActiveRecord::RecordInvalid => e
record_invalid = e
end
raise record_invalid if record_invalid

result
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
_(create_span_event.attributes['exception.type']).must_equal('ActiveModel::UnknownAttributeError')
_(create_span_event.attributes['exception.message']).must_include('unknown attribute \'attreeboot\' for User.')
end

it 'does not add an exception event if it raises a handled validation error' do
_(-> { User.create!(name: 'not otel') }).must_raise(ActiveRecord::RecordInvalid)

create_span = spans.find { |s| s.name == 'User.create!' }
_(create_span).wont_be_nil
_(create_span.events).must_be_nil
_(create_span.status.code).must_equal(OpenTelemetry::Trace::Status::UNSET)
end
end

describe '.update' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@
_(save_span).wont_be_nil
end

it 'adds an exception event if it raises' do
it 'does not add an exception event if it raises a handled validation error' do
_(-> { User.new(name: 'not otel').save! }).must_raise(ActiveRecord::RecordInvalid)

save_span = spans.find { |s| s.name == 'User#save!' }
_(save_span).wont_be_nil
save_span_event = save_span.events.first
_(save_span_event.attributes['exception.type']).must_equal('ActiveRecord::RecordInvalid')
_(save_span_event.attributes['exception.message']).must_equal('Validation failed: must be otel')
_(save_span.events).must_be_nil
_(save_span.status.code).must_equal(OpenTelemetry::Trace::Status::UNSET)
end
end

Expand Down Expand Up @@ -106,6 +105,17 @@
update_span = spans.find { |s| s.name == 'User#update!' }
_(update_span).wont_be_nil
end

it 'does not add an exception event if it raises a handled validation error' do
user = User.create!(name: 'otel')

_(-> { user.update!(name: 'not otel') }).must_raise(ActiveRecord::RecordInvalid)

update_span = spans.find { |s| s.name == 'User#update!' }
_(update_span).wont_be_nil
_(update_span.events).must_be_nil
_(update_span.status.code).must_equal(OpenTelemetry::Trace::Status::UNSET)
end
end

describe '#update_column' do
Expand Down
Loading