Skip to content
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

Support logs with no body #4276

Merged
merged 3 commits into from
Nov 14, 2024
Merged

Conversation

codefromthecrypt
Copy link
Contributor

@codefromthecrypt codefromthecrypt commented Nov 14, 2024

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.

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

See discussion

Type of change

Please delete options that are not relevant.

  • 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

  • tox -e test-py312-opentelemetry-exporter-otlp-proto-common

Does This PR Require a Contrib Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

Signed-off-by: Adrian Cole <adrian.cole@elastic.co>
@codefromthecrypt codefromthecrypt requested a review from a team as a code owner November 14, 2024 06:57
Signed-off-by: Adrian Cole <adrian.cole@elastic.co>
@lzchen lzchen merged commit ccc9e6f into open-telemetry:main Nov 14, 2024
353 checks passed
@aabmass aabmass mentioned this pull request Nov 14, 2024
6 tasks
aabmass pushed a commit to aabmass/opentelemetry-python that referenced this pull request Nov 14, 2024
aabmass pushed a commit to aabmass/opentelemetry-python that referenced this pull request Nov 14, 2024
@codefromthecrypt codefromthecrypt deleted the fix-none-body branch November 14, 2024 23:39
aabmass added a commit that referenced this pull request Nov 15, 2024
* Support logs with no body (#4276)

* Move cherry-picked changelog entry into Unreleased section

---------

Co-authored-by: Adrian Cole <64215+codefromthecrypt@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

5 participants