Issues with OTLP exporter with None values

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

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

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
45/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
Calme
Stack technique
python
Domaine
observability

Piste de recherche

Commencez par l’OTLP encoder dans exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/init.py et suivez la façon dont CeleryInstrumentor() exporte les task results et les log values. Reproduisez le résultat de valeur None avec la Celery task fournie, puis vérifiez que l’exporter le gère sans warnings ni errors et que l’incompatibilité entre SDK/API est corrigée ou clairement séparée.

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

Description

bug
Describe your environment

OS: Ubuntu
Python version: 3.12
SDK version: opentelemetry-sdk==1.36.0
API version: opentelemetry-api==1.36.0
Celery: opentelemetry-instrumentation-celery==0.57b0

What happened?

I am using CeleryInstrumentor() to get logs of celery into Grafana/Loki

First of the issues I get is that I see an incompatibility with the latest opentelemetry-sdk (1.41) version with opentelemetry-api (it does not allow me to install).

Second issue is with None values in the celery results exported to Grafana. I am seeing a warning like:
Invalid type <class 'dict'> of value {'id': 'b2f12a15-b57d-4e9a-a439-345a323e7c1b', 'name': 'app.tasks.tasks.say_hello', 'args': '()', 'kwargs': '{}', 'eta': None}

I noticed that in opentelemetry 1.41 you already updated the encoder: https://github.com/open-telemetry/opentelemetry-python/blob/main/exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/__init__.py

But I am uncapable of setting allow_null to True for CeleryInstrumentor().

Steps to Reproduce

Setup CeleryInstrumentor() and have a task that retuns None values somewhere.
In my case:

# API route to trigger the task
@bp.route('/long_task', methods=['GET'])
def trigger_task():
    task = say_hello.delay()
    return jsonify({"task_id": task.id, "status": "Task has been submitted"}), 202

@celery.task
def say_hello():
    sleep(10)
    logger.info(f"[HEALTHCHECK] say_hello config_class={type(Config).__name__} service_name={Config.SERVICE_NAME}")
    return "Hello, World!"

I also have a custom logger setup, which might be the one causing None to get inserted over the values.

Expected Result

No errors or warning escalated to Loki/Grafana

Actual Result

I monkey patched _encode_key_value:

def _encode_key_value(key: str, value: _Any, allow_null: bool = False) -> _PB2KeyValue:
if value is None:
return _PB2KeyValue(key=key, value=_encode_value(value, allow_null=True))
return _PB2KeyValue(key=key, value=_encode_value(value, allow_null=allow_null))

Additional context

I am unsure if this is a proper solution, I guess not and that it should be configured and CeleryInstrumentor some setting that allows to pass the allow_none=True, but I do not know how to do it.

Would you like to implement a fix?

None

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.