Skip to content

Conversation

@trask
Copy link
Member

@trask trask commented Jan 29, 2026

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:

     ...
     .hasException(emitExceptionsAsLogs()? null : exception)
     ...

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) in hasAttributesSatisfyingExactly asserts the attribute value is null/absent

This last one we use heavily in instrumentation repo, e.g.

   hasAttributesSatisfyingExactly(
     ...
     equalTo(DB_OPERATION, emitStableDatabaseSemconv() ? null : "SELECT")
     ...
   )

@codecov
Copy link

codecov bot commented Jan 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.16%. Comparing base (fd7d014) to head (0c3a9ab).
⚠️ Report is 4 commits behind head on main.

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

@trask trask marked this pull request as ready for review January 29, 2026 04:14
@trask trask requested a review from a team as a code owner January 29, 2026 04:14
// true for assertions.
@SuppressWarnings("NullAway")
public SpanDataAssert hasException(Throwable exception) {
public SpanDataAssert hasException(@Nullable Throwable exception) {
Copy link
Member

Choose a reason for hiding this comment

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

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.

@jkwatson jkwatson merged commit 6054204 into open-telemetry:main Jan 29, 2026
27 checks passed
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