Skip to content

[SDK] Implementation of container resource as per semconv #3572

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

Conversation

nikhilbhatia08
Copy link
Contributor

@nikhilbhatia08 nikhilbhatia08 commented Jul 29, 2025

Fixes # (issue)
Partially fixes #3548

Changes

Added container resource detector only for collecting info about container.id from /proc/self/cgroup and added test coverage to it, but could not add test coverage to Detect() of ContainerResource

Please provide a brief description of the changes here.

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@nikhilbhatia08 nikhilbhatia08 requested a review from a team as a code owner July 29, 2025 17:11
Copy link

linux-foundation-easycla bot commented Jul 29, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

Copy link

netlify bot commented Jul 29, 2025

Deploy Preview for opentelemetry-cpp-api-docs canceled.

Name Link
🔨 Latest commit 018a1f8
🔍 Latest deploy log https://app.netlify.com/projects/opentelemetry-cpp-api-docs/deploys/6898d0cd0f0daa00088d7918

Copy link

codecov bot commented Jul 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.08%. Comparing base (5f6d99f) to head (fd93b32).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3572      +/-   ##
==========================================
+ Coverage   90.03%   90.08%   +0.06%     
==========================================
  Files         220      222       +2     
  Lines        7069     7115      +46     
==========================================
+ Hits         6364     6409      +45     
- Misses        705      706       +1     
Files with missing lines Coverage Δ
resource_detectors/container_detector_utils.cc 100.00% <100.00%> (ø)
resource_detectors/test/container_detector_test.cc 100.00% <100.00%> (ø)
sdk/src/resource/resource_detector.cc 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lalitb lalitb requested a review from Copilot July 29, 2025 17:55
Copilot

This comment was marked as outdated.

Copilot

This comment was marked as outdated.

@dbarker
Copy link
Member

dbarker commented Aug 5, 2025

Thanks for the PR @nikhilbhatia08! I think we just need to hash out how best to include these "built-in" detectors in the repo/build systems since many will bring platform dependencies. I've posted my proposal to the initial issue thread.

@lalitb lalitb requested a review from Copilot August 8, 2025 17:49
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements a container resource detector that extracts container IDs from cgroup information to comply with OpenTelemetry semantic conventions. The implementation focuses specifically on detecting the container.id attribute by parsing /proc/self/cgroup files.

  • Adds a new ContainerResourceDetector class that reads container ID from cgroup files
  • Implements helper functions for parsing container IDs from cgroup file lines using regex
  • Adds comprehensive test coverage for container ID extraction logic

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
resource_detectors/include/opentelemetry/resource_detectors/container_resource_detector.h Header file defining the ContainerResourceDetector class and helper functions
resource_detectors/container_detector.cc Implementation of the ContainerResourceDetector::Detect() method
resource_detectors/container.cc Implementation of container ID extraction logic from cgroup files
resource_detectors/CMakeLists.txt CMake configuration for the new resource_detectors library
resource_detectors/BUILD Bazel build configuration for the resource_detectors library
sdk/test/resource/resource_test.cc Test cases for container ID extraction functionality
sdk/test/resource/CMakeLists.txt Updated test dependencies to include resource_detectors
sdk/test/resource/BUILD Updated Bazel test dependencies
sdk/src/resource/resource_detector.cc Refactored environment variable constants to use constexpr
CMakeLists.txt Added resource_detectors subdirectory to build

Copy link
Member

@lalitb lalitb left a comment

Choose a reason for hiding this comment

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

LGTM, once preview flag is added and approved by @dbarker. Thanks @nikhilbhatia08 for contribution, nice work.

Copy link
Member

@dbarker dbarker left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks for the PR. Congrats on your first contribution! Looking forward to the next one :)

@nikhilbhatia08
Copy link
Contributor Author

Thank you so much, @dbarker, @lalitb, and @rafaelroquetto, for helping me with my first contribution! Really appreciate it :) Looking forward to contributing more.

@lalitb lalitb merged commit fab6a41 into open-telemetry:main Aug 10, 2025
69 checks passed
@nikhilbhatia08 nikhilbhatia08 deleted the implement_resource_detectors branch August 13, 2025 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[SDK] Implement resource detectors
8 participants