Skip to content

Commit

Permalink
feat: Enhance _encode_value in OpenTelemetry exporter to handle None …
Browse files Browse the repository at this point in the history
…values as strings (open-telemetry#4392)
  • Loading branch information
trend-denny-lee committed Jan 23, 2025
1 parent 58f2d16 commit ce68a49
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ def _encode_value(value: Any) -> PB2AnyValue:
return PB2AnyValue(
array_value=PB2ArrayValue(values=[_encode_value(v) for v in value])
)
if value is None:
return PB2AnyValue(string_value="")
elif isinstance(value, Mapping):
return PB2AnyValue(
kvlist_value=PB2KeyValueList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ def test_encode_no_body(self):

self.assertEqual(encode_logs(sdk_logs), expected_encoding)

def test_encode_body_dict_value_has_none(self):
sdk_logs, expected_encoding = self.get_test_logs()
for log in sdk_logs:
log.log_record.body = {"key": None}

for resource_log in expected_encoding.resource_logs:
for scope_log in resource_log.scope_logs:
for log_record in scope_log.log_records:
log_record.body.ClearField("string_value")

self.assertEqual(encode_logs(sdk_logs), expected_encoding)

def test_dropped_attributes_count(self):
sdk_logs = self._get_test_logs_dropped_attributes()
encoded_logs = encode_logs(sdk_logs)
Expand Down

0 comments on commit ce68a49

Please sign in to comment.