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

Aperta
#5,210 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@danilopeixoto ci sta già lavorando.

Dal 20/5/2026.

  • #5239 di @grvmishra788 — chiusa senza merge

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
66/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
python

Direzione di ricerca

Inizia in opentelemetry/exporter/otlp/proto/common/_internal/init.py, in _encode_value, dove pathlib.PosixPath attualmente solleva un’eccezione. Segui il percorso con cui gli attributi OTLP di LogRecord e Span arrivano a questo encoder, quindi verifica che i valori Path vengano gestiti come stringhe senza compromettere la codifica esistente dei valori primitivi o i test pertinenti dell’exporter.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
2.7k
Fork
1.1k
Merge medio
3g 12h
PR unite (30g)
16

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di open-telemetry/opentelemetry-python

Tutte le issue di open-telemetry/opentelemetry-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.