Skip to content

Commit

Permalink
Instrument temporary fork, kafka-python-ng inside kafka-python's inst…
Browse files Browse the repository at this point in the history
…rumentation
  • Loading branch information
rjduffner committed May 21, 2024
1 parent f8758c6 commit 9e5770d
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#2397](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2397)))
- `opentelemetry-processor-baggage` Initial release
([#2436](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2436))
- `opentelemetry-instrumentation-kafka-python` Instrument temporary fork, kafka-python-ng
inside kafka-python's instrumentation
([#2537](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2537)))

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion instrumentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
| [opentelemetry-instrumentation-grpc](./opentelemetry-instrumentation-grpc) | grpcio ~= 1.27 | No | experimental
| [opentelemetry-instrumentation-httpx](./opentelemetry-instrumentation-httpx) | httpx >= 0.18.0 | No | experimental
| [opentelemetry-instrumentation-jinja2](./opentelemetry-instrumentation-jinja2) | jinja2 >= 2.7, < 4.0 | No | experimental
| [opentelemetry-instrumentation-kafka-python](./opentelemetry-instrumentation-kafka-python) | kafka-python >= 2.0 | No | experimental
| [opentelemetry-instrumentation-kafka-python](./opentelemetry-instrumentation-kafka-python) | kafka-python >= 2.0, < 3.0 | No | experimental
| [opentelemetry-instrumentation-logging](./opentelemetry-instrumentation-logging) | logging | No | experimental
| [opentelemetry-instrumentation-mysql](./opentelemetry-instrumentation-mysql) | mysql-connector-python ~= 8.0 | No | experimental
| [opentelemetry-instrumentation-mysqlclient](./opentelemetry-instrumentation-mysqlclient) | mysqlclient < 3 | No | experimental
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ dependencies = [

[project.optional-dependencies]
instruments = [
"kafka-python >= 2.0",
"kafka-python >= 2.0, < 3.0",
"kafka-python-ng >= 2.0, < 3.0"
]

[project.entry-points.opentelemetry_instrumentor]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,15 @@ def consume_hook(span, record, args, kwargs):
API
___
"""
from importlib.metadata import distribution, PackageNotFoundError
from typing import Collection

import kafka
from wrapt import wrap_function_wrapper

from opentelemetry import trace
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
from opentelemetry.instrumentation.kafka.package import _instruments
from opentelemetry.instrumentation.kafka.package import _instruments, _instruments_ng
from opentelemetry.instrumentation.kafka.utils import _wrap_next, _wrap_send
from opentelemetry.instrumentation.kafka.version import __version__
from opentelemetry.instrumentation.utils import unwrap
Expand All @@ -86,6 +87,17 @@ class KafkaInstrumentor(BaseInstrumentor):
"""

def instrumentation_dependencies(self) -> Collection[str]:
# Determine which package of kafka-python is installed
# Right now there are two packages, kafka-python and kafka-python-ng
# The latter is a fork of the former because the former is connected
# to a pypi namespace that the current maintainers cannot access
# https://github.com/dpkp/kafka-python/issues/2431
try:
distribution("kafka-python-ng")
return _instruments_ng
except PackageNotFoundError:
pass

return _instruments

def _instrument(self, **kwargs):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
# limitations under the License.


_instruments = ("kafka-python >= 2.0",)
_instruments = ("kafka-python >= 2.0, < 3.0",)
_instruments_ng = ("kafka-python-ng >= 2.0, < 3.0",)
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@
"instrumentation": "opentelemetry-instrumentation-jinja2==0.46b0.dev",
},
{
"library": "kafka-python >= 2.0",
"library": "kafka-python >= 2.0, < 3.0",
"instrumentation": "opentelemetry-instrumentation-kafka-python==0.46b0.dev",
},
{
"library": "kafka-python-ng >= 2.0, < 3.0",
"instrumentation": "opentelemetry-instrumentation-kafka-python==0.46b0.dev",
},
{
Expand Down

0 comments on commit 9e5770d

Please sign in to comment.