Skip to content

Commit 00888d9

Browse files
committed
Fix broken RST docs
1 parent 0da62aa commit 00888d9

File tree

3 files changed

+171
-3
lines changed

3 files changed

+171
-3
lines changed

docs/instrumentation/aiokafka/aiokafka.rst

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,65 @@
11
.. include:: ../../../instrumentation/opentelemetry-instrumentation-aiokafka/README.rst
22
:end-before: References
33

4+
Usage
5+
=====
6+
7+
The instrumentation will track producer and consumer operations.
8+
9+
Producer Example
10+
----------------
11+
12+
.. code-block:: python
13+
14+
import asyncio
15+
from opentelemetry.instrumentation.aiokafka import AioKafkaInstrumentor
16+
from aiokafka import AIOKafkaProducer
17+
18+
async def produce():
19+
# Enable instrumentation
20+
AioKafkaInstrumentor().instrument()
21+
22+
# Use aiokafka producer as usual
23+
producer = AIOKafkaProducer(bootstrap_servers=['localhost:9092'])
24+
await producer.start()
25+
try:
26+
await producer.send_and_wait('my-topic', b'raw_bytes')
27+
finally:
28+
await producer.stop()
29+
30+
asyncio.run(produce())
31+
32+
Consumer Example
33+
----------------
34+
35+
.. code-block:: python
36+
37+
import asyncio
38+
from opentelemetry.instrumentation.aiokafka import AioKafkaInstrumentor
39+
from aiokafka import AIOKafkaConsumer
40+
41+
async def consume():
42+
# Enable instrumentation
43+
AioKafkaInstrumentor().instrument()
44+
45+
# Use aiokafka consumer as usual
46+
consumer = AIOKafkaConsumer(
47+
'my-topic',
48+
bootstrap_servers=['localhost:9092'],
49+
group_id='my-group',
50+
auto_offset_reset='earliest'
51+
)
52+
await consumer.start()
53+
try:
54+
async for msg in consumer:
55+
print(f'Received message: {msg.value.decode("utf-8")}')
56+
finally:
57+
await consumer.stop()
58+
59+
asyncio.run(consume())
60+
461
API
5-
---
62+
===
663

764
.. automodule:: opentelemetry.instrumentation.aiokafka
865
:members:

docs/instrumentation/confluent_kafka/confluent_kafka.rst

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,71 @@
11
.. include:: ../../../instrumentation/opentelemetry-instrumentation-confluent-kafka/README.rst
2+
:end-before: References
3+
4+
Usage
5+
=====
6+
7+
The instrumentation will track producer and consumer operations.
8+
9+
Producer Example
10+
----------------
11+
12+
.. code-block:: python
13+
14+
from opentelemetry.instrumentation.confluent_kafka import ConfluentKafkaInstrumentor
15+
from confluent_kafka import Producer
16+
17+
# Enable instrumentation
18+
ConfluentKafkaInstrumentor().instrument()
19+
20+
# Use confluent-kafka producer as usual
21+
conf = {'bootstrap.servers': 'localhost:9092'}
22+
producer = Producer(conf)
23+
producer.produce('my-topic', value=b'raw_bytes')
24+
producer.flush()
25+
26+
Consumer Example
27+
----------------
28+
29+
.. code-block:: python
30+
31+
from confluent_kafka import Consumer, KafkaError, KafkaException
32+
from opentelemetry.instrumentation.confluent_kafka import ConfluentKafkaInstrumentor
33+
import sys
34+
35+
# Enable instrumentation
36+
ConfluentKafkaInstrumentor().instrument()
37+
38+
# Use confluent-kafka consumer as usual
39+
conf = {
40+
'bootstrap.servers': 'localhost:9092',
41+
'group.id': 'foo',
42+
'auto.offset.reset': 'smallest'
43+
}
44+
consumer = Consumer(conf)
45+
46+
def basic_consume_loop(consumer, topics):
47+
try:
48+
consumer.subscribe(topics)
49+
while True:
50+
msg = consumer.poll(timeout=1.0)
51+
if msg is None:
52+
continue
53+
if msg.error():
54+
if msg.error().code() == KafkaError._PARTITION_EOF:
55+
# End of partition event
56+
sys.stderr.write(f'{msg.topic()} [{msg.partition()}] reached end at offset {msg.offset()}')
57+
else:
58+
raise KafkaException(msg.error())
59+
else:
60+
# Process the message here
61+
print(f'Received message: {msg.value().decode("utf-8")}')
62+
finally:
63+
consumer.close()
64+
65+
basic_consume_loop(consumer, ['my-topic'])
66+
67+
API
68+
===
269

370
.. automodule:: opentelemetry.instrumentation.confluent_kafka
471
:members:
Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,54 @@
11
.. include:: ../../../instrumentation/opentelemetry-instrumentation-kafka-python/README.rst
22
:end-before: References
33

4+
Usage
5+
=====
6+
7+
The instrumentation will track producer and consumer operations.
8+
9+
Producer Example
10+
----------------
11+
12+
.. code-block:: python
13+
14+
from opentelemetry.instrumentation.kafka import KafkaInstrumentor
15+
from kafka import KafkaProducer
16+
17+
# Enable instrumentation
18+
KafkaInstrumentor().instrument()
19+
20+
# Use kafka-python producer as usual
21+
producer = KafkaProducer(bootstrap_servers=['localhost:9092'])
22+
producer.send('my-topic', b'raw_bytes')
23+
producer.flush()
24+
25+
Consumer Example
26+
----------------
27+
28+
.. code-block:: python
29+
30+
from opentelemetry.instrumentation.kafka import KafkaInstrumentor
31+
from kafka import KafkaConsumer
32+
33+
# Enable instrumentation
34+
KafkaInstrumentor().instrument()
35+
36+
# Use kafka-python consumer as usual
37+
consumer = KafkaConsumer(
38+
'my-topic',
39+
bootstrap_servers=['localhost:9092'],
40+
group_id='my-group',
41+
auto_offset_reset='earliest'
42+
)
43+
44+
# Process messages
45+
for message in consumer:
46+
print(f'Received message: {message.value.decode("utf-8")}')
47+
448
API
5-
---
49+
===
650

7-
.. automodule:: opentelemetry.instrumentation.kafka
51+
.. automodule:: opentelemetry.instrumentation.kafka_python
852
:members:
953
:undoc-members:
1054
:show-inheritance:

0 commit comments

Comments
 (0)