OpenTelemetry Celery Instrumentation¶
Instrument celery to trace Celery applications.
Usage¶
Start broker backend
docker run -p 5672:5672 rabbitmq
Run instrumented task
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor
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):
trace.set_tracer_provider(TracerProvider())
span_processor = BatchExportSpanProcessor(ConsoleSpanExporter())
trace.get_tracer_provider().add_span_processor(span_processor)
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.
CarrierGetter
[source]¶ Bases:
opentelemetry.trace.propagation.textmap.DictGetter
-
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 an empty list.
- 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 an empty list if the
key doesn’t exist.
-
-
class
opentelemetry.instrumentation.celery.
CeleryInstrumentor
[source]¶ Bases:
opentelemetry.instrumentation.instrumentor.BaseInstrumentor