Skip to content

Fix Handle null context in Baggage.fromContext() and Baggage.fromContextOrNull() - #8667

Merged
jack-berg merged 2 commits into
open-telemetry:mainfrom
NithinU2802:fix/baggage-null-context-handling
Aug 13, 2026
Merged

Fix Handle null context in Baggage.fromContext() and Baggage.fromContextOrNull()#8667
jack-berg merged 2 commits into
open-telemetry:mainfrom
NithinU2802:fix/baggage-null-context-handling

Conversation

@NithinU2802

Copy link
Copy Markdown
Contributor

In Baggage, to add null checks to Baggage.fromContext(context) and Baggage.fromContextOrNull(context) with log using ApiUsageLogger and for Baggage.fromContext(context) now returns empty() when the context is null, also for Baggage.fromContextOrNull(context) returns null. Additionally, added unit tests to cover these scenarios.

I'm happy to update any changes if needed.

Closes #8665

@NithinU2802
NithinU2802 requested a review from a team as a code owner July 28, 2026 11:36
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Jul 28, 2026

Copy link
Copy Markdown

Pull request dashboard status

Merged · refreshed 2026-08-13 20:48 UTC

Status above doesn't look right?
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.46%. Comparing base (ff91c02) to head (195ebde).

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8667      +/-   ##
============================================
- Coverage     91.46%   91.46%   -0.01%     
- Complexity    10456    10458       +2     
============================================
  Files          1021     1021              
  Lines         27647    27653       +6     
  Branches       3242     3242              
============================================
+ Hits          25288    25293       +5     
  Misses         1616     1616              
- Partials        743      744       +1     

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

Comment thread api/all/src/main/java/io/opentelemetry/api/baggage/Baggage.java Outdated
…l and fromContextOrNull_null tests, and add LogCapturer assertions

@jkwatson jkwatson 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.

seems reasonable to me

@NithinU2802

Copy link
Copy Markdown
Contributor Author

Hi @jack-berg, could you please review this PR once you get a chance.

@opentelemetry-pr-dashboard

Copy link
Copy Markdown

Hi @NithinU2802 — just a friendly reminder that this pull request is waiting on you.

There are still items that need your attention. See the dashboard status comment for the full list. You don't need to push a code change to hand it back — replying to move each discussion forward is enough, whether that's answering a question, explaining why no change is needed, or asking a follow-up. The dashboard then automatically routes it back to reviewers.

If you believe this pull request is incorrectly routed as waiting on the author, comment /dashboard route:reviewers to route it from waiting on the author to waiting on reviewers.

@NithinU2802

Copy link
Copy Markdown
Contributor Author

/dashboard route:reviewers

@opentelemetry-pr-dashboard

Copy link
Copy Markdown

@NithinU2802 this pull request is already past review and waiting on maintainers, so /dashboard route:reviewers had no effect.

@jack-berg jack-berg 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.

This implements our null guard guidance. There's a ton of API surface area like this and the behavior is really simple so I don't think its worth it in general to add test cases everywhere asserting the log behavior. It doesn't harm any thing, but I don't think its necessary in future cases.

Note I added this exact code in my draft PR where I used an agent to scan / fix all cases like this: https://github.com/open-telemetry/opentelemetry-java/pull/8321/changes#diff-71a58ce1813a311dae68cf8efcbcff989eaddd1464c7b409de100bd75365c943

@jack-berg
jack-berg merged commit 38ec5bd into open-telemetry:main Aug 13, 2026
29 checks passed
@otelbot

otelbot Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Thank you for your contribution @NithinU2802! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey.

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.

Fix to add null handling to Baggage.fromContext() and Baggage.fromContextOrNull()

4 participants