A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://opentelemetry-python-contrib.readthedocs.io/en/latest/instrumentation/pika/pika.html below:

Website Navigation


OpenTelemetry Pika Instrumentation — OpenTelemetry Python Contrib documentation

OpenTelemetry Pika Instrumentation

Instrument pika to trace RabbitMQ applications.

Usage
docker run -p 5672:5672 rabbitmq
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!')
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)
import pika
from opentelemetry.instrumentation.pika import PikaInstrumentor
from opentelemetry.trace import get_tracer_provider

connection = pika.BlockingConnection(pika.URLParameters('amqp://localhost'))
channel = connection.channel()
tracer_provider = get_tracer_provider()

channel.queue_declare(queue='hello')

PikaInstrumentor.instrument_channel(channel, tracer_provider=tracer_provider)

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

PikaInstrumentor.uninstrument_channel(channel)
import pika
from opentelemetry.instrumentation.pika import PikaInstrumentor
from opentelemetry.trace import Span
from pika import BasicProperties

def publish_hook(span: Span, body: bytes, properties: BasicProperties):
    span.set_attribute("messaging.payload", body.decode())

def consume_hook(span: Span, body: bytes, properties: BasicProperties):
    span.set_attribute("messaging.id", properties.message_id)

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

PikaInstrumentor.instrument_channel(channel, publish_hook=publish_hook, consume_hook=consume_hook)

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

PikaInstrumentor.uninstrument_channel(channel)
Consumer Instrumentation

For consumer instrumentation, pika supports two consuming modes:

API
class opentelemetry.instrumentation.pika.PikaInstrumentor(*args, **kwargs)[source]

Bases: BaseInstrumentor

CONSUMER_CALLBACK_ATTR = 'on_message_callback'
static instrument_channel(channel, tracer_provider=None, publish_hook=<function dummy_callback>, consume_hook=<function dummy_callback>)[source]
Return type:

None

static uninstrument_channel(channel)[source]
Return type:

None

instrumentation_dependencies()[source]

Return a list of python packages with versions that the will be instrumented.

The format should be the same as used in requirements.txt or pyproject.toml.

For example, if an instrumentation instruments requests 1.x, this method should look like: :rtype: Collection[str]

def instrumentation_dependencies(self) -> Collection[str]:

return [‘requests ~= 1.0’]

This will ensure that the instrumentation will only be used when the specified library is present in the environment.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4