Skip to content

autoinstrumentation: don't print duplicated conflict log error message #3432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 18, 2025
Merged
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#3423](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3423))
- `opentelemetry-instrumentation-asyncio` Fix duplicate instrumentation
([#3383](https://github.com/open-telemetry/opentelemetry-python-contrib/issues/3383))

- `opentelemetry-instrumentation-botocore` Add GenAI instrumentation for additional Bedrock models for InvokeModel API
([#3419](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3419))
- `opentelemetry-instrumentation` don't print duplicated conflict log error message
([#3432](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3432))

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,12 @@ def instrument(self, **kwargs: Any):
if not skip_dep_check:
conflict = self._check_dependency_conflicts()
if conflict:
_LOG.error(conflict)
# auto-instrumentation path: don't log conflict as error, instead
# let _load_instrumentors handle the exception
if raise_exception_on_conflict:
raise DependencyConflictError(conflict)
# manual instrumentation path: log the conflict as error
_LOG.error(conflict)
return None

# initialize semantic conventions opt-in if needed
Expand Down
19 changes: 18 additions & 1 deletion opentelemetry-instrumentation/tests/test_instrumentor.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ def test_protect(self):
def test_singleton(self):
self.assertIs(self.Instrumentor(), self.Instrumentor())

@patch("opentelemetry.instrumentation.instrumentor._LOG")
@patch(
"opentelemetry.instrumentation.instrumentor.BaseInstrumentor._check_dependency_conflicts"
)
def test_instrument_missing_dependency_raise(
self, mock__check_dependency_conflicts
self, mock__check_dependency_conflicts, mock_logger
):
instrumentor = self.Instrumentor()

Expand All @@ -71,3 +72,19 @@ def test_instrument_missing_dependency_raise(
instrumentor.instrument,
raise_exception_on_conflict=True,
)
mock_logger.error.assert_not_called()

@patch("opentelemetry.instrumentation.instrumentor._LOG")
@patch(
"opentelemetry.instrumentation.instrumentor.BaseInstrumentor._check_dependency_conflicts"
)
def test_instrument_missing_dependency_log_error(
self, mock__check_dependency_conflicts, mock_logger
):
instrumentor = self.Instrumentor()
conflict = DependencyConflict("missing", "missing")
mock__check_dependency_conflicts.return_value = conflict
self.assertIsNone(
instrumentor.instrument(raise_exception_on_conflict=False)
)
mock_logger.error.assert_any_call(conflict)