Skip to content

Commit d6f6c60

Browse files
authored
autoinstrumentation: don't print duplicated conflict log error message (#3432)
* Update instrumentor.py * Add tests for dependency conflict logging * Format code in test_instrument_missing_dependency * Add comments for dependency conflict handling
1 parent dd15167 commit d6f6c60

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
([#3423](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3423))
2121
- `opentelemetry-instrumentation-asyncio` Fix duplicate instrumentation
2222
([#3383](https://github.com/open-telemetry/opentelemetry-python-contrib/issues/3383))
23-
2423
- `opentelemetry-instrumentation-botocore` Add GenAI instrumentation for additional Bedrock models for InvokeModel API
2524
([#3419](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3419))
25+
- `opentelemetry-instrumentation` don't print duplicated conflict log error message
26+
([#3432](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3432))
2627

2728
## Version 1.32.0/0.53b0 (2025-04-10)
2829

opentelemetry-instrumentation/src/opentelemetry/instrumentation/instrumentor.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,12 @@ def instrument(self, **kwargs: Any):
111111
if not skip_dep_check:
112112
conflict = self._check_dependency_conflicts()
113113
if conflict:
114-
_LOG.error(conflict)
114+
# auto-instrumentation path: don't log conflict as error, instead
115+
# let _load_instrumentors handle the exception
115116
if raise_exception_on_conflict:
116117
raise DependencyConflictError(conflict)
118+
# manual instrumentation path: log the conflict as error
119+
_LOG.error(conflict)
117120
return None
118121

119122
# initialize semantic conventions opt-in if needed

opentelemetry-instrumentation/tests/test_instrumentor.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@ def test_protect(self):
5454
def test_singleton(self):
5555
self.assertIs(self.Instrumentor(), self.Instrumentor())
5656

57+
@patch("opentelemetry.instrumentation.instrumentor._LOG")
5758
@patch(
5859
"opentelemetry.instrumentation.instrumentor.BaseInstrumentor._check_dependency_conflicts"
5960
)
6061
def test_instrument_missing_dependency_raise(
61-
self, mock__check_dependency_conflicts
62+
self, mock__check_dependency_conflicts, mock_logger
6263
):
6364
instrumentor = self.Instrumentor()
6465

@@ -71,3 +72,19 @@ def test_instrument_missing_dependency_raise(
7172
instrumentor.instrument,
7273
raise_exception_on_conflict=True,
7374
)
75+
mock_logger.error.assert_not_called()
76+
77+
@patch("opentelemetry.instrumentation.instrumentor._LOG")
78+
@patch(
79+
"opentelemetry.instrumentation.instrumentor.BaseInstrumentor._check_dependency_conflicts"
80+
)
81+
def test_instrument_missing_dependency_log_error(
82+
self, mock__check_dependency_conflicts, mock_logger
83+
):
84+
instrumentor = self.Instrumentor()
85+
conflict = DependencyConflict("missing", "missing")
86+
mock__check_dependency_conflicts.return_value = conflict
87+
self.assertIsNone(
88+
instrumentor.instrument(raise_exception_on_conflict=False)
89+
)
90+
mock_logger.error.assert_any_call(conflict)

0 commit comments

Comments
 (0)