From 239e6a8fd27ddb07656741877424e5f23bea1046 Mon Sep 17 00:00:00 2001 From: Pranav Sharma Date: Tue, 7 Jan 2025 22:13:12 -0500 Subject: [PATCH] Update documentation around detecting k8s resource attributes (#1621) --- gcp-resources/README.md | 42 +++++++++++++++------------------- gcp-resources/build.gradle.kts | 1 - 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/gcp-resources/README.md b/gcp-resources/README.md index 549b53b39..2305c0e21 100644 --- a/gcp-resources/README.md +++ b/gcp-resources/README.md @@ -14,7 +14,7 @@ The following OpenTelemetry semantic conventions will be detected: | host.id | auto | auto | | | | | host.name | auto | auto | | | | | host.type | auto | auto | | | | -| k8s.pod.name | | downward API or auto | | | | +| k8s.pod.name | | downward API | | | | | k8s.namespace.name | | downward API | | | | | k8s.container.name | | hardcoded (manual) | | | | | k8s.cluster.name | | auto | | | | @@ -22,33 +22,29 @@ The following OpenTelemetry semantic conventions will be detected: | faas.version | | | auto | auto | auto | | faas.instance | | | auto | auto | auto | -## Downward API +## Setting Kubernetes attributes -For GKE applications, some values must be passed via the environment variable using k8s -"downward API". For example, the following spec will ensure `k8s.namespace.name` and -`k8s.pod.name` are correctly discovered: +This resource detector does not detect the following resource attributes +`container.name`, `k8s.pod.name` and `k8s.namespace.name`. When using this detector, +you should use this in your Pod Spec to set these using +[`OTEL_RESOURCE_ATTRIBUTES`](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.20.0/specification/resource/sdk.md#specifying-resource-information-via-an-environment-variable): ```yaml -spec: - containers: - - name: my-application - image: gcr.io/my-project/my-image:latest - env: - - name: POD_NAME - valueFrom: - fieldRef: - fieldPath: metadata.name - - name: NAMESPACE - valueFrom: - fieldRef: - fieldPath: metadata.namespace - - name: CONTAINER_NAME - value: my-application +env: +- name: POD_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name +- name: NAMESPACE_NAME + valueFrom: + fieldRef: + fieldPath: metadata.namespace +- name: CONTAINER_NAME + value: my-container-name +- name: OTEL_RESOURCE_ATTRIBUTES + value: k8s.pod.name=$(POD_NAME),k8s.namespace.name=$(NAMESPACE_NAME),k8s.container.name=$(CONTAINER_NAME) ``` -Additionally, the container name will only be discovered via the environment variable `CONTAINER_NAME` -which much be included in the environment. - ## Usage with Manual Instrumentation It is recommended to use this resource detector with the [OpenTelemetry Autoconfiguration SPI](https://github.com/open-telemetry/opentelemetry-java/blob/main/sdk-extensions/autoconfigure/README.md#resource-provider-spi). The GCP resource detector automatically provides the detected resources via the [autoconfigure-spi](https://github.com/open-telemetry/opentelemetry-java/tree/main/sdk-extensions/autoconfigure-spi) SDK extension. diff --git a/gcp-resources/build.gradle.kts b/gcp-resources/build.gradle.kts index 57e39190e..d73b1ae6a 100644 --- a/gcp-resources/build.gradle.kts +++ b/gcp-resources/build.gradle.kts @@ -28,5 +28,4 @@ dependencies { testImplementation("com.google.guava:guava") testImplementation("org.junit.jupiter:junit-jupiter-api") - testImplementation("io.opentelemetry:opentelemetry-sdk-testing") }