Feature Request: Support for `pathlib.Path` objects in OTLP Exporter attributes
维护者通常 2 天内回复
评估
- 难度
- 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 内容生成。
描述
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
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
open-telemetry/opentelemetry-python 的其他 Issue
-
References to Archived open-telemetry/oteps可能已有人在做 @RjyavardhanSingh 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
open-telemetry/opentelemetry-python#5984 · 1 条评论 ·
维护者通常 2 天内回复
-
Autoconfiguration rejects OTEL_EXPORTER_OTLP_PROTOCOL=http/json可能已有人在做 @WendeelMarinho 于 2 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 82/100
open-telemetry/opentelemetry-python#5981 ·
维护者通常 2 天内回复
-
MeterProvider raises ValueError on empty or uppercase OTEL_METRICS_EXEMPLAR_FILTER可能已有人在做 @bishalde 于 8 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 83/100
open-telemetry/opentelemetry-python#5948 · 3 条评论 ·
维护者通常 2 天内回复
-
W3CBaggagePropagator drops a list-member over 4096 bytes that W3C Baggage requires it to propagate可能已有人在做 @codedbyadiiii 于 20 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 70/100
open-telemetry/opentelemetry-python#5913 ·
维护者通常 2 天内回复
-
otel.sdk.processor.{span,log}.queue.capacity uses synchronous UpDownCounter recorded once in __init__可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
open-telemetry/opentelemetry-python#5891 ·
维护者通常 2 天内回复
查看 open-telemetry/opentelemetry-python 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
bug improve content
难度 1/5 1 小时以内 新手友好度 92/100
opensafely/documentation#2102 ·
维护者通常 1 天内回复
-
difficulty:1 documentation
难度 2/5 1-3 小时 新手友好度 82/100
MakazhanAlpamys/Soup#3533 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
onyx-dot-app/onyx#18730 ·
维护者通常 1 天内回复