Skip to content

Conversation

@adinauer
Copy link
Member

📜 Description

Using the SDK and having to guard against null is not a nice experience. Instead the SDK now tries to do the right thing when it receives null on APIs like setTag, setData, setContext, setExtra etc.

This means the SDK will:

  • NoOp if the key is null (maybe returning null if a return type is specified)
  • Unset the previous value if the value is set to null

💡 Motivation and Context

Fixes #4224

💚 How did you test it?

📝 Checklist

  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

@github-actions
Copy link
Contributor

github-actions bot commented Mar 10, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 382.18 ms 445.12 ms 62.94 ms
Size 1.58 MiB 2.21 MiB 642.29 KiB

Previous results on branch: fix/fewer-npes

Startup times

Revision Plain With Sentry Diff
e24a560 415.04 ms 523.32 ms 108.28 ms

App size

Revision Plain With Sentry Diff
e24a560 1.58 MiB 2.21 MiB 642.30 KiB

Comment on lines 680 to 684
for (final Span span : this.children) {
// This is used in the spanFinishCallback, when the span isn't finished, but has a finish
// date
if (!span.isFinished() && span.getFinishDate() == null) {
return false;
Copy link
Member

Choose a reason for hiding this comment

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

Seems unrelated, should we revert this change?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah yes, forgot to revert this.

Comment on lines +678 to +680
if (key == null) {
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

I think we need to also unset if value is null here, like we do in the other overloads

Copy link
Member

Choose a reason for hiding this comment

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

Or maybe it will be handled by the below call? Not sure.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, this is handled by Contexts.put so no need to duplicate it here.

Copy link
Member

@lcian lcian left a comment

Choose a reason for hiding this comment

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

LGTM

@lcian
Copy link
Member

lcian commented Mar 11, 2025

Flaky tests? Looks like the system tests are failing after ac9ebcd

@adinauer
Copy link
Member Author

I'm guessing it's the OkHttp change. I've set the timeouts since it ran into SocketTimeoutException

@adinauer adinauer merged commit 21a214b into main Mar 12, 2025
35 checks passed
@adinauer adinauer deleted the fix/fewer-npes branch March 12, 2025 05:32
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.

Span.setData / Transaction.setData cause NullPointerException

3 participants