Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle nulls in noop / multi #2939

Merged
merged 3 commits into from
May 7, 2021
Merged

Conversation

anuraaga
Copy link
Contributor

Fixes #2921

This may not be a good idea for Multi but went with consistency for now, let me know thoughts.

@codecov
Copy link

codecov bot commented Feb 26, 2021

Codecov Report

Merging #2939 (f58e602) into main (bd6cfd8) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##               main    #2939   +/-   ##
=========================================
  Coverage     91.04%   91.05%           
- Complexity     2990     2995    +5     
=========================================
  Files           336      336           
  Lines          9316     9324    +8     
  Branches        946      949    +3     
=========================================
+ Hits           8482     8490    +8     
  Misses          543      543           
  Partials        291      291           
Impacted Files Coverage Δ Complexity Δ
...ry/context/propagation/MultiTextMapPropagator.java 100.00% <100.00%> (ø) 13.00 <8.00> (+4.00)
...try/context/propagation/NoopTextMapPropagator.java 100.00% <100.00%> (ø) 7.00 <2.00> (+1.00)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bd6cfd8...f58e602. Read the comment docs.

Copy link
Contributor

@jkwatson jkwatson left a comment

Choose a reason for hiding this comment

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

Thanks!

@@ -45,13 +45,22 @@

@Override
public <C> void inject(Context context, @Nullable C carrier, TextMapSetter<C> setter) {
if (context == null || setter == null) {
Copy link
Member

@Oberon00 Oberon00 Feb 26, 2021

Choose a reason for hiding this comment

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

I think letting the null bubble through to the inner propagators would be better, also for extract.

Copy link
Contributor

Choose a reason for hiding this comment

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

why is this better?

Copy link
Member

Choose a reason for hiding this comment

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

Mostly just a gut feeling, and principle of least surprise. Also the Javadoc in https://github.com/open-telemetry/opentelemetry-java/blob/v0.17.1/api/context/src/main/java/io/opentelemetry/context/propagation/TextMapPropagator.java#L46-L53 TextMapPropagator.composite() states that it "simply delegates injection and extraction", so that's what I would do.

Copy link
Contributor

Choose a reason for hiding this comment

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

Javadoc can certainly be updated. My opinion is that this is the safest approach, so that propagators that are not maintained by us will also be guarded against these bad inputs if they are wrapped up in a composite propagator with other "official" propagators.

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 that makes sense. If a user wants the other behavior, they can implement their own "NullNaiveMultiPropagator".

}
if (getter == null) {
return context;
}
for (TextMapPropagator textPropagator : textPropagators) {
context = textPropagator.extract(context, carrier, getter);
}
Copy link
Member

@Oberon00 Oberon00 Feb 26, 2021

Choose a reason for hiding this comment

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

As said above, I would not guard against null before this loop also here in extract, but only ensure that we don't return null even if null was passed in as context (and textPropagators was possibly empty).

Copy link
Member

@bogdandrutu bogdandrutu left a comment

Choose a reason for hiding this comment

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

Per offline discussion with @jkwatson block this until the release

@jkwatson
Copy link
Contributor

Let's continue the discussion after we release 1.0.0. Whatever we decide can go into the next minor release.

@jkwatson
Copy link
Contributor

jkwatson commented Mar 5, 2021

Per offline discussion with @jkwatson block this until the release

Can we unblock this now?

@jkwatson
Copy link
Contributor

Per offline discussion with @jkwatson block this until the release

Can we unblock this now?

How about now, @bogdandrutu ?

@jkwatson jkwatson dismissed bogdandrutu’s stale review April 19, 2021 17:42

we're now post 1.0.0, so I think we can move forward with the discussion

@jkwatson
Copy link
Contributor

jkwatson commented May 5, 2021

@anuraaga looks like this needs a rebase.

@jkwatson jkwatson merged commit 0b8131c into open-telemetry:main May 7, 2021
This was referenced Dec 19, 2021
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.

Verify/update all propagators to make sure they do not throw exceptions on bad inputs.
4 participants