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 摘要。