Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(errors): revert breaking change #3796

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions lib/datadog/tracing/metadata/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ module Metadata
# Adds error tagging behavior
# @public_api
module Errors
def set_error(e)
Datadog::Core.log_deprecation do
'Errors.set_error(..) is deprecated. ' \
'Use Errors.set_error_tags(..) instead.'
end
Comment on lines +14 to +17
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is set_error deprecated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Errors.set_error shadows SpanOperation.set_error. SpanOperation.set_error always sets the status on a Span to error. In OpenTelemetry we need to decouple setting error tags from setting error statuses. To do this I renamed Errors.set_error to Errors.set_error_tags in a previous PR. This was a breaking change. Here I am adding set_error_tags back but deprecating it to avoid maintaining two methods that do the exact same thing.

set_error_tags(e)
end

# Mark the span with the given error.
def set_error_tags(e)
e = Core::Error.build_from(e)
Expand Down
24 changes: 13 additions & 11 deletions spec/datadog/tracing/metadata/errors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,23 @@
end
end

describe '#set_error_tags' do
subject(:set_error_tags) { test_object.set_error_tags(error) }
Array(['set_error', 'set_error_tags']) do |method_name|
describe "##{method_name}" do
subject(:error_setter) { test_object.send(method_name) }

let(:error) { RuntimeError.new('oops') }
let(:backtrace) { %w[method1 method2 method3] }
let(:error) { RuntimeError.new('oops') }
let(:backtrace) { %w[method1 method2 method3] }

before { error.set_backtrace(backtrace) }
before { error.set_backtrace(backtrace) }

it do
set_error_tags
it do
error_setter

expect(test_object).to have_error_message('oops')
expect(test_object).to have_error_type('RuntimeError')
backtrace.each do |method|
expect(test_object).to have_error_stack(include(method))
expect(test_object).to have_error_message('oops')
expect(test_object).to have_error_type('RuntimeError')
backtrace.each do |method|
expect(test_object).to have_error_stack(include(method))
end
end
end
end
Expand Down
Loading