Registry / observability / opentelemetry-instrumentation-pika

opentelemetry-instrumentation-pika

JSON →
library0.65b0pypypi✓ verified 23d ago

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 pika
INSTALL
IMPORT
SIG · OPENTELEMETRY-INST
O
opentelemetry-instrumentation-pika
observabilitypythonv0.65b0
Install
2.8s avg
Import
465ms
Disk
24MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.65b0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.480s · 25.4MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.8s · import 0.450s · 26MB
24MB installed
● package 24MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

PikaInstrumentor
from opentelemetry.instrumentation.pika import PikaInstrumentor

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.

import pika from opentelemetry import trace from opentelemetry.sdk.resources import Resource from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor from opentelemetry.instrumentation.pika import PikaInstrumentor # Configure OpenTelemetry SDK resource = Resource.create({"service.name": "pika-test-app"}) provider = TracerProvider(resource=resource) processor = SimpleSpanProcessor(ConsoleSpanExporter()) provider.add_span_processor(processor) trace.set_tracer_provider(provider) # Instrument Pika PikaInstrumentor().instrument() # Pika usage (example: publish a message) def send_message(): print("Sending message...") connection = pika.BlockingConnection(pika.ConnectionParameters('localhost')) channel = connection.channel() channel.queue_declare(queue='hello') channel.basic_publish(exchange='', routing_key='hello', body=b'Hello World!') print("Message sent.") connection.close() if __name__ == "__main__": # Ensure RabbitMQ is running or adjust connection parameters try: send_message() print("Traces should be printed to the console.") except Exception as e: print(f"Error connecting to RabbitMQ or sending message: {e}") print("Please ensure RabbitMQ is running and accessible at 'localhost'.")
Debug
Known issues
gotchaOpenTelemetry Python SDK and instrumentations must be initialized before the instrumented library (pika) is imported or used. Importing pika before calling `PikaInstrumentor().instrument()` may result in uninstrumented operations.
fix
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.
affects: All versions
breakingAs a beta library (`0.x.y.b0` versioning), `opentelemetry-instrumentation-pika` may introduce breaking changes to its API, configuration, or generated telemetry attributes between minor versions. While efforts are made to align with semantic conventions, these can evolve rapidly.
fix
Refer to the `opentelemetry-python-contrib` changelog for specific breaking changes in new releases. Pin exact versions in production environments to avoid unexpected behavior.
affects: All beta versions (e.g., < 1.0.0)
gotchaAutomatic instrumentation in multi-process/forking environments (e.g., Gunicorn with multiple workers) can be problematic. OpenTelemetry SDK components, especially `PeriodicExportingMetricReader`, may not function correctly across forked processes due to issues with background threads and locks.
fix
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.
affects: All versions
gotchaThe instrumentation relies on `pika` being installed and compatible. Recent changes to dependency checks mean that if `pika` is missing or its version is outside the supported range, instrumentation might fail silently or raise an `ImportError` or `DependencyConflictError`.
fix
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.
affects: All versions
Upgrade
Version history
0.65b0latest on PyPI · released Jul 16, 2026
Audit
Dependencies
pikarequiredThe library instruments 'pika' for RabbitMQ communication.
opentelemetry-sdkrequiredRequired for OpenTelemetry API and SDK functionalities.
Agent activity
15 hits · last 30 days
node
10
Amazon
1
OpenAI (training)
1
Resources
opentelemetry-instrumentation-pika — pip install opentelemetry-instrumentation-pika · libregistry