-
Notifications
You must be signed in to change notification settings - Fork 874
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() doesn't accept null values #65
Comments
Can you open this in https://github.com/open-telemetry/opentelemetry-java? That is where this change would need to happen. (btw, I totally support this!) |
OK. Will do. BTW, I'm seeing this issue in multiple packages. I think the original Datadog code was written without null-checking in mind. Leaving this check in place is a ticking bomb. |
Linked issue: open-telemetry/opentelemetry-java#765 |
Yeah, the existing code does null-checking here: This problem is coming up when moving the instrumentation to use OpenTelemetry API directly. |
Closing (tracking subsequent cleanup in #76) |
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: