Metadata-Version: 2.1
Name: opentelemetry-instrumentation-celery
Version: 0.15b0
Summary: OpenTelemetry Celery Instrumentation
Home-page: https://github.com/open-telemetry/opentelemetry-python/tree/master/instrumentation/opentelemetry-instrumentation-celery
Author: OpenTelemetry Authors
Author-email: cncf-opentelemetry-contributors@lists.cncf.io
License: Apache-2.0
Platform: any
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Requires-Python: >=3.5
Description-Content-Type: text/x-rst
Requires-Dist: opentelemetry-api (==0.15b0)
Requires-Dist: opentelemetry-instrumentation (==0.15b0)
Requires-Dist: celery (~=4.0)
Provides-Extra: test
Requires-Dist: pytest ; extra == 'test'
Requires-Dist: celery (~=4.0) ; extra == 'test'
Requires-Dist: opentelemetry-test (==0.15b0) ; extra == 'test'

OpenTelemetry Celery Instrumentation
====================================

|pypi|

.. |pypi| image:: https://badge.fury.io/py/opentelemetry-instrumentation-celery.svg
   :target: https://pypi.org/project/opentelemetry-instrumentation-celery/

Instrumentation for Celery.


Installation
------------

::

    pip install opentelemetry-instrumentation-celery

Usage
-----

* Start broker backend

::
    docker run -p 5672:5672 rabbitmq


* Run instrumented task

.. code-block:: python

    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
----------
* `OpenTelemetry Celery Instrumentation <https://opentelemetry-python.readthedocs.io/en/latest/instrumentation/celery/celery.html>`_
* `OpenTelemetry Project <https://opentelemetry.io/>`_



