microsoft/ApplicationInsights-Kubernetes

Investigation: Using a label to locate the current container

xiaomi7732 opened this issue · 1 comments

Kudos to @TTmaister.
See details: #344 (comment).

Container name looks like a good candidate for identifying the running container - considering it is more unreliable to get a container id from within the container.

The challenge is how to generalize the implementation for everyone to provide container name in the environment variable, and it worth investigating.

The example given in #344 will not always work - the container name happened to be the app label, but it can't be generalized.

Yaml anchor might be something worth looking into: https://stackoverflow.com/questions/46418441/is-it-possible-to-get-the-container-name-from-within-the-container-in-kubernetes

Also, it is possible to access all environment variables by querying the pods.

All those approaches require a level of user configuration.

Is there better way to do it?

Looked into various options and I think the one proposed by @TTmaister in #344 is a pretty good solution. As long as the environment variable of ContainerName is set to the correct value (and I believe that is not a high bar), it should work well.

Also pointed out in #344, when containerName is missing, cloud_RoleName will be missing too in Application Insights. And depends on the way telemetries are organized, it can be important. That's a good motivation to address this issue.