From aa3e781a95def24e52c0dceaf7c33ec5b6193a7e Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Wed, 27 Nov 2024 12:36:33 +0100 Subject: [PATCH 01/13] Remove the mapping of `app.kubernetes.io/instance` to `service.instance.id`, because multiple containers should never share the same `service.instance.id` --- CHANGELOG.md | 7 ++++-- README.md | 6 ++--- docs/api.md | 5 ++-- pkg/constants/env.go | 7 +++--- pkg/instrumentation/sdk.go | 9 +++++-- pkg/instrumentation/sdk_test.go | 44 ++++++++++++++------------------- 6 files changed, 39 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c3ee367ff..545f8cff97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ +### 🧰 Bug fixes 🧰 + +- Remove the mapping of `app.kubernetes.io/instance` to `service.instance.id`, because multiple containers + should never share the same `service.instance.id` (#3495) + ## 0.113.0 ### 💡 Enhancements 💡 @@ -220,8 +225,6 @@ - `app.kubernetes.io/name` becomes `service.name` - `app.kubernetes.io/version` becomes `service.version` - `app.kubernetes.io/part-of` becomes `service.namespace` - - `app.kubernetes.io/instance` becomes `service.instance.id` - ### 🧰 Bug fixes 🧰 diff --git a/README.md b/README.md index 6244ab90cf..747bf69aa0 100644 --- a/README.md +++ b/README.md @@ -725,7 +725,8 @@ EOF ### Configure resource attributes with annotations -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. +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. ```yaml apiVersion: v1 @@ -733,6 +734,7 @@ kind: Pod metadata: name: example-pod annotations: + # this is just an example, you can create any resource attributes you need resource.opentelemetry.io/service.name: "my-service" resource.opentelemetry.io/service.version: "1.0.0" resource.opentelemetry.io/environment: "production" @@ -750,7 +752,6 @@ The following labels are supported: - `app.kubernetes.io/name` becomes `service.name` - `app.kubernetes.io/version` becomes `service.version` - `app.kubernetes.io/part-of` becomes `service.namespace` -- `app.kubernetes.io/instance` becomes `service.instance.id` ```yaml apiVersion: v1 @@ -761,7 +762,6 @@ metadata: app.kubernetes.io/name: "my-service" app.kubernetes.io/version: "1.0.0" app.kubernetes.io/part-of: "shop" - app.kubernetes.io/instance: "my-service-123" spec: containers: - name: main-container diff --git a/docs/api.md b/docs/api.md index 9601cca2fd..362e7339a7 100644 --- a/docs/api.md +++ b/docs/api.md @@ -1389,8 +1389,7 @@ Defaults defines default values for the instrumentation. UseLabelsForResourceAttributes defines whether to use common labels for resource attributes: - `app.kubernetes.io/name` becomes `service.name` - `app.kubernetes.io/version` becomes `service.version` - - `app.kubernetes.io/part-of` becomes `service.namespace` - - `app.kubernetes.io/instance` becomes `service.instance.id`
+ - `app.kubernetes.io/part-of` becomes `service.namespace`
false @@ -54000,4 +53999,4 @@ Deployment, Daemonset, StatefulSet.
false - \ No newline at end of file + diff --git a/pkg/constants/env.go b/pkg/constants/env.go index 27963fb900..eebf26e2f4 100644 --- a/pkg/constants/env.go +++ b/pkg/constants/env.go @@ -35,10 +35,9 @@ const ( AnnotationDefaultAutoInstrumentationApacheHttpd = InstrumentationPrefix + "default-auto-instrumentation-apache-httpd-image" AnnotationDefaultAutoInstrumentationNginx = InstrumentationPrefix + "default-auto-instrumentation-nginx-image" - LabelAppName = "app.kubernetes.io/name" - LabelAppInstance = "app.kubernetes.io/instance" - LabelAppVersion = "app.kubernetes.io/version" - LabelAppPartOf = "app.kubernetes.io/part-of" + LabelAppName = "app.kubernetes.io/name" + LabelAppVersion = "app.kubernetes.io/version" + LabelAppPartOf = "app.kubernetes.io/part-of" LabelTargetAllocator = "opentelemetry.io/target-allocator" ResourceAttributeAnnotationPrefix = "resource.opentelemetry.io/" diff --git a/pkg/instrumentation/sdk.go b/pkg/instrumentation/sdk.go index 1ec6272836..e89b554eb1 100644 --- a/pkg/instrumentation/sdk.go +++ b/pkg/instrumentation/sdk.go @@ -469,11 +469,16 @@ func chooseServiceVersion(pod corev1.Pod, useLabelsForResourceAttributes bool, i // chooseServiceInstanceId returns the service.instance.id to be used in the instrumentation. // The precedence is as follows: -// 1. annotation with key "service.instance.id" or "app.kubernetes.io/instance" +// 1. annotation with key "service.instance.id" // 2. namespace name + pod name + container name // (as defined by https://opentelemetry.io/docs/specs/semconv/resource/#service-experimental) func createServiceInstanceId(pod corev1.Pod, useLabelsForResourceAttributes bool, namespaceName, podName, containerName string) string { - serviceInstanceId := chooseLabelOrAnnotation(pod, useLabelsForResourceAttributes, semconv.ServiceInstanceIDKey, constants.LabelAppInstance) + // Do not use labels for service instance id, + // because multiple containers in the same pod would get the same service instance id, + // which violates the uniqueness requirement of service instance id - + // see https://opentelemetry.io/docs/specs/semconv/resource/#service-experimental. + // We still allow the user to set the service instance id via annotation, because this is explicitly set by the user. + serviceInstanceId := chooseLabelOrAnnotation(pod, false, semconv.ServiceInstanceIDKey, "") if serviceInstanceId != "" { return serviceInstanceId } diff --git a/pkg/instrumentation/sdk_test.go b/pkg/instrumentation/sdk_test.go index 04f9826807..09e7ee427b 100644 --- a/pkg/instrumentation/sdk_test.go +++ b/pkg/instrumentation/sdk_test.go @@ -156,10 +156,9 @@ func TestSDKInjection(t *testing.T) { }, }, Labels: map[string]string{ - "app.kubernetes.io/name": "app-name", - "app.kubernetes.io/instance": "app-id", - "app.kubernetes.io/version": "v1", - "app.kubernetes.io/part-of": "shop", + "app.kubernetes.io/name": "app-name", + "app.kubernetes.io/version": "v1", + "app.kubernetes.io/part-of": "shop", }, Annotations: map[string]string{ "resource.opentelemetry.io/foo": "bar", @@ -180,10 +179,9 @@ func TestSDKInjection(t *testing.T) { Name: "app", UID: "pod-uid", Labels: map[string]string{ - "app.kubernetes.io/name": "app-name", - "app.kubernetes.io/instance": "app-id", - "app.kubernetes.io/version": "v1", - "app.kubernetes.io/part-of": "shop", + "app.kubernetes.io/name": "app-name", + "app.kubernetes.io/version": "v1", + "app.kubernetes.io/part-of": "shop", }, Annotations: map[string]string{ "resource.opentelemetry.io/foo": "bar", @@ -396,10 +394,9 @@ func TestSDKInjection(t *testing.T) { }, }, Labels: map[string]string{ - "app.kubernetes.io/name": "app-name", - "app.kubernetes.io/instance": "app-id", - "app.kubernetes.io/version": "v1", - "app.kubernetes.io/part-of": "shop", + "app.kubernetes.io/name": "app-name", + "app.kubernetes.io/version": "v1", + "app.kubernetes.io/part-of": "shop", }, Annotations: map[string]string{ "resource.opentelemetry.io/foo": "bar", @@ -420,10 +417,9 @@ func TestSDKInjection(t *testing.T) { Name: "app", UID: "pod-uid", Labels: map[string]string{ - "app.kubernetes.io/name": "app-name", - "app.kubernetes.io/instance": "app-id", - "app.kubernetes.io/version": "v1", - "app.kubernetes.io/part-of": "shop", + "app.kubernetes.io/name": "app-name", + "app.kubernetes.io/version": "v1", + "app.kubernetes.io/part-of": "shop", }, Annotations: map[string]string{ "resource.opentelemetry.io/foo": "bar", @@ -481,7 +477,7 @@ func TestSDKInjection(t *testing.T) { }, { Name: "OTEL_RESOURCE_ATTRIBUTES", - 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", + 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", }, }, }, @@ -516,10 +512,9 @@ func TestSDKInjection(t *testing.T) { Namespace: "project1", Name: "app", Labels: map[string]string{ - "app.kubernetes.io/name": "not-used", - "app.kubernetes.io/instance": "not-used", - "app.kubernetes.io/version": "not-used", - "app.kubernetes.io/part-of": "not-used", + "app.kubernetes.io/name": "not-used", + "app.kubernetes.io/version": "not-used", + "app.kubernetes.io/part-of": "not-used", }, }, Spec: corev1.PodSpec{ @@ -557,10 +552,9 @@ func TestSDKInjection(t *testing.T) { Namespace: "project1", Name: "app", Labels: map[string]string{ - "app.kubernetes.io/name": "not-used", - "app.kubernetes.io/instance": "not-used", - "app.kubernetes.io/version": "not-used", - "app.kubernetes.io/part-of": "not-used", + "app.kubernetes.io/name": "not-used", + "app.kubernetes.io/version": "not-used", + "app.kubernetes.io/part-of": "not-used", }, }, Spec: corev1.PodSpec{ From cd5c44e77bc5040b959e307739fc616c34fdc6ef Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Wed, 27 Nov 2024 12:50:01 +0100 Subject: [PATCH 02/13] Remove the mapping of `app.kubernetes.io/instance` to `service.instance.id`, because multiple containers should never share the same `service.instance.id` --- CHANGELOG.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 545f8cff97..1c3ee367ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,6 @@ -### 🧰 Bug fixes 🧰 - -- Remove the mapping of `app.kubernetes.io/instance` to `service.instance.id`, because multiple containers - should never share the same `service.instance.id` (#3495) - ## 0.113.0 ### 💡 Enhancements 💡 @@ -225,6 +220,8 @@ - `app.kubernetes.io/name` becomes `service.name` - `app.kubernetes.io/version` becomes `service.version` - `app.kubernetes.io/part-of` becomes `service.namespace` + - `app.kubernetes.io/instance` becomes `service.instance.id` + ### 🧰 Bug fixes 🧰 From bca76c6119de9ec641317d742d3093e0fb0d6caf Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Wed, 27 Nov 2024 12:50:14 +0100 Subject: [PATCH 03/13] Remove the mapping of `app.kubernetes.io/instance` to `service.instance.id`, because multiple containers should never share the same `service.instance.id` --- .chloggen/service-instanc-id-mapping.yaml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 .chloggen/service-instanc-id-mapping.yaml diff --git a/.chloggen/service-instanc-id-mapping.yaml b/.chloggen/service-instanc-id-mapping.yaml new file mode 100755 index 0000000000..1886cdda29 --- /dev/null +++ b/.chloggen/service-instanc-id-mapping.yaml @@ -0,0 +1,17 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action) +component: auto-instrumentation + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Remove the mapping of `app.kubernetes.io/instance` to `service.instance.id`, because multiple containers + should never share the same `service.instance.id` + +# One or more tracking issues related to the change +issues: [3495] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: From 84200196ff4e0fc9d8999b31891263f093fe7052 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Wed, 27 Nov 2024 12:53:07 +0100 Subject: [PATCH 04/13] Remove the mapping of `app.kubernetes.io/instance` to `service.instance.id`, because multiple containers should never share the same `service.instance.id` --- pkg/instrumentation/sdk.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/instrumentation/sdk.go b/pkg/instrumentation/sdk.go index e89b554eb1..8254daf513 100644 --- a/pkg/instrumentation/sdk.go +++ b/pkg/instrumentation/sdk.go @@ -472,7 +472,7 @@ func chooseServiceVersion(pod corev1.Pod, useLabelsForResourceAttributes bool, i // 1. annotation with key "service.instance.id" // 2. namespace name + pod name + container name // (as defined by https://opentelemetry.io/docs/specs/semconv/resource/#service-experimental) -func createServiceInstanceId(pod corev1.Pod, useLabelsForResourceAttributes bool, namespaceName, podName, containerName string) string { +func createServiceInstanceId(pod corev1.Pod, namespaceName, podName, containerName string) string { // Do not use labels for service instance id, // because multiple containers in the same pod would get the same service instance id, // which violates the uniqueness requirement of service instance id - @@ -527,7 +527,7 @@ func (i *sdkInjector) createResourceMap(ctx context.Context, otelinst v1alpha1.I k8sResources[semconv.K8SPodNameKey] = pod.Name k8sResources[semconv.K8SPodUIDKey] = string(pod.UID) k8sResources[semconv.K8SNodeNameKey] = pod.Spec.NodeName - k8sResources[semconv.ServiceInstanceIDKey] = createServiceInstanceId(pod, useLabelsForResourceAttributes, ns.Name, fmt.Sprintf("$(%s)", constants.EnvPodName), pod.Spec.Containers[index].Name) + k8sResources[semconv.ServiceInstanceIDKey] = createServiceInstanceId(pod, ns.Name, fmt.Sprintf("$(%s)", constants.EnvPodName), pod.Spec.Containers[index].Name) i.addParentResourceLabels(ctx, otelinst.Spec.Resource.AddK8sUIDAttributes, ns, pod.ObjectMeta, k8sResources) for k, v := range k8sResources { From ef24a5f9d51e5f7f216a74146062d5487c3c1869 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Wed, 27 Nov 2024 13:03:52 +0100 Subject: [PATCH 05/13] Remove the mapping of `app.kubernetes.io/instance` to `service.instance.id`, because multiple containers should never share the same `service.instance.id` --- apis/v1alpha1/instrumentation_types.go | 1 - docs/api.md | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/apis/v1alpha1/instrumentation_types.go b/apis/v1alpha1/instrumentation_types.go index e290f4033b..4f2e6f986e 100644 --- a/apis/v1alpha1/instrumentation_types.go +++ b/apis/v1alpha1/instrumentation_types.go @@ -152,7 +152,6 @@ type Defaults struct { // - `app.kubernetes.io/name` becomes `service.name` // - `app.kubernetes.io/version` becomes `service.version` // - `app.kubernetes.io/part-of` becomes `service.namespace` - // - `app.kubernetes.io/instance` becomes `service.instance.id` UseLabelsForResourceAttributes bool `json:"useLabelsForResourceAttributes,omitempty"` } diff --git a/docs/api.md b/docs/api.md index 362e7339a7..a7d167a474 100644 --- a/docs/api.md +++ b/docs/api.md @@ -53999,4 +53999,4 @@ Deployment, Daemonset, StatefulSet.
false - + \ No newline at end of file From 1c64af93607269b6c7d909f18af86e027c90e665 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Wed, 27 Nov 2024 17:40:37 +0100 Subject: [PATCH 06/13] Remove the mapping of `app.kubernetes.io/instance` to `service.instance.id`, because multiple containers should never share the same `service.instance.id` --- .chloggen/service-instanc-id-mapping.yaml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/.chloggen/service-instanc-id-mapping.yaml b/.chloggen/service-instanc-id-mapping.yaml index 1886cdda29..b50698a392 100755 --- a/.chloggen/service-instanc-id-mapping.yaml +++ b/.chloggen/service-instanc-id-mapping.yaml @@ -5,8 +5,7 @@ change_type: bug_fix component: auto-instrumentation # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). -note: Remove the mapping of `app.kubernetes.io/instance` to `service.instance.id`, because multiple containers - should never share the same `service.instance.id` +note: Remove the mapping of `app.kubernetes.io/instance` to `service.instance.id` # One or more tracking issues related to the change issues: [3495] @@ -14,4 +13,15 @@ issues: [3495] # (Optional) One or more lines of additional information to render under the primary note. # These lines will be padded with 2 spaces and then inserted directly into the document. # Use pipe (|) for multiline entries. -subtext: +subtext: | + Technically, this is a breaking change, but we regard it as a bug fix because the previous behavior was incorrect. + + In you did have multiple containers and use `app.kubernetes.io/instance` to set the `service.instance.id`, + you will now see multiple instances in the UI - which is the correct behavior. + + You can still use the attribute `resource.opentelemetry.io/service.instance.id` to set the `service.instance.id`, + which will be shared across all containers in the pod - but this is not recommended. + + Refer to the [semantic conventions](https://opentelemetry.io/docs/specs/semconv/resource/#service-experimental) + for more information. + From 68a1b9f975fa9b1f4caea29165f656815877af0a Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 28 Nov 2024 09:21:21 +0100 Subject: [PATCH 07/13] Update .chloggen/service-instanc-id-mapping.yaml Co-authored-by: Jacob Aronoff --- .chloggen/service-instanc-id-mapping.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chloggen/service-instanc-id-mapping.yaml b/.chloggen/service-instanc-id-mapping.yaml index b50698a392..02a12a644e 100755 --- a/.chloggen/service-instanc-id-mapping.yaml +++ b/.chloggen/service-instanc-id-mapping.yaml @@ -16,7 +16,7 @@ issues: [3495] subtext: | Technically, this is a breaking change, but we regard it as a bug fix because the previous behavior was incorrect. - In you did have multiple containers and use `app.kubernetes.io/instance` to set the `service.instance.id`, + if you did have multiple container instrumentation and use `app.kubernetes.io/instance` to set the `service.instance.id`, you will now see multiple instances in the UI - which is the correct behavior. You can still use the attribute `resource.opentelemetry.io/service.instance.id` to set the `service.instance.id`, From d2482624d5a2262a692052e84385302566cb0f7a Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 28 Nov 2024 09:21:36 +0100 Subject: [PATCH 08/13] Update .chloggen/service-instanc-id-mapping.yaml Co-authored-by: Jacob Aronoff --- .chloggen/service-instanc-id-mapping.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chloggen/service-instanc-id-mapping.yaml b/.chloggen/service-instanc-id-mapping.yaml index 02a12a644e..46e33b03cb 100755 --- a/.chloggen/service-instanc-id-mapping.yaml +++ b/.chloggen/service-instanc-id-mapping.yaml @@ -20,7 +20,7 @@ subtext: | you will now see multiple instances in the UI - which is the correct behavior. You can still use the attribute `resource.opentelemetry.io/service.instance.id` to set the `service.instance.id`, - which will be shared across all containers in the pod - but this is not recommended. + which will be shared across all containers in the pod - but this is not recommended for multiple container instrumentation instances. Refer to the [semantic conventions](https://opentelemetry.io/docs/specs/semconv/resource/#service-experimental) for more information. From 872f482b69d0f38e9f1a5500d4867056b6d5f6d4 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 28 Nov 2024 13:23:21 +0100 Subject: [PATCH 09/13] add docs --- README.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/README.md b/README.md index 747bf69aa0..d701b2ead8 100644 --- a/README.md +++ b/README.md @@ -794,6 +794,35 @@ The priority for setting resource attributes is as follows (first found wins): This priority is applied for each resource attribute separately, so it is possible to set some attributes via annotations and others via labels. +### How resource attributes are calculated from the pod's metadata + +The following resource attributes are calculated from the pod's metadata. + +#### How service.name is calculated + +Choose the first value found: + +- `k8s.depleyment.name` +- `k8s.replicaset.name` +- `k8s.statefulset.name` +- `k8s.daemonset.name` +- `k8s.cronjob.name` +- `k8s.job.name` +- `k8s.pod.name` +- `k8s.container.name` + +#### How service.version is calculated + +Take the tag from the docker image name of the container. +If the tag contains a `/`, the tag is ignored (this can happen if the image name contains a port number). + +#### How service.instance.id is calculated + +Create a unique identifier for the application running in the container. +The identifier is created by concatenating the following values: + +`..` + ## Contributing and Developing Please see [CONTRIBUTING.md](CONTRIBUTING.md). From 96c8a067df293e84b55fb19fcf7428daa2f1e1ec Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Tue, 10 Dec 2024 15:06:37 +0100 Subject: [PATCH 10/13] Update README.md Co-authored-by: Cyrille Le Clerc --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d701b2ead8..cc06522591 100644 --- a/README.md +++ b/README.md @@ -798,7 +798,7 @@ annotations and others via labels. The following resource attributes are calculated from the pod's metadata. -#### How service.name is calculated +#### How `service.name` is calculated Choose the first value found: From becbfebcdc66181b5f6344781277ef8c9c740e33 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Tue, 10 Dec 2024 15:08:33 +0100 Subject: [PATCH 11/13] Apply suggestions from code review Co-authored-by: Cyrille Le Clerc --- README.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index cc06522591..c40ed5e24b 100644 --- a/README.md +++ b/README.md @@ -802,6 +802,8 @@ The following resource attributes are calculated from the pod's metadata. Choose the first value found: +- `pod.annotation[resource.opentelemetry.io/service.name]` +- `if (config[useLabelsForResourceAttributes]) pod.label[app.kubernetes.io/name]` - `k8s.depleyment.name` - `k8s.replicaset.name` - `k8s.statefulset.name` @@ -813,15 +815,16 @@ Choose the first value found: #### How service.version is calculated -Take the tag from the docker image name of the container. -If the tag contains a `/`, the tag is ignored (this can happen if the image name contains a port number). +- `pod.annotation[resource.opentelemetry.io/service.version]` +- `if (cfg[useLabelsForResourceAttributes]) pod.label[app.kubernetes.io/version]` +- `if (contains(container.image.tags[0], '/') == false) contains(container.image.tags[0] -#### How service.instance.id is calculated +#### How `service.instance.id` is calculated -Create a unique identifier for the application running in the container. -The identifier is created by concatenating the following values: -`..` +- `pod.annotation[resource.opentelemetry.io/service.instance.id]` +- `if (config[useLabelsForResourceAttributes]) pod.label[app.kubernetes.io/instance]` +- `concat([k8s.namespace.name, k8s.pod.name, k8s.container.name], '.')` ## Contributing and Developing From 0c4863ea7896123099039f9e5c64c8909234b067 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Tue, 10 Dec 2024 15:12:24 +0100 Subject: [PATCH 12/13] add docs --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c40ed5e24b..03db116c0f 100644 --- a/README.md +++ b/README.md @@ -813,7 +813,7 @@ Choose the first value found: - `k8s.pod.name` - `k8s.container.name` -#### How service.version is calculated +#### How `service.version` is calculated - `pod.annotation[resource.opentelemetry.io/service.version]` - `if (cfg[useLabelsForResourceAttributes]) pod.label[app.kubernetes.io/version]` From db099557018787ff9388710d4be76fe19d61ddc4 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Tue, 10 Dec 2024 15:36:58 +0100 Subject: [PATCH 13/13] add docs --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 03db116c0f..e027144d4b 100644 --- a/README.md +++ b/README.md @@ -817,7 +817,7 @@ Choose the first value found: - `pod.annotation[resource.opentelemetry.io/service.version]` - `if (cfg[useLabelsForResourceAttributes]) pod.label[app.kubernetes.io/version]` -- `if (contains(container.image.tags[0], '/') == false) contains(container.image.tags[0] +- `if (contains(container docker image tag, '/') == false) container docker image tag` #### How `service.instance.id` is calculated