Update documentation around detecting k8s resource attributes (#1621)

This commit is contained in:
Pranav Sharma 2025-01-07 22:13:12 -05:00 committed by GitHub
parent 6069c1df8b
commit 239e6a8fd2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 24 deletions

View File

@ -14,7 +14,7 @@ The following OpenTelemetry semantic conventions will be detected:
| host.id | auto | auto | | | | | host.id | auto | auto | | | |
| host.name | auto | auto | | | | | host.name | auto | auto | | | |
| host.type | auto | auto | | | | | host.type | auto | auto | | | |
| k8s.pod.name | | downward API or auto | | | | | k8s.pod.name | | downward API | | | |
| k8s.namespace.name | | downward API | | | | | k8s.namespace.name | | downward API | | | |
| k8s.container.name | | hardcoded (manual) | | | | | k8s.container.name | | hardcoded (manual) | | | |
| k8s.cluster.name | | auto | | | | | k8s.cluster.name | | auto | | | |
@ -22,33 +22,29 @@ The following OpenTelemetry semantic conventions will be detected:
| faas.version | | | auto | auto | auto | | faas.version | | | auto | auto | auto |
| faas.instance | | | 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 This resource detector does not detect the following resource attributes
"downward API". For example, the following spec will ensure `k8s.namespace.name` and `container.name`, `k8s.pod.name` and `k8s.namespace.name`. When using this detector,
`k8s.pod.name` are correctly discovered: 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 ```yaml
spec: env:
containers: - name: POD_NAME
- name: my-application valueFrom:
image: gcr.io/my-project/my-image:latest fieldRef:
env: fieldPath: metadata.name
- name: POD_NAME - name: NAMESPACE_NAME
valueFrom: valueFrom:
fieldRef: fieldRef:
fieldPath: metadata.name fieldPath: metadata.namespace
- name: NAMESPACE - name: CONTAINER_NAME
valueFrom: value: my-container-name
fieldRef: - name: OTEL_RESOURCE_ATTRIBUTES
fieldPath: metadata.namespace value: k8s.pod.name=$(POD_NAME),k8s.namespace.name=$(NAMESPACE_NAME),k8s.container.name=$(CONTAINER_NAME)
- name: CONTAINER_NAME
value: my-application
``` ```
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 ## 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. 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.

View File

@ -28,5 +28,4 @@ dependencies {
testImplementation("com.google.guava:guava") testImplementation("com.google.guava:guava")
testImplementation("org.junit.jupiter:junit-jupiter-api") testImplementation("org.junit.jupiter:junit-jupiter-api")
testImplementation("io.opentelemetry:opentelemetry-sdk-testing")
} }