Skip to content
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

Added k8s ResourceDetector #122

Merged
merged 2 commits into from
Oct 27, 2024
Merged

Added k8s ResourceDetector #122

merged 2 commits into from
Oct 27, 2024

Conversation

RichardChukwu
Copy link
Contributor

@RichardChukwu RichardChukwu commented Oct 22, 2024

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

  • [yes] CONTRIBUTING guidelines followed
  • [yes ] Unit tests added/updated (if applicable)
  • [Not yet ] Appropriate CHANGELOG.md files updated for non-trivial, user-facing changes
  • [N/A ] Changes in public API reviewed (if applicable)

@RichardChukwu RichardChukwu requested a review from a team as a code owner October 22, 2024 22:43
Copy link

codecov bot commented Oct 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 58.6%. Comparing base (56a6f45) to head (3ca4a7b).
Report is 38 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##            main    #122     +/-   ##
=======================================
+ Coverage   52.3%   58.6%   +6.3%     
=======================================
  Files         38      39      +1     
  Lines       4967    5774    +807     
=======================================
+ Hits        2598    3387    +789     
- Misses      2369    2387     +18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lalitb lalitb merged commit fe3b916 into open-telemetry:main Oct 27, 2024
10 checks passed
use std::time::Duration;

/// A resource detector for Kubernetes environment variables.
pub struct K8sResourceDetector;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why isn't this exported from lib.rs?

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.

Add k8s ResourceDetector
3 participants