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

未关闭
#5,210 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

@danilopeixoto 已经在做这个了。

开始于 2026年5月20日。

  • #5239 来自 @grvmishra788 —— 已关闭,未合并

评估

难度
3/5
预计耗时
1-2 天
新手友好度
66/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
冷清
技术栈
python

调研方向

从 opentelemetry/exporter/otlp/proto/common/_internal/init.py 中的 _encode_value 开始,目前 pathlib.PosixPath 会在那里引发异常。跟踪 LogRecord 和 Span 的 OTLP 属性如何到达此编码器,然后验证 Path 值会作为字符串处理,同时不会破坏现有的基本类型值编码或相关的 exporter 测试。

由索引模型根据 Issue 内容生成。

描述

feature-request
Is your feature request related to a problem?

Currently, passing a pathlib.Path object as an attribute value to a LogRecord (or Span) causes the OTLP Exporter to fail with an Exception: Invalid type <class 'pathlib.PosixPath'>. While I understand the OTLP spec is strict about primitive types, pathlib.Path is a Python standard library type frequently used in logging context (e.g., model paths, log file locations).

Describe the solution you'd like

It would be helpful if the OpenTelemetry Python SDK could automatically coerce pathlib.Path objects to strings during the OTLP encoding process, or provide a standard hook/configuration to handle common non-primitive types without crashing the exporter.

Describe alternatives you've considered

I am currently using a custom structlog processor to manually stringify all Path objects before they reach the OpenTelemetry logging bridge:

def stringify_non_standard_types(event_dict):
    for key, value in event_dict.items():
        if isinstance(value, Path):
            event_dict[key] = str(value)
    return event_dict

While this works, it requires manual configuration for every project and doesn't cover cases where third-party instrumentations might inject Path objects into the context.

Additional Context

Stack trace:

  File ".../opentelemetry/exporter/otlp/proto/common/_internal/__init__.py", line 100, in _encode_value
    raise Exception(f"Invalid type {type(value)} of value {value}")
Exception: Invalid type <class 'pathlib.PosixPath'> of value /Users/user/models/my-model
Would you like to implement a fix?

Yes

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

主要语言
Python
星标
2.7k
派生
1.1k
平均合并
3 天 12 小时
30 天内合并 PR
16

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

open-telemetry/opentelemetry-python 的其他 Issue

查看 open-telemetry/opentelemetry-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。