Skip to content

Commit

Permalink
Merge branch 'main' into issue_2555, fix changelog conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
jgibo committed Aug 5, 2024
2 parents d96e92c + ca0dd50 commit 4937ee7
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/instrumentations_1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
- "util-http"
- "fastapislim"
- "processor-baggage"
- "kafka-pythonng"
os: [ubuntu-20.04]
exclude:
- python-version: pypy3
Expand Down
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased


## Added

- `opentelemetry-instrumentation-tornado` Handle http client exception and record exception info into span
([#2563](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2563))
- `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)))

## Breaking changes

## Fixed
Expand All @@ -28,6 +29,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#2589](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2589))
- `opentelemetry-instrumentation-celery` propagates baggage
([#2385](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2385))
- `opentelemetry-instrumentation-tornado` Handle http client exception and record exception info into span
([#2563](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2563))

## Version 1.26.0/0.47b0 (2024-07-23)

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 | migration
| [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,kafka-python-ng >= 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, < 10.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 @@ -15,6 +15,6 @@ pytest-benchmark==4.0.0
tomli==2.0.1
typing_extensions==4.9.0
wrapt==1.16.0
zipp==3.17.0
zipp==3.19.2
-e opentelemetry-instrumentation
-e instrumentation/opentelemetry-instrumentation-grpc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ classifiers = [
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
dependencies = [
"opentelemetry-api ~= 1.5",
Expand All @@ -31,7 +32,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,19 @@ def consume_hook(span, record, args, kwargs):
API
___
"""
from importlib.metadata import PackageNotFoundError, distribution
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_kafka_python,
_instruments_kafka_python_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 +91,23 @@ 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_kafka_python_ng,)
except PackageNotFoundError:
pass

try:
distribution("kafka-python")
return (_instruments_kafka_python,)
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,7 @@
# limitations under the License.


_instruments = ("kafka-python >= 2.0",)
_instruments_kafka_python = "kafka-python >= 2.0, < 3.0"
_instruments_kafka_python_ng = "kafka-python-ng >= 2.0, < 3.0"

_instruments = (_instruments_kafka_python, _instruments_kafka_python_ng)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
asgiref==3.7.2
Deprecated==1.2.14
importlib-metadata==6.11.0
iniconfig==2.0.0
kafka-python-ng==2.2.2
packaging==24.0
pluggy==1.5.0
py-cpuinfo==9.0.0
pytest==7.4.4
tomli==2.0.1
typing_extensions==4.9.0
wrapt==1.16.0
zipp==3.19.2
-e opentelemetry-instrumentation
-e instrumentation/opentelemetry-instrumentation-kafka-python
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@
"instrumentation": "opentelemetry-instrumentation-jinja2==0.48b0.dev",
},
{
"library": "kafka-python >= 2.0",
"library": "kafka-python >= 2.0, < 3.0",
"instrumentation": "opentelemetry-instrumentation-kafka-python==0.48b0.dev",
},
{
"library": "kafka-python-ng >= 2.0, < 3.0",
"instrumentation": "opentelemetry-instrumentation-kafka-python==0.48b0.dev",
},
{
Expand Down
9 changes: 9 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,9 @@ envlist =

; opentelemetry-instrumentation-kafka-python
py3{8,9,10,11}-test-instrumentation-kafka-python
py3{8,9,10,11,12}-test-instrumentation-kafka-pythonng
pypy3-test-instrumentation-kafka-python
pypy3-test-instrumentation-kafka-pythonng
lint-instrumentation-kafka-python

; opentelemetry-instrumentation-confluent-kafka
Expand Down Expand Up @@ -443,6 +445,10 @@ commands_pre =
kafka-python: pip install opentelemetry-semantic-conventions@{env:CORE_REPO}\#egg=opentelemetry-semantic-conventions&subdirectory=opentelemetry-semantic-conventions
kafka-python: pip install opentelemetry-sdk@{env:CORE_REPO}\#egg=opentelemetry-sdk&subdirectory=opentelemetry-sdk
kafka-python: pip install -r {toxinidir}/instrumentation/opentelemetry-instrumentation-kafka-python/test-requirements.txt
kafka-pythonng: pip install opentelemetry-api@{env:CORE_REPO}\#egg=opentelemetry-api&subdirectory=opentelemetry-api
kafka-pythonng: pip install opentelemetry-semantic-conventions@{env:CORE_REPO}\#egg=opentelemetry-semantic-conventions&subdirectory=opentelemetry-semantic-conventions
kafka-pythonng: pip install opentelemetry-sdk@{env:CORE_REPO}\#egg=opentelemetry-sdk&subdirectory=opentelemetry-sdk
kafka-pythonng: pip install -r {toxinidir}/instrumentation/opentelemetry-instrumentation-kafka-python/test-requirements-ng.txt

confluent-kafka: pip install opentelemetry-api@{env:CORE_REPO}\#egg=opentelemetry-api&subdirectory=opentelemetry-api
confluent-kafka: pip install opentelemetry-semantic-conventions@{env:CORE_REPO}\#egg=opentelemetry-semantic-conventions&subdirectory=opentelemetry-semantic-conventions
Expand Down Expand Up @@ -940,6 +946,9 @@ commands =
lint-instrumentation-kafka-python: flake8 --config {toxinidir}/.flake8 {toxinidir}/instrumentation/opentelemetry-instrumentation-kafka-python
lint-instrumentation-kafka-python: sh -c "cd instrumentation && pylint --rcfile ../.pylintrc opentelemetry-instrumentation-kafka-python"

; Test only for kafka-pythonng instrumentation as the only difference between kafka-python and kafka-pythonng is the version of kafka-python
test-instrumentation-kafka-pythonng: pytest {toxinidir}/instrumentation/opentelemetry-instrumentation-kafka-python/tests {posargs}

test-instrumentation-confluent-kafka: pytest {toxinidir}/instrumentation/opentelemetry-instrumentation-confluent-kafka/tests {posargs}
lint-instrumentation-confluent-kafka: black --diff --check --config {toxinidir}/pyproject.toml {toxinidir}/instrumentation/opentelemetry-instrumentation-confluent-kafka
lint-instrumentation-confluent-kafka: isort --diff --check-only --settings-path {toxinidir}/.isort.cfg {toxinidir}/instrumentation/opentelemetry-instrumentation-confluent-kafka
Expand Down

0 comments on commit 4937ee7

Please sign in to comment.