Skip to content
Open
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
3 changes: 3 additions & 0 deletions opentelemetry-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## vNext

- Fix `Span::set_status` keeping an earlier `Status::Error` when a later one
has a description that sorts first alphabetically. The latest error is now
recorded; `Ok` stays final and `Unset` is still ignored.
- Fixed the experimental async-runtime `PeriodicReader`, `BatchSpanProcessor`
and `BatchLogProcessor` waiting two intervals before their first collection or
flush. The ticker already delays before firing, so the extra skipped tick is
Expand Down
20 changes: 17 additions & 3 deletions opentelemetry-sdk/src/trace/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,9 @@ impl opentelemetry::trace::Span for Span {
/// If used, this will override the default span status, which is [`Status::Unset`].
fn set_status(&mut self, status: Status) {
self.with_data(|data| {
// check if we should update the status
// These values form a total order: Ok > Error > Unset.
if status > data.status {
// Ok is final and Unset is ignored. Otherwise the latest status wins,
// so a later Error replaces an earlier one whatever its description.
if data.status != Status::Ok && status != Status::Unset {
data.status = status;
}
});
Expand Down Expand Up @@ -694,6 +694,20 @@ mod tests {
span.set_status(Status::error("error"));
span.with_data(|data| assert_ne!(data.status, Status::Ok));
}
{
let mut span = create_span();
// the last error is recorded, whatever the order of the descriptions
span.set_status(Status::error("timeout"));
span.set_status(Status::error("connection refused"));
span.with_data(|data| assert_eq!(data.status, Status::error("connection refused")));
}
{
let mut span = create_span();
// unset does not clear an error
span.set_status(Status::error("error"));
span.set_status(Status::Unset);
span.with_data(|data| assert_eq!(data.status, Status::error("error")));
}
}

#[test]
Expand Down
8 changes: 4 additions & 4 deletions opentelemetry/src/global/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ pub trait ObjectSafeSpan {
/// Sets the status of the `Span`. `message` MUST be ignored when the status is `OK` or
/// `Unset`.
///
/// The order of status is `Ok` > `Error` > `Unset`. That's means set the status
/// to `Unset` will always be ignore, set the status to `Error` only works when current
/// status is `Unset`, set the status to `Ok` will be consider final and any further call
/// to this function will be ignore.
/// The order of status is `Ok` > `Error` > `Unset`. Setting the status to `Unset` is
/// always ignored. Setting it to `Error` replaces the current status unless that status
/// is `Ok`, so the latest error is kept. Setting it to `Ok` is final, and any further
/// call to this function is ignored.
fn set_status(&mut self, status: Status);

/// Updates the `Span`'s name. After this update, any sampling behavior based on the
Expand Down
Loading