-
Notifications
You must be signed in to change notification settings - Fork 283
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
Prevent NPE when deleting OpenTracing baggage #7637
base: master
Are you sure you want to change the base?
Conversation
… value setBaggageItem("key",null)
if (baggageItems == EMPTY_BAGGAGE) { | ||
baggageItems = new ConcurrentHashMap<>(4); | ||
if (value == null) { | ||
baggageItems.remove(key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we protect the call when the baggageItems
has not yet been initialized (in that case this will throw an unsupported operation exception)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be unexpected. An outside actor is not aware if something is initialized or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, you can then just check if the baggageItems != EMPTY_BAGGAGE
before calling remove
Many thanks for the contribution 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EMPTY_BAGGAGE is just an empty map, so .remove is a noop.
Would that make a difference ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dump question but I could not find from OpenTracing spec nor code base that null
value must be supported?
Not the null
should throw a NPE, it should not but I am not sure that setting a null
value should remove the key-value pair... 🤔
Can you help me where you found this behavior?
Moreover, this change would required additional test for core and OpenTracing instrumentation (we can discuss this point later once we find out how the API should behave).
EDIT: I find the the OpenTracing shim from OpenTelemetry (so the implementation of OpenTracing from the OpenTelemetry standard) does skip null
keys and values:
https://github.com/open-telemetry/opentelemetry-java/blob/0132d5d98b21cd4cbc2a0354a4d5bcc2867a2969/opentracing-shim/src/main/java/io/opentelemetry/opentracingshim/SpanShim.java#L167-L178
So I would not be in favor of changing the baggage behavior, only fixing the NPE.
Right, fortunately with opentelemetry you have the option to get the Baggage using getBaggage() turn it into a builder, update it and store it again. open-telemetry/opentelemetry-java#2553 I feel this might be an unintended restriction due to the ConcurrentHashMap. What would my alternative be to remove a baggage Item ? |
What Does This Do
Prevent NPE when deleting baggage value by
setBaggageItem("key", null)
Motivation
NPE when trying to remove a baggage item.
Additional Notes
Contributor Checklist
type:
and (comp:
orinst:
) labels in addition to any usefull labelsclose
,fix
or any linking keywords when referencing an issue.Use
solves
instead, and assign the PR milestone to the issue