Right now, if you send a log event without a body, code will crash like below. This allows a log record body to be None, avoiding this error.
Overriding of current EventLoggerProvider is not allowed
Exception while exporting logs.
Traceback (most recent call last):
File "/Users/adriancole/oss/otel-ollama/examples/python/opentelemetry/openai/.venv/lib/python3.12/site-packages/opentelemetry/sdk/_logs/_internal/export/__init__.py", line 307, in _export_batch
self._exporter.export(self._log_records[:idx]) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/adriancole/oss/otel-ollama/examples/python/opentelemetry/openai/.venv/lib/python3.12/site-packages/opentelemetry/exporter/otlp/proto/grpc/_log_exporter/__init__.py", line 111, in export
return self._export(batch)
^^^^^^^^^^^^^^^^^^^
File "/Users/adriancole/oss/otel-ollama/examples/python/opentelemetry/openai/.venv/lib/python3.12/site-packages/opentelemetry/exporter/otlp/proto/grpc/exporter.py", line 300, in _export
request=self._translate_data(data),
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/adriancole/oss/otel-ollama/examples/python/opentelemetry/openai/.venv/lib/python3.12/site-packages/opentelemetry/exporter/otlp/proto/grpc/_log_exporter/__init__.py", line 108, in _translate_data
return encode_logs(data)
^^^^^^^^^^^^^^^^^
File "/Users/adriancole/oss/otel-ollama/examples/python/opentelemetry/openai/.venv/lib/python3.12/site-packages/opentelemetry/exporter/otlp/proto/common/_internal/_log_encoder/__init__.py", line 37, in encode_logs
return ExportLogsServiceRequest(resource_logs=_encode_resource_logs(batch))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/adriancole/oss/otel-ollama/examples/python/opentelemetry/openai/.venv/lib/python3.12/site-packages/opentelemetry/exporter/otlp/proto/common/_internal/_log_encoder/__init__.py", line 71, in _encode_resource_logs
pb2_log = _encode_log(sdk_log)
^^^^^^^^^^^^^^^^^^^^
File "/Users/adriancole/oss/otel-ollama/examples/python/opentelemetry/openai/.venv/lib/python3.12/site-packages/opentelemetry/exporter/otlp/proto/common/_internal/_log_encoder/__init__.py", line 57, in _encode_log
body=_encode_value(log_data.log_record.body),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/adriancole/oss/otel-ollama/examples/python/opentelemetry/openai/.venv/lib/python3.12/site-packages/opentelemetry/exporter/otlp/proto/common/_internal/__init__.py", line 90, in _encode_value
raise Exception(f"Invalid type {type(value)} of value {value}")
Exception: Invalid type <class 'NoneType'> of value None
[x] Bug fix (non-breaking change which fixes an issue)
[ ] New feature (non-breaking change which adds functionality)
[ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
[ ] This change requires a documentation update
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
Description
Right now, if you send a log event without a body, code will crash like below. This allows a log record body to be
None
, avoiding this error.See discussion
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
tox -e test-py312-opentelemetry-exporter-otlp-proto-common
Does This PR Require a Contrib Repo Change?
Checklist: