Skip to content

Commit

Permalink
improve test coverage for nil and empty attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
mabdinur committed Jul 18, 2024
1 parent 9a7de18 commit f01655f
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions spec/datadog/opentelemetry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@
context "attributes is #{attrs.inspect}" do
let(:attributes) { attrs }

it 'sets records an event and sets the status of the span to error' do
it 'sets records an exception event and sets span error tags using the Exception object' do
expect(span.events.count).to eq(1)
expect(span.events[0].name).to eq('exception')
expect(span.events[0].time_unix_nano / 1e9).to be_within(1).of(Time.now.to_f)
Expand All @@ -633,22 +633,48 @@
":in `full_message': Error (StandardError)"
)
expect(span).to_not have_error
expect(span).to have_error_message('Error')
end
end
end

context 'with attributes' do
context 'with attributes containing nil values' do
let(:attributes) { { 'exception.stacktrace' => nil, 'exception.type' => nil, 'exception.message' => nil } }

it 'sets records an exception event and sets span error tags using the attributes hash' do
expect(span.events.count).to eq(1)
expect(span.events[0].name).to eq('exception')
expect(span.events[0].attributes).to eq({})
expect(span).to_not have_error
expect(span).to have_error_message('Error')
end
end

context 'with attributes containing empty values' do
let(:attributes) { { 'exception.stacktrace' => '', 'exception.type' => '', 'exception.message' => '' } }

it 'sets records an exception event and does NOT set span error tags' do
expect(span.events.count).to eq(1)
expect(span.events[0].name).to eq('exception')
expect(span.events[0].attributes).to eq(attributes)
expect(span).to_not have_error
expect(span).to have_error_message(nil)
end
end

context 'with attributes containing exception stacktrace, type and message' do
let(:attributes) do
{ 'exception.stacktrace' => 'funny_stack', 'exception.type' => 'CustomError', 'exception.message' => 'NewError',
'candy' => true }
end

it 'sets records an event and sets the status of the span to error using attributes' do
it 'sets records an exception event and sets span error tags using the attributes hash' do
expect(span.events.count).to eq(1)
expect(span.events[0].name).to eq('exception')
expect(span.events[0].time_unix_nano / 1e9).to be_within(1).of(Time.now.to_f)
expect(span.events[0].attributes).to eq(attributes)
expect(span).to_not have_error
expect(span).to have_error_message('NewError')
end
end
end
Expand Down

0 comments on commit f01655f

Please sign in to comment.