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!: total order constraint on span.status= #805

Merged
merged 9 commits into from
Jun 14, 2021
Merged
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
13 changes: 8 additions & 5 deletions sdk/lib/opentelemetry/sdk/trace/span.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,23 @@ def record_exception(exception, attributes: nil)

# Sets the Status to the Span
#
# If used, this will override the default Span status. Default is OK.
# If used, this will override the default Span status. Default has code = Status::UNSET.
robertlaurin marked this conversation as resolved.
Show resolved Hide resolved
#
# Only the value of the last call will be recorded, and implementations
# are free to ignore previous calls.
# An attempt to set the status with code == Status::UNSET is ignored.
# If the status is set with code == Status::OK, any further attempt to set the status
# is ignored.
#
# @param [Status] status The new status, which overrides the default Span
# status, which is OK.
# status, which has code = Status::UNSET.
#
# @return [void]
def status=(status)
return if status.code == OpenTelemetry::Trace::Status::UNSET

@mutex.synchronize do
if @ended
OpenTelemetry.logger.warn('Calling status= on an ended Span.')
else
elsif @status.code != OpenTelemetry::Trace::Status::OK
@status = status
end
end
Expand Down
24 changes: 23 additions & 1 deletion sdk/test/opentelemetry/sdk/trace/span_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -324,15 +324,37 @@

describe '#status=' do
it 'sets the status' do
span.status = Status.new(1, description: 'cancelled')
span.status = Status.new(Status::ERROR, description: 'cancelled')
_(span.status.description).must_equal('cancelled')
_(span.status.code).must_equal(Status::ERROR)
end

it 'does not set the status if span is ended' do
span.finish
span.status = Status.new(Status::ERROR, description: 'cancelled')
_(span.status.code).must_equal(Status::UNSET)
end

it 'does not set the status if asked to set to UNSET' do
span.status = Status.new(Status::ERROR, description: 'cancelled')
span.status = Status.new(Status::UNSET, description: 'actually, maybe it is OK?')
_(span.status.description).must_equal('cancelled')
_(span.status.code).must_equal(Status::ERROR)
end

it 'does not override the status once set to OK' do
span.status = Status.new(Status::OK, description: 'nothing to see here')
span.status = Status.new(Status::ERROR, description: 'cancelled')
_(span.status.description).must_equal('nothing to see here')
_(span.status.code).must_equal(Status::OK)
end

it 'allows overriding ERROR with OK' do
span.status = Status.new(Status::ERROR, description: 'cancelled')
span.status = Status.new(Status::OK, description: 'nothing to see here')
_(span.status.description).must_equal('nothing to see here')
_(span.status.code).must_equal(Status::OK)
end
end

describe '#name=' do
Expand Down