This library provides OpenTelemetry instrumentation for the `pika` Python library, enabling automatic tracing of RabbitMQ interactions. It is part of the `opentelemetry-python-contrib` project, which frequently releases beta versions, with stable releases typically occurring less often. The library requires Python 3.9 or newer.
pip install opentelemetry-instrumentation-pika opentelemetry-sdk pikaVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to instrument the Pika library to automatically generate OpenTelemetry traces. It initializes the OpenTelemetry SDK with a console exporter, instruments Pika, and then performs a basic message publish operation. Ensure a RabbitMQ instance is accessible at `localhost` for this example to run successfully.
Always place OpenTelemetry SDK setup and instrumentation calls at the very beginning of your application's entry point, before any `import pika` or related code is executed.
Refer to the `opentelemetry-python-contrib` changelog for specific breaking changes in new releases. Pin exact versions in production environments to avoid unexpected behavior.
For Gunicorn and similar pre-fork servers, consider using a single worker process if automatic metric collection is critical, or use programmatic instrumentation to configure an exporter per worker process. Alternatively, explore zero-code instrumentation via `opentelemetry-instrument` with specific configurations or ensure metrics are pushed via OTLP directly.
Ensure `pika` is installed and its version meets the requirements specified by `opentelemetry-instrumentation-pika`. Check the `instrumentation_dependencies` method in the source code or `pyproject.toml` for precise version constraints.