Skip to main content

OpenTelemetry Celery Instrumentation

Project description

pypi

Instrumentation for Celery.

Installation

pip install opentelemetry-instrumentation-celery

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 BatchSpanProcessor
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 = BatchSpanProcessor(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)

Setting up tracing

When tracing a celery worker process, tracing and instrumention both must be initialized after the celery worker process is initialized. This is required for any tracing components that might use threading to work correctly such as the BatchSpanProcessor. Celery provides a signal called worker_process_init that can be used to accomplish this as shown in the example above.

References

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

File details

Details for the file opentelemetry-instrumentation-celery-0.22b0.tar.gz.

File metadata

  • Download URL: opentelemetry-instrumentation-celery-0.22b0.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.7.10

File hashes

Hashes for opentelemetry-instrumentation-celery-0.22b0.tar.gz
Algorithm Hash digest
SHA256 8f0422fc6c35f2427cb4e39edb2704203e1de65b2d71702dd1f11df9d79d7a34
MD5 e54cd93554b994dd1333f5da36a7af80
BLAKE2b-256 373db4455eae78e9063a146b90a584ad4def5d3bb34f1fee81b4a290bd28a2e2

See more details on using hashes here.

File details

Details for the file opentelemetry_instrumentation_celery-0.22b0-py3-none-any.whl.

File metadata

File hashes

Hashes for opentelemetry_instrumentation_celery-0.22b0-py3-none-any.whl
Algorithm Hash digest
SHA256 18e96ce35c5a5a326d66798b8988a0a681f90b7e0124088657cd8aaf203c25bb
MD5 45fc6c853b8312b55cbb5ed49930e658
BLAKE2b-256 eba6bf4e71ec5857362c7c20fb05e3652aa910b7ddca5f7ec510a8f81897c5d8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page