Add assertion support for Span hasException(null)#8033
Merged
jkwatson merged 1 commit intoopen-telemetry:mainfrom Jan 29, 2026
Merged
Add assertion support for Span hasException(null)#8033jkwatson merged 1 commit intoopen-telemetry:mainfrom
jkwatson merged 1 commit intoopen-telemetry:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8033 +/- ##
=========================================
Coverage 90.16% 90.16%
- Complexity 7483 7485 +2
=========================================
Files 836 836
Lines 22562 22567 +5
Branches 2237 2239 +2
=========================================
+ Hits 20343 20348 +5
Misses 1515 1515
Partials 704 704 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
jack-berg
reviewed
Jan 29, 2026
| // true for assertions. | ||
| @SuppressWarnings("NullAway") | ||
| public SpanDataAssert hasException(Throwable exception) { | ||
| public SpanDataAssert hasException(@Nullable Throwable exception) { |
Member
There was a problem hiding this comment.
This is another case of: #7359 (review)
I support retaining the ability to add the @Nullable annotation to parameters, and think its useful here. Also, there was never any followup to #7359 to update VERSIONING.md to disallow this type of change, so it's still allowed.
jack-berg
approved these changes
Jan 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
hasException(null)is called, it now asserts that the span has no exception event instead of throwing a NullPointerException.This would be convenient in open-telemetry/opentelemetry-java-instrumentation#16049, e.g. when chaining:
I think the behavior reasonably follows convention:
hasSchemaUrl(@Nullable String)asserts the schema URL equals the given value (including null)hasBody(@Nullable Value<?>)asserts the body equals the given value (including null)equalTo(key, null)inhasAttributesSatisfyingExactlyasserts the attribute value is null/absentThis last one we use heavily in instrumentation repo, e.g.