Skip to content

celery instrumentation setting a single time limit (soft_time_limit or time_limit) leads to warning: "Attribute 'celery.timelimit' mixes types str and int in attribute value sequence" #2022

Description

@maxkomarychev

Describe your environment Describe any aspect of your environment relevant to the problem, including your Python version, platform, version numbers of installed dependencies, information about your cloud hosting provider, etc. If you're reporting a problem with a specific version of a library in this repo, please check whether the problem has been fixed on main.

  • python 3.9.9
  • celery 5.3.4 and celery 4.4.2

Steps to reproduce
Describe exactly how to reproduce the error. Include a code sample if applicable.

  1. create file tasks.py

    from celery import Celery
    
    app = Celery('tasks', broker='pyamqp://guest@localhost//')
    
    @app.task(soft_time_limit=42)
    def add(x, y):
        return x + y
  2. start broker:

    OTEL_METRICS_EXPORTER=none OTEL_TRACES_EXPORTER=console opentelemetry-instrument celery -A tasks worker --loglevel=INFO
  3. run a task:

    $ python
    Python 3.9.9 (main, Apr 13 2022, 11:57:59) 
    [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from tasks import add
    >>> from datetime import datetime
    >>> add.apply_async(('',''), eta=datetime.utcnow())
    <AsyncResult: c4a1673d-a09a-4462-9238-fb6199d0ace1>
    >>> 
    
  4. observe warning

[2023-10-26 17:45:57,289: WARNING/ForkPoolWorker-8] Attribute 'celery.timelimit' mixes types str and int in attribute value sequence

What is the expected behavior?
What did you expect to see?

To not see a warning

What is the actual behavior?
What did you see instead?

I am observing a warning "Attribute 'celery.timelimit' mixes types str and int in attribute value sequence" from OTEL when setting soft_timie_limit

I am observing a warning "Attribute 'celery.timelimit' mixes types int and str in attribute value sequence" from OTEL when setting time_limit

Additional context
Add any other context about the problem here.

I have debugged and logged some values from

if key == "timelimit":
if value in [(None, None), [None, None]]:
continue
if None in value:
value = ["" if tl is None else tl for tl in value]
I see that values is actually [None, 42] (None and a number) which makes this code to produce [str, int] and trigger a warning from
https://github.com/open-telemetry/opentelemetry-python/blob/34d11d59e9b37052eb3aa6706288641ecb3056e7/opentelemetry-api/src/opentelemetry/attributes/__init__.py#L86-L93

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions