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 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)

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

File metadata

  • Download URL: opentelemetry-instrumentation-celery-0.16b1.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.7.9

File hashes

Hashes for opentelemetry-instrumentation-celery-0.16b1.tar.gz
Algorithm Hash digest
SHA256 07ebea0a764c25fc418fa0331b74c698fbf2afcb59de9fb7f7517607e3cafeab
MD5 174d770f97a0c2b3fbae973585b45cc2
BLAKE2b-256 6afed3b20f9233515eb71ef2392ece2e315ebca61a8ed4ac93443fbdef56b38a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opentelemetry_instrumentation_celery-0.16b1-py3-none-any.whl
Algorithm Hash digest
SHA256 1ac7d9ee90b587d9d446d3f9d05e99751fb9142073c94d519210823881ffecb7
MD5 52062218169ef85eb743aa2aa76893ad
BLAKE2b-256 3714cf731b09ef7d7443f0fb8b5782b734d0866f70291510761dc20a301847c5

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