Skip to content

Request to Add Detector for Kubernetes #4136

Open
@dashpole

Description

Background

At one point, I had written an OTep about how kubernetes resource detectors should function, but it wasn't accepted due to lack of interest. open-telemetry/oteps#195

I was recently reminded of the impact of this in #2310 (comment).

Proposed Solution

Add a Kubernetes resource detector in detectors/kubernetes/. It will have a single implementation of the resource.Detector interface, and no configuration.

It will detect:

  • k8s.container.name
  • k8s.pod.name
  • k8s.pod.uid
  • k8s.namespace.name
  • k8s.node.name

From:

  • OTEL_RESOURCE_ATTRIBUTES_K8S_CONTAINER_NAME
  • OTEL_RESOURCE_ATTRIBUTES_K8S_POD_NAME
  • OTEL_RESOURCE_ATTRIBUTES_K8S_POD_UID
  • OTEL_RESOURCE_ATTRIBUTES_K8S_NAMESPACE_NAME
  • OTEL_RESOURCE_ATTRIBUTES_K8S_NODE_NAME

If pod name is not discovered, fall back to the HOSTNAME env var. This defaults to the pod's name, but can be overridden in the pod spec.

If pod namespace is not discovered, fall back to reading /var/run/secrets/kubernetes.io/serviceaccount/namespace. This is always the pod's namespace AFAIK, but isn't a recommended way to get it.

Prior Art

OTel Operator: https://github.com/open-telemetry/opentelemetry-operator/blob/76cff59b0c0640da29c56d5ae91eae5fe843ae5b/pkg/constants/env.go#L25

Tasks

  • Code complete:
    • Comprehensive unit tests.
    • End-to-end integration tests.
    • Tests all passing.
    • Instrumentation functionality verified.
  • Documented
  • Examples
    • Dockerfile file to build example application.
    • docker-compose.yml to run example in a docker environment to demonstrate instrumentation.

@jaredjenkins

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions