From b337e6434704f21c88f4bfbe6ddbfa2540b92a5f Mon Sep 17 00:00:00 2001 From: Nimrod Shlagman Date: Wed, 28 Dec 2022 08:45:00 +0200 Subject: [PATCH 1/2] add python-kafka to docs --- docs-requirements.txt | 1 + .../kafka_python/kafka_python.rst | 10 +++++++++ .../instrumentation/kafka/__init__.py | 22 +++++++++---------- 3 files changed, 21 insertions(+), 12 deletions(-) create mode 100644 docs/instrumentation/kafka_python/kafka_python.rst diff --git a/docs-requirements.txt b/docs-requirements.txt index a1b55877a1..c45df7daf3 100644 --- a/docs-requirements.txt +++ b/docs-requirements.txt @@ -27,6 +27,7 @@ celery>=4.0 flask~=2.0 falcon~=2.0 grpcio~=1.27 +kafka-python>=2.0 mysql-connector-python~=8.0 psutil>=5 pika>=0.12.0 diff --git a/docs/instrumentation/kafka_python/kafka_python.rst b/docs/instrumentation/kafka_python/kafka_python.rst new file mode 100644 index 0000000000..5e921c20fa --- /dev/null +++ b/docs/instrumentation/kafka_python/kafka_python.rst @@ -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: diff --git a/instrumentation/opentelemetry-instrumentation-kafka-python/src/opentelemetry/instrumentation/kafka/__init__.py b/instrumentation/opentelemetry-instrumentation-kafka-python/src/opentelemetry/instrumentation/kafka/__init__.py index c262f0c812..b3edd4140b 100644 --- a/instrumentation/opentelemetry-instrumentation-kafka-python/src/opentelemetry/instrumentation/kafka/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-kafka-python/src/opentelemetry/instrumentation/kafka/__init__.py @@ -13,7 +13,7 @@ # 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 ----- @@ -30,24 +30,22 @@ producer = KafkaProducer(bootstrap_servers=['localhost:9092']) producer.send('my-topic', b'raw_bytes') - # report a span of type consumer with the default settings - consumer = KafkaConsumer('my-topic', - group_id='my-group', - bootstrap_servers=['localhost:9092']) + consumer = KafkaConsumer('my-topic', group_id='my-group', bootstrap_servers=['localhost:9092']) 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 produce_hook (Callable) - a function with extra user-defined logic to be performed before sending the message - this function signature is: - def produce_hook(span: Span, args, kwargs) +this function signature is: +def produce_hook(span: Span, args, kwargs) consume_hook (Callable) - a function with extra user-defined logic to be performed after consuming a message - this function signature is: - def consume - _hook(span: Span, record: kafka.record.ABCRecord, args, kwargs) +this function signature is: +def consume +_hook(span: Span, record: kafka.record.ABCRecord, args, kwargs) for example: + .. code: python from opentelemetry.instrumentation.kafka import KafkaInstrumentor from kafka import KafkaProducer, KafkaConsumer From 61fa84b3e00882ef4cbf6567b7b10a922d77151f Mon Sep 17 00:00:00 2001 From: Nimrod Shlagman Date: Wed, 4 Jan 2023 09:10:02 +0200 Subject: [PATCH 2/2] version + typo fix --- docs-requirements.txt | 2 +- .../src/opentelemetry/instrumentation/kafka/__init__.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/docs-requirements.txt b/docs-requirements.txt index 930091e7f8..29ef82774c 100644 --- a/docs-requirements.txt +++ b/docs-requirements.txt @@ -27,7 +27,7 @@ celery>=4.0 flask~=2.0 falcon~=2.0 grpcio~=1.27 -kafka-python>=2.0 +kafka-python>=2.0,<3.0 mysql-connector-python~=8.0 psutil>=5 pika>=0.12.0 diff --git a/instrumentation/opentelemetry-instrumentation-kafka-python/src/opentelemetry/instrumentation/kafka/__init__.py b/instrumentation/opentelemetry-instrumentation-kafka-python/src/opentelemetry/instrumentation/kafka/__init__.py index b3edd4140b..ad94a4fb04 100644 --- a/instrumentation/opentelemetry-instrumentation-kafka-python/src/opentelemetry/instrumentation/kafka/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-kafka-python/src/opentelemetry/instrumentation/kafka/__init__.py @@ -42,8 +42,7 @@ def produce_hook(span: Span, args, kwargs) consume_hook (Callable) - a function with extra user-defined logic to be performed after consuming a message this function signature is: -def consume -_hook(span: Span, record: kafka.record.ABCRecord, args, kwargs) +def consume_hook(span: Span, record: kafka.record.ABCRecord, args, kwargs) for example: .. code: python