Skip to content

Latest commit

 

History

History
70 lines (42 loc) · 1.86 KB

File metadata and controls

70 lines (42 loc) · 1.86 KB

OpenTelemetry pika Instrumentation

pypi

This library allows tracing requests made by the pika library.

Installation

pip install opentelemetry-instrumentation-pika

Usage

  • Start broker backend
docker run -p 5672:5672 rabbitmq
  • Run instrumented task
import pika
from opentelemetry.instrumentation.pika import PikaInstrumentor

PikaInstrumentor().instrument()

connection = pika.BlockingConnection(pika.URLParameters('amqp://localhost'))
channel = connection.channel()
channel.queue_declare(queue='hello')
channel.basic_publish(exchange='', routing_key='hello', body=b'Hello World!')
  • PikaInstrumentor also supports instrumentation of a single channel
import pika
from opentelemetry.instrumentation.pika import PikaInstrumentor

connection = pika.BlockingConnection(pika.URLParameters('amqp://localhost'))
channel = connection.channel()
channel.queue_declare(queue='hello')

pika_instrumentation = PikaInstrumentor()
pika_instrumentation.instrument_channel(channel=channel)


channel.basic_publish(exchange='', routing_key='hello', body=b'Hello World!')

pika_instrumentation.uninstrument_channel(channel=channel)
  • PikaInstrumentor also supports instrumentation without creating an object, and receiving a tracer_provider
PikaInstrumentor.instrument_channel(channel, tracer_provider=tracer_provider)

References