prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Add readthedocs documentation for kafka python instrumentation
  Part of [1491](https://github.com/open-telemetry/opentelemetry-python-contrib/issues/1491)
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `instrumentation/opentelemetry-instrumentation-kafka-python/src/opentelemetry/instrumentation/kafka/__init__.py`
  Content:
  ```
  1 # Copyright The OpenTelemetry Authors
  2 #
  3 # Licensed under the Apache License, Version 2.0 (the "License");
  4 # you may not use this file except in compliance with the License.
  5 # You may obtain a copy of the License at
  6 #
  7 #     http://www.apache.org/licenses/LICENSE-2.0
  8 #
  9 # Unless required by applicable law or agreed to in writing, software
  10 # distributed under the License is distributed on an "AS IS" BASIS,
  11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12 # See the License for the specific language governing permissions and
  13 # limitations under the License.
  14 
  15 """
  16 Instrument `kafka-python` to report instrumentation-kafka produced and consumed messages
  17 
  18 Usage
  19 -----
  20 
  21 ..code:: python
  22 
  23     from opentelemetry.instrumentation.kafka import KafkaInstrumentor
  24     from kafka import KafkaProducer, KafkaConsumer
  25 
  26     # Instrument kafka
  27     KafkaInstrumentor().instrument()
  28 
  29     # report a span of type producer with the default settings
  30     producer = KafkaProducer(bootstrap_servers=['localhost:9092'])
  31     producer.send('my-topic', b'raw_bytes')
  32 
  33 
  34     # report a span of type consumer with the default settings
  35     consumer = KafkaConsumer('my-topic',
  36                              group_id='my-group',
  37                              bootstrap_servers=['localhost:9092'])
  38     for message in consumer:
  39         # process message
  40 
  41 The `_instrument` method accepts the following keyword args:
  42 tracer_provider (TracerProvider) - an optional tracer provider
  43 produce_hook (Callable) - a function with extra user-defined logic to be performed before sending the message
  44                           this function signature is:
  45                           def produce_hook(span: Span, args, kwargs)
  46 consume_hook (Callable) - a function with extra user-defined logic to be performed after consuming a message
  47                           this function signature is:
  48                           def consume
  49                           _hook(span: Span, record: kafka.record.ABCRecord, args, kwargs)
  50 for example:
  51 .. code: python
  52     from opentelemetry.instrumentation.kafka import KafkaInstrumentor
  53     from kafka import KafkaProducer, KafkaConsumer
  54 
  55     def produce_hook(span, args, kwargs):
  56         if span and span.is_recording():
  57             span.set_attribute("custom_user_attribute_from_produce_hook", "some-value")
  58     def consume_hook(span, record, args, kwargs):
  59         if span and span.is_recording():
  60             span.set_attribute("custom_user_attribute_from_consume_hook", "some-value")
  61 
  62     # instrument kafka with produce and consume hooks
  63     KafkaInstrumentor().instrument(produce_hook=produce_hook, consume_hook=consume_hook)
  64 
  65     # Using kafka as normal now will automatically generate spans,
  66     # including user custom attributes added from the hooks
  67     producer = KafkaProducer(bootstrap_servers=['localhost:9092'])
  68     producer.send('my-topic', b'raw_bytes')
  69 
  70 API
  71 ___
  72 """
  73 from typing import Collection
  74 
  75 import kafka
  76 from wrapt import wrap_function_wrapper
  77 
  78 from opentelemetry import trace
  79 from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
  80 from opentelemetry.instrumentation.kafka.package import _instruments
  81 from opentelemetry.instrumentation.kafka.utils import _wrap_next, _wrap_send
  82 from opentelemetry.instrumentation.kafka.version import __version__
  83 from opentelemetry.instrumentation.utils import unwrap
  84 
  85 
  86 class KafkaInstrumentor(BaseInstrumentor):
  87     """An instrumentor for kafka module
  88     See `BaseInstrumentor`
  89     """
  90 
  91     def instrumentation_dependencies(self) -> Collection[str]:
  92         return _instruments
  93 
  94     def _instrument(self, **kwargs):
  95         """Instruments the kafka module
  96 
  97         Args:
  98             **kwargs: Optional arguments
  99                 ``tracer_provider``: a TracerProvider, defaults to global.
  100                 ``produce_hook``: a callable to be executed just before producing a message
  101                 ``consume_hook``: a callable to be executed just after consuming a message
  102         """
  103         tracer_provider = kwargs.get("tracer_provider")
  104         produce_hook = kwargs.get("produce_hook")
  105         consume_hook = kwargs.get("consume_hook")
  106 
  107         tracer = trace.get_tracer(
  108             __name__, __version__, tracer_provider=tracer_provider
  109         )
  110 
  111         wrap_function_wrapper(
  112             kafka.KafkaProducer, "send", _wrap_send(tracer, produce_hook)
  113         )
  114         wrap_function_wrapper(
  115             kafka.KafkaConsumer,
  116             "__next__",
  117             _wrap_next(tracer, consume_hook),
  118         )
  119 
  120     def _uninstrument(self, **kwargs):
  121         unwrap(kafka.KafkaProducer, "send")
  122         unwrap(kafka.KafkaConsumer, "__next__")
  123
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: 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
  --- 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,21 @@
       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
  
verification_info: {"golden_diff": "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\n--- a/instrumentation/opentelemetry-instrumentation-kafka-python/src/opentelemetry/instrumentation/kafka/__init__.py\n+++ b/instrumentation/opentelemetry-instrumentation-kafka-python/src/opentelemetry/instrumentation/kafka/__init__.py\n@@ -13,7 +13,7 @@\n # limitations under the License.\n \n \"\"\"\n-Instrument `kafka-python` to report instrumentation-kafka produced and consumed messages\n+Instrument kafka-python to report instrumentation-kafka produced and consumed messages\n \n Usage\n -----\n@@ -30,24 +30,21 @@\n     producer = KafkaProducer(bootstrap_servers=['localhost:9092'])\n     producer.send('my-topic', b'raw_bytes')\n \n-\n     # report a span of type consumer with the default settings\n-    consumer = KafkaConsumer('my-topic',\n-                             group_id='my-group',\n-                             bootstrap_servers=['localhost:9092'])\n+    consumer = KafkaConsumer('my-topic', group_id='my-group', bootstrap_servers=['localhost:9092'])\n     for message in consumer:\n-        # process message\n+    # process message\n \n-The `_instrument` method accepts the following keyword args:\n+The _instrument() method accepts the following keyword args:\n tracer_provider (TracerProvider) - an optional tracer provider\n produce_hook (Callable) - a function with extra user-defined logic to be performed before sending the message\n-                          this function signature is:\n-                          def produce_hook(span: Span, args, kwargs)\n+this function signature is:\n+def produce_hook(span: Span, args, kwargs)\n consume_hook (Callable) - a function with extra user-defined logic to be performed after consuming a message\n-                          this function signature is:\n-                          def consume\n-                          _hook(span: Span, record: kafka.record.ABCRecord, args, kwargs)\n+this function signature is:\n+def consume_hook(span: Span, record: kafka.record.ABCRecord, args, kwargs)\n for example:\n+\n .. code: python\n     from opentelemetry.instrumentation.kafka import KafkaInstrumentor\n     from kafka import KafkaProducer, KafkaConsumer\n", "issue": "Add readthedocs documentation for kafka python instrumentation\nPart of [1491](https://github.com/open-telemetry/opentelemetry-python-contrib/issues/1491)\n", "before_files": [{"content": "# Copyright The OpenTelemetry Authors\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\"\"\"\nInstrument `kafka-python` to report instrumentation-kafka produced and consumed messages\n\nUsage\n-----\n\n..code:: python\n\n    from opentelemetry.instrumentation.kafka import KafkaInstrumentor\n    from kafka import KafkaProducer, KafkaConsumer\n\n    # Instrument kafka\n    KafkaInstrumentor().instrument()\n\n    # report a span of type producer with the default settings\n    producer = KafkaProducer(bootstrap_servers=['localhost:9092'])\n    producer.send('my-topic', b'raw_bytes')\n\n\n    # report a span of type consumer with the default settings\n    consumer = KafkaConsumer('my-topic',\n                             group_id='my-group',\n                             bootstrap_servers=['localhost:9092'])\n    for message in consumer:\n        # process message\n\nThe `_instrument` method accepts the following keyword args:\ntracer_provider (TracerProvider) - an optional tracer provider\nproduce_hook (Callable) - a function with extra user-defined logic to be performed before sending the message\n                          this function signature is:\n                          def produce_hook(span: Span, args, kwargs)\nconsume_hook (Callable) - a function with extra user-defined logic to be performed after consuming a message\n                          this function signature is:\n                          def consume\n                          _hook(span: Span, record: kafka.record.ABCRecord, args, kwargs)\nfor example:\n.. code: python\n    from opentelemetry.instrumentation.kafka import KafkaInstrumentor\n    from kafka import KafkaProducer, KafkaConsumer\n\n    def produce_hook(span, args, kwargs):\n        if span and span.is_recording():\n            span.set_attribute(\"custom_user_attribute_from_produce_hook\", \"some-value\")\n    def consume_hook(span, record, args, kwargs):\n        if span and span.is_recording():\n            span.set_attribute(\"custom_user_attribute_from_consume_hook\", \"some-value\")\n\n    # instrument kafka with produce and consume hooks\n    KafkaInstrumentor().instrument(produce_hook=produce_hook, consume_hook=consume_hook)\n\n    # Using kafka as normal now will automatically generate spans,\n    # including user custom attributes added from the hooks\n    producer = KafkaProducer(bootstrap_servers=['localhost:9092'])\n    producer.send('my-topic', b'raw_bytes')\n\nAPI\n___\n\"\"\"\nfrom typing import Collection\n\nimport kafka\nfrom wrapt import wrap_function_wrapper\n\nfrom opentelemetry import trace\nfrom opentelemetry.instrumentation.instrumentor import BaseInstrumentor\nfrom opentelemetry.instrumentation.kafka.package import _instruments\nfrom opentelemetry.instrumentation.kafka.utils import _wrap_next, _wrap_send\nfrom opentelemetry.instrumentation.kafka.version import __version__\nfrom opentelemetry.instrumentation.utils import unwrap\n\n\nclass KafkaInstrumentor(BaseInstrumentor):\n    \"\"\"An instrumentor for kafka module\n    See `BaseInstrumentor`\n    \"\"\"\n\n    def instrumentation_dependencies(self) -> Collection[str]:\n        return _instruments\n\n    def _instrument(self, **kwargs):\n        \"\"\"Instruments the kafka module\n\n        Args:\n            **kwargs: Optional arguments\n                ``tracer_provider``: a TracerProvider, defaults to global.\n                ``produce_hook``: a callable to be executed just before producing a message\n                ``consume_hook``: a callable to be executed just after consuming a message\n        \"\"\"\n        tracer_provider = kwargs.get(\"tracer_provider\")\n        produce_hook = kwargs.get(\"produce_hook\")\n        consume_hook = kwargs.get(\"consume_hook\")\n\n        tracer = trace.get_tracer(\n            __name__, __version__, tracer_provider=tracer_provider\n        )\n\n        wrap_function_wrapper(\n            kafka.KafkaProducer, \"send\", _wrap_send(tracer, produce_hook)\n        )\n        wrap_function_wrapper(\n            kafka.KafkaConsumer,\n            \"__next__\",\n            _wrap_next(tracer, consume_hook),\n        )\n\n    def _uninstrument(self, **kwargs):\n        unwrap(kafka.KafkaProducer, \"send\")\n        unwrap(kafka.KafkaConsumer, \"__next__\")\n", "path": "instrumentation/opentelemetry-instrumentation-kafka-python/src/opentelemetry/instrumentation/kafka/__init__.py"}], "after_files": [{"content": "# Copyright The OpenTelemetry Authors\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\"\"\"\nInstrument kafka-python to report instrumentation-kafka produced and consumed messages\n\nUsage\n-----\n\n..code:: python\n\n    from opentelemetry.instrumentation.kafka import KafkaInstrumentor\n    from kafka import KafkaProducer, KafkaConsumer\n\n    # Instrument kafka\n    KafkaInstrumentor().instrument()\n\n    # report a span of type producer with the default settings\n    producer = KafkaProducer(bootstrap_servers=['localhost:9092'])\n    producer.send('my-topic', b'raw_bytes')\n\n    # report a span of type consumer with the default settings\n    consumer = KafkaConsumer('my-topic', group_id='my-group', bootstrap_servers=['localhost:9092'])\n    for message in consumer:\n    # process message\n\nThe _instrument() method accepts the following keyword args:\ntracer_provider (TracerProvider) - an optional tracer provider\nproduce_hook (Callable) - a function with extra user-defined logic to be performed before sending the message\nthis function signature is:\ndef produce_hook(span: Span, args, kwargs)\nconsume_hook (Callable) - a function with extra user-defined logic to be performed after consuming a message\nthis function signature is:\ndef consume_hook(span: Span, record: kafka.record.ABCRecord, args, kwargs)\nfor example:\n\n.. code: python\n    from opentelemetry.instrumentation.kafka import KafkaInstrumentor\n    from kafka import KafkaProducer, KafkaConsumer\n\n    def produce_hook(span, args, kwargs):\n        if span and span.is_recording():\n            span.set_attribute(\"custom_user_attribute_from_produce_hook\", \"some-value\")\n    def consume_hook(span, record, args, kwargs):\n        if span and span.is_recording():\n            span.set_attribute(\"custom_user_attribute_from_consume_hook\", \"some-value\")\n\n    # instrument kafka with produce and consume hooks\n    KafkaInstrumentor().instrument(produce_hook=produce_hook, consume_hook=consume_hook)\n\n    # Using kafka as normal now will automatically generate spans,\n    # including user custom attributes added from the hooks\n    producer = KafkaProducer(bootstrap_servers=['localhost:9092'])\n    producer.send('my-topic', b'raw_bytes')\n\nAPI\n___\n\"\"\"\nfrom typing import Collection\n\nimport kafka\nfrom wrapt import wrap_function_wrapper\n\nfrom opentelemetry import trace\nfrom opentelemetry.instrumentation.instrumentor import BaseInstrumentor\nfrom opentelemetry.instrumentation.kafka.package import _instruments\nfrom opentelemetry.instrumentation.kafka.utils import _wrap_next, _wrap_send\nfrom opentelemetry.instrumentation.kafka.version import __version__\nfrom opentelemetry.instrumentation.utils import unwrap\n\n\nclass KafkaInstrumentor(BaseInstrumentor):\n    \"\"\"An instrumentor for kafka module\n    See `BaseInstrumentor`\n    \"\"\"\n\n    def instrumentation_dependencies(self) -> Collection[str]:\n        return _instruments\n\n    def _instrument(self, **kwargs):\n        \"\"\"Instruments the kafka module\n\n        Args:\n            **kwargs: Optional arguments\n                ``tracer_provider``: a TracerProvider, defaults to global.\n                ``produce_hook``: a callable to be executed just before producing a message\n                ``consume_hook``: a callable to be executed just after consuming a message\n        \"\"\"\n        tracer_provider = kwargs.get(\"tracer_provider\")\n        produce_hook = kwargs.get(\"produce_hook\")\n        consume_hook = kwargs.get(\"consume_hook\")\n\n        tracer = trace.get_tracer(\n            __name__, __version__, tracer_provider=tracer_provider\n        )\n\n        wrap_function_wrapper(\n            kafka.KafkaProducer, \"send\", _wrap_send(tracer, produce_hook)\n        )\n        wrap_function_wrapper(\n            kafka.KafkaConsumer,\n            \"__next__\",\n            _wrap_next(tracer, consume_hook),\n        )\n\n    def _uninstrument(self, **kwargs):\n        unwrap(kafka.KafkaProducer, \"send\")\n        unwrap(kafka.KafkaConsumer, \"__next__\")\n", "path": "instrumentation/opentelemetry-instrumentation-kafka-python/src/opentelemetry/instrumentation/kafka/__init__.py"}]}