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.25b1.tar.gz.

File metadata

  • Download URL: opentelemetry-instrumentation-celery-0.25b1.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.12

File hashes

Hashes for opentelemetry-instrumentation-celery-0.25b1.tar.gz
Algorithm Hash digest
SHA256 1a2b20732507af5048fdf28f1f096486d3ef233680cac9c321d17cf9fd575191
MD5 9562c39ed38ce92fa6fd91d4b44838f2
BLAKE2b-256 2847602de6927148f2788b7dfc8a43cc7382962854f2cfd3eba9c6d5745472b0

See more details on using hashes here.

File details

Details for the file opentelemetry_instrumentation_celery-0.25b1-py3-none-any.whl.

File metadata

File hashes

Hashes for opentelemetry_instrumentation_celery-0.25b1-py3-none-any.whl
Algorithm Hash digest
SHA256 e34359a02f4ac615a083aa33682dfb9ce82512a8d0ade5f1c209ad14cc78df8f
MD5 f5ff9f185b67b6277f87a3ded916dda1
BLAKE2b-256 b12d996b7f08860fcc011e791c0cdf4d696d7473b03386e8abf0450ca4c9c612

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