-
Notifications
You must be signed in to change notification settings - Fork 864
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
Span::setAttribute null-checking of value may be detrimental #765
Comments
Would you want the |
As far as I'm concerned, a null value on an attribute is perfectly fine. But there may be other parts of the code that doesn't agree with me. :) My particular use case is this: The auto instrumenter picks up a bunch of values from a call to some service that we're instrumenting. We pick up those values and stick them as attribute on a Span. Sometimes the values we get extract from the call are null, which is just fine in many cases. The code may look something like this:
If we don't check for null on EVERY instance of such value propagation, we risk crashing out of our interceptor on a |
Our 3 options:
I'd love some input from other folks. @tylerbenson, @trask, @bogdandrutu , your thoughts? |
Decision from the call: We are going to update the API to allow nullable values (but not keys), and that null values will result in the call being a noop. |
From today's SIG call: |
Any thoughts on what to do with empty strings? E.g. DataDog's agent also removes the attribute if passed an empty string I'm not sure I have a preference one way or another, just wanted to raise while this is being discussed. Thx! |
I think the empty string should be considered the same as a |
I'm not happy with the empty string thing, but I think this needs clarification in the spec, so I created open-telemetry/opentelemetry-specification#431 there. |
This came up as an issue when working on the auto-instrumentation project.
The
Span::setAttribute()
method is commonly used in interceptors to copy attributes from an invocation to span attributes. This method will, by design, throw aNullPointerException
if a null value is supplied. Given that many frameworks may treat certain attributes as optional, there's a chance that attributes with null values are present on the invocation objects.The current implementation instrumenters/decorators are wrapping the calls to setAttribute() in null-checking if-statements whenever it is suspected that a null value may be supplied.
However, since the exact rules for which attributes may contain null aren't well documented for all frameworks, there's a high risk that a null-check is omitted by mistake, causing hard to find errors at runtime.
Should we implement a
setAttributeOrNull()
method that can be used when the presence of null values isn't known? Should we change the behavior ofsetAttribute()
? What is the reason we don't allow null values in the first place? Could we change the behavior to make an assignment of a null value to an attribute a no-op?The text was updated successfully, but these errors were encountered: