Skip to content

Commit

Permalink
Update documentation around detecting k8s resource attributes (#1621)
Browse files Browse the repository at this point in the history
  • Loading branch information
psx95 authored Jan 8, 2025
1 parent 6069c1d commit 239e6a8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
42 changes: 19 additions & 23 deletions gcp-resources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,37 @@ 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 | | | |
| faas.name | | | auto | auto | auto |
| 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.
Expand Down
1 change: 0 additions & 1 deletion gcp-resources/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ dependencies {
testImplementation("com.google.guava:guava")

testImplementation("org.junit.jupiter:junit-jupiter-api")
testImplementation("io.opentelemetry:opentelemetry-sdk-testing")
}

0 comments on commit 239e6a8

Please sign in to comment.