Skip to content

Commit aa3e781

Browse files
committed
Remove the mapping of app.kubernetes.io/instance to service.instance.id, because multiple containers
should never share the same `service.instance.id`
1 parent 3d254a4 commit aa3e781

File tree

6 files changed

+39
-39
lines changed

6 files changed

+39
-39
lines changed

CHANGELOG.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
<!-- next version -->
44

5+
### 🧰 Bug fixes 🧰
6+
7+
- Remove the mapping of `app.kubernetes.io/instance` to `service.instance.id`, because multiple containers
8+
should never share the same `service.instance.id` (#3495)
9+
510
## 0.113.0
611

712
### 💡 Enhancements 💡
@@ -220,8 +225,6 @@
220225
- `app.kubernetes.io/name` becomes `service.name`
221226
- `app.kubernetes.io/version` becomes `service.version`
222227
- `app.kubernetes.io/part-of` becomes `service.namespace`
223-
- `app.kubernetes.io/instance` becomes `service.instance.id`
224-
225228

226229
### 🧰 Bug fixes 🧰
227230

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -725,14 +725,16 @@ EOF
725725

726726
### Configure resource attributes with annotations
727727

728-
This example shows a pod configuration with OpenTelemetry annotations using the `resource.opentelemetry.io/` prefix. These annotations can be used to add resource attributes to data produced by OpenTelemetry instrumentation.
728+
This example shows a pod configuration with OpenTelemetry annotations using the `resource.opentelemetry.io/` prefix.
729+
These annotations can be used to add resource attributes to data produced by OpenTelemetry instrumentation.
729730

730731
```yaml
731732
apiVersion: v1
732733
kind: Pod
733734
metadata:
734735
name: example-pod
735736
annotations:
737+
# this is just an example, you can create any resource attributes you need
736738
resource.opentelemetry.io/service.name: "my-service"
737739
resource.opentelemetry.io/service.version: "1.0.0"
738740
resource.opentelemetry.io/environment: "production"
@@ -750,7 +752,6 @@ The following labels are supported:
750752
- `app.kubernetes.io/name` becomes `service.name`
751753
- `app.kubernetes.io/version` becomes `service.version`
752754
- `app.kubernetes.io/part-of` becomes `service.namespace`
753-
- `app.kubernetes.io/instance` becomes `service.instance.id`
754755

755756
```yaml
756757
apiVersion: v1
@@ -761,7 +762,6 @@ metadata:
761762
app.kubernetes.io/name: "my-service"
762763
app.kubernetes.io/version: "1.0.0"
763764
app.kubernetes.io/part-of: "shop"
764-
app.kubernetes.io/instance: "my-service-123"
765765
spec:
766766
containers:
767767
- name: main-container

docs/api.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -1389,8 +1389,7 @@ Defaults defines default values for the instrumentation.
13891389
UseLabelsForResourceAttributes defines whether to use common labels for resource attributes:
13901390
- `app.kubernetes.io/name` becomes `service.name`
13911391
- `app.kubernetes.io/version` becomes `service.version`
1392-
- `app.kubernetes.io/part-of` becomes `service.namespace`
1393-
- `app.kubernetes.io/instance` becomes `service.instance.id`<br/>
1392+
- `app.kubernetes.io/part-of` becomes `service.namespace`<br/>
13941393
</td>
13951394
<td>false</td>
13961395
</tr></tbody>
@@ -54000,4 +53999,4 @@ Deployment, Daemonset, StatefulSet.<br/>
5400053999
</td>
5400154000
<td>false</td>
5400254001
</tr></tbody>
54003-
</table>
54002+
</table>

pkg/constants/env.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ const (
3535
AnnotationDefaultAutoInstrumentationApacheHttpd = InstrumentationPrefix + "default-auto-instrumentation-apache-httpd-image"
3636
AnnotationDefaultAutoInstrumentationNginx = InstrumentationPrefix + "default-auto-instrumentation-nginx-image"
3737

38-
LabelAppName = "app.kubernetes.io/name"
39-
LabelAppInstance = "app.kubernetes.io/instance"
40-
LabelAppVersion = "app.kubernetes.io/version"
41-
LabelAppPartOf = "app.kubernetes.io/part-of"
38+
LabelAppName = "app.kubernetes.io/name"
39+
LabelAppVersion = "app.kubernetes.io/version"
40+
LabelAppPartOf = "app.kubernetes.io/part-of"
4241

4342
LabelTargetAllocator = "opentelemetry.io/target-allocator"
4443
ResourceAttributeAnnotationPrefix = "resource.opentelemetry.io/"

pkg/instrumentation/sdk.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -469,11 +469,16 @@ func chooseServiceVersion(pod corev1.Pod, useLabelsForResourceAttributes bool, i
469469

470470
// chooseServiceInstanceId returns the service.instance.id to be used in the instrumentation.
471471
// The precedence is as follows:
472-
// 1. annotation with key "service.instance.id" or "app.kubernetes.io/instance"
472+
// 1. annotation with key "service.instance.id"
473473
// 2. namespace name + pod name + container name
474474
// (as defined by https://opentelemetry.io/docs/specs/semconv/resource/#service-experimental)
475475
func createServiceInstanceId(pod corev1.Pod, useLabelsForResourceAttributes bool, namespaceName, podName, containerName string) string {
476-
serviceInstanceId := chooseLabelOrAnnotation(pod, useLabelsForResourceAttributes, semconv.ServiceInstanceIDKey, constants.LabelAppInstance)
476+
// Do not use labels for service instance id,
477+
// because multiple containers in the same pod would get the same service instance id,
478+
// which violates the uniqueness requirement of service instance id -
479+
// see https://opentelemetry.io/docs/specs/semconv/resource/#service-experimental.
480+
// We still allow the user to set the service instance id via annotation, because this is explicitly set by the user.
481+
serviceInstanceId := chooseLabelOrAnnotation(pod, false, semconv.ServiceInstanceIDKey, "")
477482
if serviceInstanceId != "" {
478483
return serviceInstanceId
479484
}

pkg/instrumentation/sdk_test.go

+19-25
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,9 @@ func TestSDKInjection(t *testing.T) {
156156
},
157157
},
158158
Labels: map[string]string{
159-
"app.kubernetes.io/name": "app-name",
160-
"app.kubernetes.io/instance": "app-id",
161-
"app.kubernetes.io/version": "v1",
162-
"app.kubernetes.io/part-of": "shop",
159+
"app.kubernetes.io/name": "app-name",
160+
"app.kubernetes.io/version": "v1",
161+
"app.kubernetes.io/part-of": "shop",
163162
},
164163
Annotations: map[string]string{
165164
"resource.opentelemetry.io/foo": "bar",
@@ -180,10 +179,9 @@ func TestSDKInjection(t *testing.T) {
180179
Name: "app",
181180
UID: "pod-uid",
182181
Labels: map[string]string{
183-
"app.kubernetes.io/name": "app-name",
184-
"app.kubernetes.io/instance": "app-id",
185-
"app.kubernetes.io/version": "v1",
186-
"app.kubernetes.io/part-of": "shop",
182+
"app.kubernetes.io/name": "app-name",
183+
"app.kubernetes.io/version": "v1",
184+
"app.kubernetes.io/part-of": "shop",
187185
},
188186
Annotations: map[string]string{
189187
"resource.opentelemetry.io/foo": "bar",
@@ -396,10 +394,9 @@ func TestSDKInjection(t *testing.T) {
396394
},
397395
},
398396
Labels: map[string]string{
399-
"app.kubernetes.io/name": "app-name",
400-
"app.kubernetes.io/instance": "app-id",
401-
"app.kubernetes.io/version": "v1",
402-
"app.kubernetes.io/part-of": "shop",
397+
"app.kubernetes.io/name": "app-name",
398+
"app.kubernetes.io/version": "v1",
399+
"app.kubernetes.io/part-of": "shop",
403400
},
404401
Annotations: map[string]string{
405402
"resource.opentelemetry.io/foo": "bar",
@@ -420,10 +417,9 @@ func TestSDKInjection(t *testing.T) {
420417
Name: "app",
421418
UID: "pod-uid",
422419
Labels: map[string]string{
423-
"app.kubernetes.io/name": "app-name",
424-
"app.kubernetes.io/instance": "app-id",
425-
"app.kubernetes.io/version": "v1",
426-
"app.kubernetes.io/part-of": "shop",
420+
"app.kubernetes.io/name": "app-name",
421+
"app.kubernetes.io/version": "v1",
422+
"app.kubernetes.io/part-of": "shop",
427423
},
428424
Annotations: map[string]string{
429425
"resource.opentelemetry.io/foo": "bar",
@@ -481,7 +477,7 @@ func TestSDKInjection(t *testing.T) {
481477
},
482478
{
483479
Name: "OTEL_RESOURCE_ATTRIBUTES",
484-
Value: "foo=bar,k8s.container.name=application-name,k8s.deployment.name=my-deployment,k8s.deployment.uid=depuid,k8s.namespace.name=project1,k8s.node.name=$(OTEL_RESOURCE_ATTRIBUTES_NODE_NAME),k8s.pod.name=$(OTEL_RESOURCE_ATTRIBUTES_POD_NAME),k8s.pod.uid=pod-uid,k8s.replicaset.name=my-replicaset,k8s.replicaset.uid=rsuid,service.instance.id=app-id,service.namespace=shop,service.version=v1",
480+
Value: "foo=bar,k8s.container.name=application-name,k8s.deployment.name=my-deployment,k8s.deployment.uid=depuid,k8s.namespace.name=project1,k8s.node.name=$(OTEL_RESOURCE_ATTRIBUTES_NODE_NAME),k8s.pod.name=$(OTEL_RESOURCE_ATTRIBUTES_POD_NAME),k8s.pod.uid=pod-uid,k8s.replicaset.name=my-replicaset,k8s.replicaset.uid=rsuid,service.instance.id=project1.$(OTEL_RESOURCE_ATTRIBUTES_POD_NAME).application-name,service.namespace=shop,service.version=v1",
485481
},
486482
},
487483
},
@@ -516,10 +512,9 @@ func TestSDKInjection(t *testing.T) {
516512
Namespace: "project1",
517513
Name: "app",
518514
Labels: map[string]string{
519-
"app.kubernetes.io/name": "not-used",
520-
"app.kubernetes.io/instance": "not-used",
521-
"app.kubernetes.io/version": "not-used",
522-
"app.kubernetes.io/part-of": "not-used",
515+
"app.kubernetes.io/name": "not-used",
516+
"app.kubernetes.io/version": "not-used",
517+
"app.kubernetes.io/part-of": "not-used",
523518
},
524519
},
525520
Spec: corev1.PodSpec{
@@ -557,10 +552,9 @@ func TestSDKInjection(t *testing.T) {
557552
Namespace: "project1",
558553
Name: "app",
559554
Labels: map[string]string{
560-
"app.kubernetes.io/name": "not-used",
561-
"app.kubernetes.io/instance": "not-used",
562-
"app.kubernetes.io/version": "not-used",
563-
"app.kubernetes.io/part-of": "not-used",
555+
"app.kubernetes.io/name": "not-used",
556+
"app.kubernetes.io/version": "not-used",
557+
"app.kubernetes.io/part-of": "not-used",
564558
},
565559
},
566560
Spec: corev1.PodSpec{

0 commit comments

Comments
 (0)