Skip to content

fix(exporter/otlp): support non-standard types as attribute values and log body#5239

Open
grvmishra788 wants to merge 3 commits into
open-telemetry:mainfrom
grvmishra788:worktree-issue-5210
Open

fix(exporter/otlp): support non-standard types as attribute values and log body#5239
grvmishra788 wants to merge 3 commits into
open-telemetry:mainfrom
grvmishra788:worktree-issue-5210

Conversation

@grvmishra788
Copy link
Copy Markdown
Contributor

@grvmishra788 grvmishra788 commented May 21, 2026

Description

Passing a pathlib.Path (or any other type outside the OTLP AnyValue spec) as a span/log attribute value or log body caused the OTLP exporter to crash:

Exception: Invalid type <class 'pathlib.PosixPath'> of value /path/to/something

Both the proto-common and json-common OTLP encoders (_encode_value()) had no fallback for unrecognised types. This PR adds a str() best-effort fallback before raising, so non-standard types are encoded as their string representation instead of crashing the exporter. If str() itself raises, the original exception propagates unchanged.

The fix mirrors the existing _clean_extended_attribute_value() behaviour in the SDK and is applied consistently across both encoder implementations.

Fixes #5210.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • New tests added to both encoder test suites.
  • Existing None-handling tests (allow_null=True/False) and list-with-None error paths all pass unchanged.

Does This PR Require a Contrib Repo Change?

  • No.

Checklist:

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

@grvmishra788 grvmishra788 requested a review from a team as a code owner May 21, 2026 02:22
…c-methods

- Use str(Path(...)) as expected value so tests pass on Windows (backslash separator)
- Add pylint disable for too-many-public-methods on TestCommonEncoder (21 methods)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Feature Request: Support for pathlib.Path objects in OTLP Exporter attributes

1 participant