opentelemetry-go
opentelemetry-go copied to clipboard
add host.id to resource auto-detection
This PR adds host id detection support for non-containerized hosts. The implementation is based on this spec pr: https://github.com/open-telemetry/opentelemetry-specification/pull/3173.
Fixes #3811
Summary
- This PR introduces a
hostIDReaderinterface with platform specific implementations for Darwin, Linux, BSD, Windows and a fallback for unsupported platfoms. - The platform specific implementations use unprivileged means to lookup the
host.id, aka machine id for non-containerized environments. Depending on platform this involves reading files in well known locations, excuting shell commands, or a combination of the two. - I followed the code organization used for the OS Description Detector, which also has platform specific implementations, however, there is one notable difference. Currently the Go SDK divides platform specific code into darwin, unix, and windows and the associated build tags for those platforms. Host id detection is more granular and requires dividing unix into linux and BSD.
See also
- Spec PR: https://github.com/open-telemetry/opentelemetry-specification/pull/3173
- JS Implementation: https://github.com/open-telemetry/opentelemetry-js/pull/3575
- Collector PR (using gopsutil): https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/18740
I realize we will want to see the spec PR merge before getting too serious about this work, but I wanted to get some eyes on the approach and encourage anyone with opinions to provide feedback here and on the spec PR.
Codecov Report
:exclamation: No coverage uploaded for pull request base (
main@1eab60f). Click here to learn what that means. The diff coverage is74.0%.
:exclamation: Current head 6df6880 differs from pull request most recent head 3230472. Consider uploading reports for the commit 3230472 to get more accurate results
Additional details and impacted files
@@ Coverage Diff @@
## main #3812 +/- ##
======================================
Coverage ? 81.5%
======================================
Files ? 170
Lines ? 12765
Branches ? 0
======================================
Hits ? 10415
Misses ? 2131
Partials ? 219
| Impacted Files | Coverage Δ | |
|---|---|---|
| sdk/resource/host_id.go | 73.0% <73.0%> (ø) |
|
| sdk/resource/config.go | 100.0% <100.0%> (ø) |
I wanted to check in to see if there is anything that anyone would like to see addressed in this PR?