-
Notifications
You must be signed in to change notification settings - Fork 661
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
opentelemetry-exporter-otlp-proto-common: permit to serialize null values in logs #4400
base: main
Are you sure you want to change the base?
Conversation
...xporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/__init__.py
Outdated
Show resolved
Hide resolved
…metry/exporter/otlp/proto/common/_internal/__init__.py
@@ -66,7 +66,11 @@ def _encode_resource(resource: Resource) -> PB2Resource: | |||
return PB2Resource(attributes=_encode_attributes(resource.attributes)) | |||
|
|||
|
|||
def _encode_value(value: Any) -> PB2AnyValue: | |||
def _encode_value( | |||
value: Any, allow_null: bool = False |
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.
is there a need for allow_null = False
? could we allow nulls for everything?
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.
_encode_value
is used via _encode_key_value
by _encode_attributes
that is used also by the metrics and trace encoders and did not want to change their behavior.
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.
A couple of thoughts:
- I'd imagine complex attributes on logs/events would also be prone to the same problem. It'd be nice to allow log attributes to have null values. So I think we should allow log attributes to have null values inside complex payloads.
- [minor] Allowing null values would not be a breaking change (it was not allowed before so nobody could add a null attribute), so I still wonder if additional logic is necessary.
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.
What do you mean with complex attributes? _encode_value
is recursive so we are handling null values nested in arrays and maps.
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 mean not just the body, but also logrecord attributes
Description
This fixes logs encoding to work with body if it is a mapping with null keys.
Fixes #4279
Fixes #4392
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Does This PR Require a Contrib Repo Change?
Checklist: