Add "instruments-any" feature: unblock multi-target instrumentations while fixing dependency conflict breakage. (#3610)

This commit is contained in:
Jeremy Voss
2025-07-21 09:24:50 -07:00
committed by GitHub
parent f20fa77ad5
commit 77f3171bd4
20 changed files with 574 additions and 90 deletions

View File

@ -31,7 +31,8 @@ dependencies = [
]
[project.optional-dependencies]
instruments = [
instruments = []
instruments-any = [
"kafka-python >= 2.0, < 3.0",
"kafka-python-ng >= 2.0, < 3.0"
]

View File

@ -91,7 +91,7 @@ from wrapt import wrap_function_wrapper
from opentelemetry import trace
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
from opentelemetry.instrumentation.kafka.package import (
_instruments,
_instruments_any,
_instruments_kafka_python,
_instruments_kafka_python_ng,
)
@ -123,7 +123,7 @@ class KafkaInstrumentor(BaseInstrumentor):
except PackageNotFoundError:
pass
return _instruments
return _instruments_any
def _instrument(self, **kwargs):
"""Instruments the kafka module

View File

@ -16,4 +16,5 @@
_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)
_instruments = ()
_instruments_any = (_instruments_kafka_python, _instruments_kafka_python_ng)

View File

@ -20,7 +20,6 @@ from wrapt import BoundFunctionWrapper
from opentelemetry.instrumentation.kafka import KafkaInstrumentor
from opentelemetry.instrumentation.kafka.package import (
_instruments,
_instruments_kafka_python,
_instruments_kafka_python_ng,
)
@ -134,4 +133,7 @@ class TestKafka(TestCase):
call("kafka-python"),
],
)
self.assertEqual(package_to_instrument, _instruments)
self.assertEqual(
package_to_instrument,
(_instruments_kafka_python, _instruments_kafka_python_ng),
)