Skip to content

Not recording celery beat tasks #110

@Horiol

Description

@Horiol

Hello, I'm trying to get traces of the celery tasks and I'm using a celery beat process to schedule the tasks but I can't receive anything if the task is executed from beat.

Example code:
tasks.py

from celery import Celery
from opentracing_instrumentation.client_hooks import celery as celery_hooks

# from custom_celery import CeleryTracing
from tracer import init_tracer
import periodic

tracer = init_tracer('test')

celery_hooks.install_patches()
app = Celery('tasks', broker='redis://localhost:6379/0')

periodic.py

from celery import shared_task


@shared_task()
def add(x=1, y=1):
    return x + y

beat.py

from celery import Celery
from tracer import init_tracer

tracer = init_tracer('beat-liveclips')

beat_schedule = {
    "print-in-ten-seconds-task": {
        "task": "periodic.add",
        "schedule": 10.0,
        "args":[3,5]
    }
}

app = Celery(broker='redis://localhost:6379/0')
app.conf.beat_schedule = beat_schedule

tracer.py

import logging
from jaeger_client import Config

def init_tracer(service):
    logging.getLogger('').handlers = []
    logging.basicConfig(format='%(message)s', level=logging.DEBUG)

    config = Config(
        config={
            'sampler': {
                'type': 'const',
                'param': 1,
            },
            'logging': True,
        },
        service_name=service,
    )

    return config.initialize_tracer()

and then, you have to execute the worker and the beat with the following commands:
celery -A tasks worker --loglevel=info
celery -A beat beat --loglevel=info

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions