Skip to content

resource-detector-containerid: demote failure to read cgroup files to debug #3579

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 3 commits into from
Jun 16, 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Version 1.34.0/0.55b0 (2025-06-04)

### Fixed

- `opentelemetry-resource-detector-containerid`: make it more quiet on platforms without cgroups
([#3579](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3579))

### Added

- `opentelemetry-instrumentation-aiokafka` Add instrumentation of `consumer.getmany` (batch)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def _get_container_id_v1():
break

except FileNotFoundError as exception:
logger.warning("Failed to get container id. Exception: %s", exception)
logger.debug("Failed to get container id. Exception: %s", exception)
return container_id


Expand All @@ -66,7 +66,7 @@ def _get_container_id_v2():
break

except FileNotFoundError as exception:
logger.warning("Failed to get container id. Exception: %s", exception)
logger.debug("Failed to get container id. Exception: %s", exception)
return container_id


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,48 @@ def test_container_id_detect_from_mountinfo_file(
actual.attributes.copy(), MockContainerResourceAttributes
)

@patch(
"opentelemetry.resource.detector.containerid._get_container_id_v1",
return_value=None,
)
@patch(
"builtins.open",
side_effect=FileNotFoundError,
)
def test_cannot_read_mountinfo_file(
self, mock_get_container_id_v1, mock_mountinfo_file
):
with self.assertLogs(
"opentelemetry.resource.detector.containerid", level="DEBUG"
) as cm:
actual = ContainerResourceDetector().detect()
self.assertFalse(actual.attributes.copy())
self.assertIn(
"DEBUG:opentelemetry.resource.detector.containerid:Failed to get container id. Exception: ",
cm.output,
)

@patch(
"opentelemetry.resource.detector.containerid._get_container_id_v2",
return_value=None,
)
@patch(
"builtins.open",
side_effect=FileNotFoundError,
)
def test_cannot_read_cgroup_file(
self, mock_get_container_id_v2, mock_cgroup_file
):
with self.assertLogs(
"opentelemetry.resource.detector.containerid", level="DEBUG"
) as cm:
actual = ContainerResourceDetector().detect()
self.assertFalse(actual.attributes.copy())
self.assertIn(
"DEBUG:opentelemetry.resource.detector.containerid:Failed to get container id. Exception: ",
cm.output,
)

@patch(
"opentelemetry.resource.detector.containerid._get_container_id",
return_value=MockContainerResourceAttributes[
Expand Down