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

Ouverte
#5,210 2 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 2 jours

@danilopeixoto y travaille déjà.

Depuis le 20/5/2026.

  • #5239 par @grvmishra788 — fermée sans fusion

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
66/100
Type d'issue
Fonctionnalité
Clarté
Plutôt claire
Activité
Calme
Stack technique
python

Piste de recherche

Commencez dans opentelemetry/exporter/otlp/proto/common/_internal/init.py, au niveau de _encode_value, où pathlib.PosixPath lève actuellement une exception. Suivez le cheminement des attributs OTLP de LogRecord et Span jusqu’à cet encodeur, puis vérifiez que les valeurs Path sont traitées comme des chaînes sans perturber l’encodage existant des valeurs primitives ni les tests pertinents de l’exporter.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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.

Langage dominant
Python
Étoiles
2.7k
Forks
1.1k
Merge moyen
3 j 12 h
PR mergées (30 j)
16

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de open-telemetry/opentelemetry-python

Toutes les issues de open-telemetry/opentelemetry-python

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.