opentelemetry-java
opentelemetry-java copied to clipboard
Add auto-detection of container information to resource if cgroupv2 is used
Follow-up to #3308 & related ticket with js: https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1173
Is your feature request related to a problem? Please describe.
Detection of the container.id in ContainerResource.java currently works by reading from /proc/self/cgroup. That does not work when cgroupv2 is turned on. However, based on these two sources there's another place to read from:
- How to get docker container ID from within the container with cgroup v2
- Python NullResource error when running torizoncore-builder build
In short, the container.id could be read from /proc/self/mountinfo as well. This also works for containerd and not only docker.
Eventually it would be good to have a standard for that, but unfortunately this is a long-standing non-moving OCI issue, until then a combination of both approaches seems to be reliable enough.
Describe the solution you'd like
Add code that reads the container id from /proc/self/mountinfo if reading from /proc/self/cgroup failed.
Describe alternatives you've considered As stated in the description, eventually it would be great to have this standardized, but until then this is the best way to go.
cc: @lo-jason , @PeterF778