Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- `opentelemetry-instrumentation-psycopg2` Add support for psycopg2-binary library
([#1422](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1422))
- `opentelemetry-instrumentation-redis` Add `sanitize_query` config option to allow query sanitization. ([#1572](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1572))
- `opentelemetry-instrumentation-celery` Record exceptions as events on the span.
([#1573](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1573))
Expand Down
2 changes: 1 addition & 1 deletion instrumentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
| [opentelemetry-instrumentation-logging](./opentelemetry-instrumentation-logging) | logging | No
| [opentelemetry-instrumentation-mysql](./opentelemetry-instrumentation-mysql) | mysql-connector-python ~= 8.0 | No
| [opentelemetry-instrumentation-pika](./opentelemetry-instrumentation-pika) | pika >= 0.12.0 | No
| [opentelemetry-instrumentation-psycopg2](./opentelemetry-instrumentation-psycopg2) | psycopg2 >= 2.7.3.1 | No
| [opentelemetry-instrumentation-psycopg2](./opentelemetry-instrumentation-psycopg2) | psycopg2 >= 2.7.3.1, psycopg2-binary >= 2.7.3.1 | No
| [opentelemetry-instrumentation-pymemcache](./opentelemetry-instrumentation-pymemcache) | pymemcache >= 1.3.5, < 4 | No
| [opentelemetry-instrumentation-pymongo](./opentelemetry-instrumentation-pymongo) | pymongo >= 3.1, < 5.0 | No
| [opentelemetry-instrumentation-pymysql](./opentelemetry-instrumentation-pymysql) | PyMySQL < 2 | No
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# limitations under the License.


_instruments = ("psycopg2 >= 2.7.3.1",)
_instruments = (("psycopg2 >= 2.7.3.1", "psycopg2-binary >= 2.7.3.1"),)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_instruments = (("psycopg2 >= 2.7.3.1", "psycopg2-binary >= 2.7.3.1"),)
_instruments = ("psycopg2 >= 2.7.3.1", "psycopg2-binary >= 2.7.3.1")

This is what the kafka-python is doing, please take a look at opentelemetry-instrumentation-kafka-python/pyproject.toml, with that updated you should be able to drop the dependencies,py changes.

Copy link
Contributor

@joshowen joshowen Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've done the minimal implementation here #3186

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from logging import getLogger
from typing import Collection, Optional
from typing import Collection, Optional, Union

from pkg_resources import (
Distribution,
Expand Down Expand Up @@ -42,21 +42,51 @@ def get_dist_dependency_conflicts(
return get_dependency_conflicts(instrumentation_deps)


def check_dependency_conflicts(dep: str) -> Optional[DependencyConflict]:
try:
get_distribution(dep)
except VersionConflict as exc:
return DependencyConflict(dep, exc.dist)
except DistributionNotFound:
return DependencyConflict(dep)
except RequirementParseError as exc:
logger.warning(
'error parsing dependency, reporting as a conflict: "%s" - %s',
dep,
exc,
)
return DependencyConflict(dep)
return None


def merge_dependency_conflicts(
conflicts: Collection[DependencyConflict],
) -> DependencyConflict:
return DependencyConflict(
required=" or ".join(
[conflict.required for conflict in conflicts if conflict.required]
),
found=" and ".join(
[conflict.found for conflict in conflicts if conflict.found]
)
or None,
)


def get_dependency_conflicts(
deps: Collection[str],
deps: Collection[Union[str, tuple]],
) -> Optional[DependencyConflict]:
for dep in deps:
try:
get_distribution(dep)
except VersionConflict as exc:
return DependencyConflict(dep, exc.dist)
except DistributionNotFound:
return DependencyConflict(dep)
except RequirementParseError as exc:
logger.warning(
'error parsing dependency, reporting as a conflict: "%s" - %s',
dep,
exc,
)
return DependencyConflict(dep)
if isinstance(dep, tuple):
checks = [
check_dependency_conflicts(dep_option) for dep_option in dep
]
successful_checks = [check for check in checks if check is None]
if len(successful_checks) > 0:
return None
failed_checks = [check for check in checks if check is not None]
return merge_dependency_conflicts(failed_checks)
conflict = check_dependency_conflicts(dep)
if conflict:
return conflict
return None
26 changes: 26 additions & 0 deletions opentelemetry-instrumentation/tests/test_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,32 @@ def test_get_dependency_conflicts_not_installed(self):
'DependencyConflict: requested: "this-package-does-not-exist" but found: "None"',
)

def test_get_dependency_conflicts_multiple_possible_dependencies_not_installed(
self,
):
conflict = get_dependency_conflicts(
[
(
"this-package-does-not-exist",
"this-package-also-does-not-exist",
)
]
)
self.assertTrue(conflict is not None)
self.assertTrue(isinstance(conflict, DependencyConflict))
self.assertEqual(
str(conflict),
'DependencyConflict: requested: "this-package-does-not-exist or this-package-also-does-not-exist" but found: "None"',
)

def test_get_dependency_conflicts_multiple_possible_dependencies_one_installed(
self,
):
conflict = get_dependency_conflicts(
[("this-package-does-not-exist", "pytest")]
)
self.assertIsNone(conflict)

def test_get_dependency_conflicts_mismatched_version(self):
conflict = get_dependency_conflicts(["pytest == 5000"])
self.assertTrue(conflict is not None)
Expand Down
7 changes: 7 additions & 0 deletions scripts/generate_instrumentation_readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ def main():
if not instruments:
instruments = (name,)

instruments = [
", ".join(instrument)
if isinstance(instrument, tuple)
else instrument
for instrument in instruments
]

metric_column = "Yes" if supports_metrics else "No"

table.append(
Expand Down