Skip to content

fix(sdk): record the latest error status whatever its description - #3867

Open
WatchTree-19 wants to merge 4 commits into
open-telemetry:mainfrom
WatchTree-19:fix/span-status-last-error
Open

WatchTree-19 wants to merge 4 commits into
open-telemetry:mainfrom
WatchTree-19:fix/span-status-last-error

Conversation

@WatchTree-19

Copy link
Copy Markdown

Changes

Span::set_status in opentelemetry-sdk/src/trace/span.rs updates the status only when status > data.status. Status derives PartialOrd, and a derived ordering compares two Error values by their description, so a later error replaces an earlier one only when its description sorts after it:

span.set_status(Status::error("timeout"));
span.set_status(Status::error("connection refused"));
// status stays Error { description: "timeout" }

The Status docs say only the value of the last call is recorded. This keeps Ok final and ignores Unset, as the specification requires, and otherwise records the latest status. The other SDKs (Java, JS, Ruby, PHP) behave the same way.

Two cases are added to the existing set_status test: a later error with an earlier-sorting description is recorded, and Unset does not clear an error. The first fails on main with left: Error { description: "timeout" }.

Merge requirement checklist

  • CONTRIBUTING guidelines followed
  • Unit tests added/updated (if applicable)
  • Appropriate CHANGELOG.md files updated for non-trivial, user-facing changes
  • Changes in public API reviewed (if applicable): no public API change

Checked with cargo fmt --all, cargo clippy -p opentelemetry_sdk --all-targets --all-features -- -Dwarnings and cargo test -p opentelemetry_sdk --all-features --lib (513 passed).

Span::set_status compared statuses with the derived PartialOrd, which
orders two Error values by their description. A later error therefore
replaced an earlier one only when its description sorted after it, so
"timeout" followed by "connection refused" kept "timeout".

Ok stays final and Unset is still ignored; otherwise the latest status
is recorded, as the Status docs describe.
@WatchTree-19
WatchTree-19 requested a review from a team as a code owner November 15, 2026 01:53
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Waiting on maintainers · refreshed 2026-12-04 15:18 UTC

Merge when ready.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Should this be with the author? Comment /dashboard route:author to route it back.
  • Anything wrong — including the routing? Report it with what you expected; it helps us improve the dashboard.

@codecov

codecov Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.8%. Comparing base (7385eda) to head (6e44f27).

Additional details and impacted files
@@           Coverage Diff           @@
##            main   #3867     +/-   ##
=======================================
- Coverage   86.8%   86.8%   -0.1%     
=======================================
  Files        131     131             
  Lines      34801   34809      +8     
=======================================
+ Hits       30216   30222      +6     
- Misses      4585    4587      +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@TommyCpp TommyCpp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. We should probably update this doc comment too:

/// 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.

@WatchTree-19

Copy link
Copy Markdown
Author

Thanks @TommyCpp, good catch. The set_status doc comment in global/trace.rs now describes the new rule, in 81e6ad4.

@lalitb lalitb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks.

@WatchTree-19

Copy link
Copy Markdown
Author

@lalitb thanks for the approval. Is there anything else needed from me before this can be merged?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants