mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-07-28 20:52:57 +08:00
add python-kafka to docs (#1552)
This commit is contained in:
@ -29,6 +29,7 @@ elasticsearch>=2.0,<9.0
|
|||||||
flask~=2.0
|
flask~=2.0
|
||||||
falcon~=2.0
|
falcon~=2.0
|
||||||
grpcio~=1.27
|
grpcio~=1.27
|
||||||
|
kafka-python>=2.0,<3.0
|
||||||
mysql-connector-python~=8.0
|
mysql-connector-python~=8.0
|
||||||
psutil>=5
|
psutil>=5
|
||||||
pika>=0.12.0
|
pika>=0.12.0
|
||||||
|
10
docs/instrumentation/kafka_python/kafka_python.rst
Normal file
10
docs/instrumentation/kafka_python/kafka_python.rst
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
.. include:: ../../../instrumentation/opentelemetry-instrumentation-kafka-python/README.rst
|
||||||
|
:end-before: References
|
||||||
|
|
||||||
|
API
|
||||||
|
---
|
||||||
|
|
||||||
|
.. automodule:: opentelemetry.instrumentation.kafka
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
@ -13,7 +13,7 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Instrument `kafka-python` to report instrumentation-kafka produced and consumed messages
|
Instrument kafka-python to report instrumentation-kafka produced and consumed messages
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
-----
|
-----
|
||||||
@ -30,24 +30,21 @@ Usage
|
|||||||
producer = KafkaProducer(bootstrap_servers=['localhost:9092'])
|
producer = KafkaProducer(bootstrap_servers=['localhost:9092'])
|
||||||
producer.send('my-topic', b'raw_bytes')
|
producer.send('my-topic', b'raw_bytes')
|
||||||
|
|
||||||
|
|
||||||
# report a span of type consumer with the default settings
|
# report a span of type consumer with the default settings
|
||||||
consumer = KafkaConsumer('my-topic',
|
consumer = KafkaConsumer('my-topic', group_id='my-group', bootstrap_servers=['localhost:9092'])
|
||||||
group_id='my-group',
|
|
||||||
bootstrap_servers=['localhost:9092'])
|
|
||||||
for message in consumer:
|
for message in consumer:
|
||||||
# process message
|
# process message
|
||||||
|
|
||||||
The `_instrument` method accepts the following keyword args:
|
The _instrument() method accepts the following keyword args:
|
||||||
tracer_provider (TracerProvider) - an optional tracer provider
|
tracer_provider (TracerProvider) - an optional tracer provider
|
||||||
produce_hook (Callable) - a function with extra user-defined logic to be performed before sending the message
|
produce_hook (Callable) - a function with extra user-defined logic to be performed before sending the message
|
||||||
this function signature is:
|
this function signature is:
|
||||||
def produce_hook(span: Span, args, kwargs)
|
def produce_hook(span: Span, args, kwargs)
|
||||||
consume_hook (Callable) - a function with extra user-defined logic to be performed after consuming a message
|
consume_hook (Callable) - a function with extra user-defined logic to be performed after consuming a message
|
||||||
this function signature is:
|
this function signature is:
|
||||||
def consume
|
def consume_hook(span: Span, record: kafka.record.ABCRecord, args, kwargs)
|
||||||
_hook(span: Span, record: kafka.record.ABCRecord, args, kwargs)
|
|
||||||
for example:
|
for example:
|
||||||
|
|
||||||
.. code: python
|
.. code: python
|
||||||
from opentelemetry.instrumentation.kafka import KafkaInstrumentor
|
from opentelemetry.instrumentation.kafka import KafkaInstrumentor
|
||||||
from kafka import KafkaProducer, KafkaConsumer
|
from kafka import KafkaProducer, KafkaConsumer
|
||||||
|
Reference in New Issue
Block a user