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 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.23b0.tar.gz
.
File metadata
- Download URL: opentelemetry-instrumentation-celery-0.23b0.tar.gz
- Upload date:
- Size: 14.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.7.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6fcedb0a60394986b3794d88285ef56fb0982e095190ebcd1a369a39d3f80d24 |
|
MD5 | 3edaa9ec78e4d71e47813bab4ac9b9a6 |
|
BLAKE2b-256 | 5422d3252ea6e0071479e237a7f0436b8374c96210674cb30fb5cd74bfd8e2b8 |
Provenance
File details
Details for the file opentelemetry_instrumentation_celery-0.23b0-py3-none-any.whl
.
File metadata
- Download URL: opentelemetry_instrumentation_celery-0.23b0-py3-none-any.whl
- Upload date:
- Size: 13.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.7.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e3efa9467e94a0f12975d0af02ad5e8a8f526a3072839ab724ccf4334aa9de9 |
|
MD5 | 2b8f1ad8526b33b5b0e2299d0f593514 |
|
BLAKE2b-256 | 8e7b473a4ba3ca39e1e99674144b172c64dc92fbcbe3b2d57f81c7976733406c |