Skip to content

Commit 248bec3

Browse files
committed
update recommended attributes to match semconv
1 parent 888eeda commit 248bec3

File tree

5 files changed

+41
-12
lines changed

5 files changed

+41
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: breaking
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
5+
component: auto-instrumentation
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: Update recommended resource attributes to match the [semantic conventions](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/non-normative/k8s-attributes.md)
9+
10+
# One or more tracking issues related to the change
11+
issues: []
12+
13+
# (Optional) One or more lines of additional information to render under the primary note.
14+
# These lines will be padded with 2 spaces and then inserted directly into the document.
15+
# Use pipe (|) for multiline entries.
16+
subtext: |
17+
This change updates the recommended resource attributes to match the [semantic conventions](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/non-normative/k8s-attributes.md).
18+
The following attributes have been updated:
19+
- `service.version` now uses the docker image digest in addition to the tag
20+
- the well-known label `app.kubernetes.io/part-of` has been removed
21+
- the well-known label `app.kubernetes.io/instance` has been added (translates to `service.name`)
22+

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -752,12 +752,12 @@ spec:
752752

753753
### Configure resource attributes with labels
754754

755-
You can also use common labels to set resource attributes.
755+
You can also use common labels to set resource attributes (first entry wins).
756756

757757
The following labels are supported:
758+
- `app.kubernetes.io/instance` becomes `service.name`
758759
- `app.kubernetes.io/name` becomes `service.name`
759760
- `app.kubernetes.io/version` becomes `service.version`
760-
- `app.kubernetes.io/part-of` becomes `service.namespace`
761761

762762
```yaml
763763
apiVersion: v1

apis/v1alpha1/instrumentation_types.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,10 @@ type Sampler struct {
138138
// Defaults defines default values for the instrumentation.
139139
type Defaults struct {
140140
// UseLabelsForResourceAttributes defines whether to use common labels for resource attributes:
141+
// Note: first entry wins:
142+
// - `app.kubernetes.io/instance` becomes `service.name`
141143
// - `app.kubernetes.io/name` becomes `service.name`
142144
// - `app.kubernetes.io/version` becomes `service.version`
143-
// - `app.kubernetes.io/part-of` becomes `service.namespace`
144145
UseLabelsForResourceAttributes bool `json:"useLabelsForResourceAttributes,omitempty"`
145146
}
146147

pkg/constants/env.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ const (
2424
AnnotationDefaultAutoInstrumentationApacheHttpd = InstrumentationPrefix + "default-auto-instrumentation-apache-httpd-image"
2525
AnnotationDefaultAutoInstrumentationNginx = InstrumentationPrefix + "default-auto-instrumentation-nginx-image"
2626

27-
LabelAppName = "app.kubernetes.io/name"
28-
LabelAppVersion = "app.kubernetes.io/version"
29-
LabelAppPartOf = "app.kubernetes.io/part-of"
30-
3127
LabelTargetAllocator = "opentelemetry.io/target-allocator"
3228
ResourceAttributeAnnotationPrefix = "resource.opentelemetry.io/"
3329

@@ -51,3 +47,11 @@ const (
5147
TACollectorTLSKeyFileName = "tls.key"
5248
TACollectorTLSCertFileName = "tls.crt"
5349
)
50+
51+
var (
52+
LabelAppName = []string{
53+
"app.kubernetes.io/instance",
54+
"app.kubernetes.io/name",
55+
}
56+
LabelAppVersion = []string{"app.kubernetes.io/version"}
57+
)

pkg/instrumentation/sdk.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -431,13 +431,15 @@ func chooseServiceName(pod corev1.Pod, useLabelsForResourceAttributes bool, reso
431431
// The precedence is as follows:
432432
// 1. annotation with key resource.opentelemetry.io/<resource>.
433433
// 2. label with key labelKey.
434-
func chooseLabelOrAnnotation(pod corev1.Pod, useLabelsForResourceAttributes bool, resource attribute.Key, labelKey string) string {
434+
func chooseLabelOrAnnotation(pod corev1.Pod, useLabelsForResourceAttributes bool, resource attribute.Key, labelKeys []string) string {
435435
if v := pod.GetAnnotations()[(constants.ResourceAttributeAnnotationPrefix + string(resource))]; v != "" {
436436
return v
437437
}
438438
if useLabelsForResourceAttributes {
439-
if v := pod.GetLabels()[labelKey]; v != "" {
440-
return v
439+
for _, labelKey := range labelKeys {
440+
if v := pod.GetLabels()[labelKey]; v != "" {
441+
return v
442+
}
441443
}
442444
}
443445
return ""
@@ -472,7 +474,7 @@ func createServiceInstanceId(pod corev1.Pod, namespaceName, podName, containerNa
472474
// which violates the uniqueness requirement of service instance id -
473475
// see https://opentelemetry.io/docs/specs/semconv/resource/#service-experimental.
474476
// We still allow the user to set the service instance id via annotation, because this is explicitly set by the user.
475-
serviceInstanceId := chooseLabelOrAnnotation(pod, false, semconv.ServiceInstanceIDKey, "")
477+
serviceInstanceId := chooseLabelOrAnnotation(pod, false, semconv.ServiceInstanceIDKey, nil)
476478
if serviceInstanceId != "" {
477479
return serviceInstanceId
478480
}
@@ -539,7 +541,7 @@ func (i *sdkInjector) createResourceMap(ctx context.Context, otelinst v1alpha1.I
539541
}
540542
}
541543
}
542-
partOf := chooseLabelOrAnnotation(pod, useLabelsForResourceAttributes, semconv.ServiceNamespaceKey, constants.LabelAppPartOf)
544+
partOf := chooseLabelOrAnnotation(pod, useLabelsForResourceAttributes, semconv.ServiceNamespaceKey, nil)
543545
if partOf != "" && !existingRes[string(semconv.ServiceNamespaceKey)] {
544546
res[string(semconv.ServiceNamespaceKey)] = partOf
545547
}

0 commit comments

Comments
 (0)