Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #48
Changes
This PR adds a Kubernetes (k8s) ResourceDetector for OpenTelemetry Rust contrib. The detector extracts Kubernetes-specific resource attributes (Pod name, Namespace, and Node name) from environment variables and adds them as OpenTelemetry resource attributes.
Summary of Changes:
New K8sResourceDetector:
Detects and retrieves the following k8s environment variables:
K8S_POD_NAME: The name of the Kubernetes pod.
K8S_NAMESPACE_NAME: The name of the Kubernetes namespace.
K8S_NODE_NAME: The name of the node where the pod is running.
Fallback to default values (e.g., "unknown_pod") if these environment variables are not set.
Integration with Resource Chain:
The K8sResourceDetector is added to the list of detectors when creating resources, ensuring Kubernetes-specific attributes are added seamlessly alongside existing detectors.
Unit Tests:
Unit tests are included to verify the correct behavior of the K8sResourceDetector, covering scenarios such as:
All environment variables are present.
One or more environment variables are missing.
Default values are used when environment variables are not set.
Merge requirement checklist
CHANGELOG.md
files updated for non-trivial, user-facing changes