OpenTelemetry Celery Instrumentation
Project description
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.17b0.tar.gz
.
File metadata
- Download URL: opentelemetry-instrumentation-celery-0.17b0.tar.gz
- Upload date:
- Size: 12.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba0a77bd8a62c4a38ed3bb80e30b691eb4d2c7bd91ee551de13ca3edb054d624 |
|
MD5 | ce0a02814756b4fa07cbf41608441f2a |
|
BLAKE2b-256 | 91be7da0ff37c87a9e131dcea820e054efdb8ff34dcfe5e83f94529ccf937421 |
Provenance
File details
Details for the file opentelemetry_instrumentation_celery-0.17b0-py3-none-any.whl
.
File metadata
- Download URL: opentelemetry_instrumentation_celery-0.17b0-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed0aab6b080c5842c5ad3e537c428d0def7d39852941317c2838838c173f63a2 |
|
MD5 | a4daacf4561427a369d357a7ee05a4a1 |
|
BLAKE2b-256 | 6da9cbb8a5afd266c683dd91c8185b54191793e37188d23778f8c58c7fa00a11 |