Skip to content

Commit 033d8ac

Browse files
committed
clean up
1 parent 8e7e651 commit 033d8ac

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
([#3567](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3567))
1818
- `opentelemetry-resource-detector-containerid`: make it more quiet on platforms without cgroups
1919
([#3579](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3579))
20-
- `opentelemetry-instrumentation`: Fix dependency conflict detection when instrumented packages are not installed. Add "instruments_either" feature for instrumentations that target multiple packages.
20+
- `opentelemetry-instrumentation`: Fix dependency conflict detection when instrumented packages are not installed by moving check back to before instrumentors are loaded. Add "instruments_either" feature for instrumentations that target multiple packages.
2121
([#3610](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3610))
2222

2323
### Added

instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_instrumentation.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ def _instrumentation_loaded_successfully_call():
146146
return call("Instrumented %s", "psycopg2")
147147

148148
mock_distro = Mock()
149-
# TODO: This test previously did nothing. By mocking the distro, it blocked any possibility of a dependency conflict. Mocking no dependency conflict for no. But, in the future, update this package toml with the instruemnts_either field. See https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3610
150149
mock_dep.return_value = None
151150
mock_distro.load_instrumentor.return_value = None
152151
_load_instrumentors(mock_distro)

opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/_load.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ def _load_instrumentors(distro):
115115
distro.load_instrumentor(entry_point, skip_dep_check=True)
116116
_logger.debug("Instrumented %s", entry_point.name)
117117
except DependencyConflictError as exc:
118-
# DependencyConflicts will generally arise without exception from the get_dist_dependency_conflicts call before instrumentation is attempted. Keeping this exception in case of custom distro and instrumentor behavior. See https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3610 for details.
118+
# Dependency conflicts are generally caught from get_dist_dependency_conflicts
119+
# returning a DependencyConflict. Keeping this error handling in case custom
120+
# distro and instrumentor behavior raises a DependencyConflictError later.
121+
# See https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3610
119122
_logger.debug(
120123
"Skipping instrumentation %s: %s",
121124
entry_point.name,
@@ -142,7 +145,6 @@ def _load_instrumentors(distro):
142145
)
143146
continue
144147
except Exception as exc: # pylint: disable=broad-except
145-
# print("Skipping instrumentation %s: %s" % (entry_point.name, exc))
146148
_logger.exception("Instrumenting of %s failed", entry_point.name)
147149
raise exc
148150

opentelemetry-instrumentation/src/opentelemetry/instrumentation/dependencies.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,27 @@
2929

3030

3131
class DependencyConflict:
32+
"""Represents a dependency conflict in OpenTelemetry instrumentation.
33+
34+
This class is used to track conflicts between required dependencies and the
35+
actual installed packages. It supports two scenarios:
36+
37+
1. Standard conflicts where all dependencies are required
38+
2. Either/or conflicts where only one of a set of dependencies is required
39+
40+
Attributes:
41+
required: The required dependency specification that conflicts with what's installed.
42+
found: The actual dependency that was found installed (if any).
43+
required_either: Collection of dependency specifications where any one would satisfy
44+
the requirement (for either/or scenarios).
45+
found_either: Collection of actual dependencies found for either/or scenarios.
46+
"""
47+
3248
required: str | None = None
3349
found: str | None = None
3450
# The following fields are used when an instrumentation requires any of a set of dependencies rather than all.
35-
required_either: Collection[str] = []
36-
found_either: Collection[str] = []
51+
required_either: Collection[str] = None
52+
found_either: Collection[str] = None
3753

3854
def __init__(
3955
self,

opentelemetry-instrumentation/tests/auto_instrumentation/test_load.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,13 +386,10 @@ def test_load_instrumentors_import_error_does_not_stop_everything(
386386
@patch(
387387
"opentelemetry.instrumentation.auto_instrumentation._load.get_dist_dependency_conflicts"
388388
)
389-
@patch("opentelemetry.instrumentation.auto_instrumentation._load._logger")
390389
@patch(
391390
"opentelemetry.instrumentation.auto_instrumentation._load.entry_points"
392391
)
393-
def test_load_instrumentors_raises_exception(
394-
self, iter_mock, mock_logger, mock_dep
395-
):
392+
def test_load_instrumentors_raises_exception(self, iter_mock, mock_dep):
396393
ep_mock1 = Mock(name="instr1")
397394
ep_mock2 = Mock(name="instr2")
398395

0 commit comments

Comments
 (0)