OpenTelemetry Celery Instrumentation

Instrument celery to trace Celery applications.

Usage

  • Start broker backend

docker run -p 5672:5672 rabbitmq
  • Run instrumented task

from opentelemetry.instrumentation.celery import CeleryInstrumentor

from celery import Celery
from celery.signals import worker_process_init

@worker_process_init.connect(weak=False)
def init_celery_tracing(*args, **kwargs):
    CeleryInstrumentor().instrument()

app = Celery("tasks", broker="amqp://localhost")

@app.task
def add(x, y):
    return x + y

add.delay(42, 50)

API

class opentelemetry.instrumentation.celery.CeleryGetter[source]

Bases: opentelemetry.propagators.textmap.Getter

get(carrier, key)[source]

Function that can retrieve zero or more values from the carrier. In the case that the value does not exist, returns None.

Parameters
  • carrier – An object which contains values that are used to construct a Context.

  • key – key of a field in carrier.

Returns: first value of the propagation key or None if the key doesn’t

exist.

keys(carrier)[source]

Function that can retrieve all the keys in a carrier object.

Parameters

carrier – An object which contains values that are used to construct a Context.

Returns

list of keys from the carrier.

class opentelemetry.instrumentation.celery.CeleryInstrumentor(*args, **kwargs)[source]

Bases: opentelemetry.instrumentation.instrumentor.BaseInstrumentor