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.24b0.tar.gz
.
File metadata
- Download URL: opentelemetry-instrumentation-celery-0.24b0.tar.gz
- Upload date:
- Size: 14.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.7.0 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.7.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c10c3ab926ff53c0ce1f8263a734154da0fb96a8193a5dd323ac6a9a37baf0c |
|
MD5 | 0f0b38b435b9ad43c8515705d62e520e |
|
BLAKE2b-256 | b5669ceab10f15248c6a83f50d96b56d04f2e75cd5ee3fbc17575cbb5754e87b |
File details
Details for the file opentelemetry_instrumentation_celery-0.24b0-py3-none-any.whl
.
File metadata
- Download URL: opentelemetry_instrumentation_celery-0.24b0-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.7.0 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.7.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ddd6179a0f35de962374f0d508d7395f1f7d0a0e66c9e97963cf65705300088 |
|
MD5 | 9b3dbc28bf9e37c784ee59c7a88f4c1f |
|
BLAKE2b-256 | 7f8c0f6a6f904eeae007ba087d38e3f0bf78d64a419073b7ff5b22e03f5cc89e |