Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 702a652

Browse files
committedMar 6, 2025·
Fix auto-instrumentation with multi annotation
Signed-off-by: Yuri Oliveira <yurimsa@gmail.com>
1 parent bda55b9 commit 702a652

10 files changed

+331
-1
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: 'bug_fix'
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: operator
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: It fix a case when the auto instrumentation fails with annotations set on both namespace and pod with different valid values
9+
10+
# One or more tracking issues related to the change
11+
issues: [3407]
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:

‎pkg/instrumentation/annotation.go

+5
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ func annotationValue(ns metav1.ObjectMeta, pod metav1.ObjectMeta, annotation str
6161
return podAnnValue
6262
}
6363

64+
// if both are 'true' or a defined instance-name, pod takes precedence
65+
if !strings.EqualFold(nsAnnValue, "false") && !strings.EqualFold(podAnnValue, "false") {
66+
return podAnnValue
67+
}
68+
6469
// by now, the pod annotation is 'true', and the namespace annotation is either true or an instance name
6570
// so, the namespace annotation can be used
6671
return nsAnnValue

‎pkg/instrumentation/annotation_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func TestEffectiveAnnotationValue(t *testing.T) {
3939

4040
{
4141
"ns-has-concrete-instance",
42-
"some-instance",
42+
"true",
4343
corev1.Pod{
4444
ObjectMeta: metav1.ObjectMeta{
4545
Annotations: map[string]string{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
apiVersion: v1
3+
kind: Namespace
4+
metadata:
5+
name: my-other-dotnet-ns
6+
annotations:
7+
instrumentation.opentelemetry.io/inject-sdk: "true"
8+
---
9+
apiVersion: opentelemetry.io/v1alpha1
10+
kind: OpenTelemetryCollector
11+
metadata:
12+
name: sidecar
13+
namespace: my-other-dotnet-ns
14+
spec:
15+
config: |
16+
receivers:
17+
otlp:
18+
protocols:
19+
grpc:
20+
http:
21+
processors:
22+
23+
exporters:
24+
debug:
25+
26+
service:
27+
pipelines:
28+
traces:
29+
receivers: [otlp]
30+
exporters: [debug]
31+
mode: sidecar
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
apiVersion: opentelemetry.io/v1alpha1
3+
kind: Instrumentation
4+
metadata:
5+
name: dotnet-multi
6+
namespace: my-other-dotnet-ns
7+
spec:
8+
env:
9+
- name: OTEL_TRACES_EXPORTER
10+
value: otlp
11+
- name: OTEL_EXPORTER_OTLP_ENDPOINT
12+
value: http://localhost:4317
13+
- name: OTEL_EXPORTER_OTLP_TIMEOUT
14+
value: "20"
15+
- name: OTEL_TRACES_SAMPLER
16+
value: parentbased_traceidratio
17+
- name: OTEL_TRACES_SAMPLER_ARG
18+
value: "0.85"
19+
- name: SPLUNK_TRACE_RESPONSE_HEADER_ENABLED
20+
value: "true"
21+
exporter:
22+
endpoint: http://localhost:4317
23+
propagators:
24+
- jaeger
25+
- b3multi
26+
sampler:
27+
type: parentbased_traceidratio
28+
argument: "0.25"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
namespace: my-other-dotnet-ns
5+
annotations:
6+
instrumentation.opentelemetry.io/inject-dotnet: "true"
7+
sidecar.opentelemetry.io/inject: "true"
8+
labels:
9+
app: my-dotnet
10+
spec:
11+
containers:
12+
- env:
13+
- name: OTEL_NODE_IP
14+
valueFrom:
15+
fieldRef:
16+
fieldPath: status.hostIP
17+
- name: OTEL_POD_IP
18+
valueFrom:
19+
fieldRef:
20+
fieldPath: status.podIP
21+
- name: ASPNETCORE_URLS
22+
value: http://+:8080
23+
- name: CORECLR_ENABLE_PROFILING
24+
value: "1"
25+
- name: CORECLR_PROFILER
26+
value: '{918728DD-259F-4A6A-AC2B-B85E1B658318}'
27+
- name: CORECLR_PROFILER_PATH
28+
value: /otel-auto-instrumentation-dotnet/linux-x64/OpenTelemetry.AutoInstrumentation.Native.so
29+
- name: DOTNET_STARTUP_HOOKS
30+
value: /otel-auto-instrumentation-dotnet/net/OpenTelemetry.AutoInstrumentation.StartupHook.dll
31+
- name: DOTNET_ADDITIONAL_DEPS
32+
value: /otel-auto-instrumentation-dotnet/AdditionalDeps
33+
- name: OTEL_DOTNET_AUTO_HOME
34+
value: /otel-auto-instrumentation-dotnet
35+
- name: DOTNET_SHARED_STORE
36+
value: /otel-auto-instrumentation-dotnet/store
37+
- name: OTEL_TRACES_EXPORTER
38+
value: otlp
39+
- name: OTEL_EXPORTER_OTLP_ENDPOINT
40+
value: http://localhost:4317
41+
- name: OTEL_EXPORTER_OTLP_TIMEOUT
42+
value: "20"
43+
- name: OTEL_TRACES_SAMPLER
44+
value: parentbased_traceidratio
45+
- name: OTEL_TRACES_SAMPLER_ARG
46+
value: "0.85"
47+
- name: SPLUNK_TRACE_RESPONSE_HEADER_ENABLED
48+
value: "true"
49+
- name: OTEL_SERVICE_NAME
50+
value: my-dotnet
51+
- name: OTEL_RESOURCE_ATTRIBUTES_POD_NAME
52+
valueFrom:
53+
fieldRef:
54+
apiVersion: v1
55+
fieldPath: metadata.name
56+
- name: OTEL_RESOURCE_ATTRIBUTES_NODE_NAME
57+
valueFrom:
58+
fieldRef:
59+
apiVersion: v1
60+
fieldPath: spec.nodeName
61+
- name: OTEL_PROPAGATORS
62+
value: jaeger,b3multi
63+
- name: OTEL_RESOURCE_ATTRIBUTES
64+
name: myapp
65+
volumeMounts:
66+
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
67+
readOnly: true
68+
- mountPath: /otel-auto-instrumentation-dotnet
69+
name: opentelemetry-auto-instrumentation-dotnet
70+
- args:
71+
- --config=env:OTEL_CONFIG
72+
name: otc-container
73+
initContainers:
74+
- name: opentelemetry-auto-instrumentation-dotnet
75+
status:
76+
containerStatuses:
77+
- name: myapp
78+
ready: true
79+
started: true
80+
- name: otc-container
81+
ready: true
82+
started: true
83+
initContainerStatuses:
84+
- name: opentelemetry-auto-instrumentation-dotnet
85+
ready: true
86+
phase: Running
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: my-dotnet
5+
namespace: my-other-dotnet-ns
6+
spec:
7+
selector:
8+
matchLabels:
9+
app: my-dotnet
10+
replicas: 1
11+
template:
12+
metadata:
13+
labels:
14+
app: my-dotnet
15+
annotations:
16+
sidecar.opentelemetry.io/inject: "true"
17+
instrumentation.opentelemetry.io/inject-dotnet: "true"
18+
spec:
19+
securityContext:
20+
runAsUser: 1000
21+
runAsGroup: 3000
22+
fsGroup: 3000
23+
containers:
24+
- name: myapp
25+
image: ghcr.io/open-telemetry/opentelemetry-operator/e2e-test-app-dotnet:main
26+
securityContext:
27+
allowPrivilegeEscalation: false
28+
capabilities:
29+
drop: ["ALL"]
30+
env:
31+
- name: ASPNETCORE_URLS
32+
value: "http://+:8080"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
namespace: my-other-dotnet-ns
5+
annotations:
6+
instrumentation.opentelemetry.io/inject-sdk: "true"
7+
sidecar.opentelemetry.io/inject: "true"
8+
labels:
9+
app: my-sdk
10+
spec:
11+
containers:
12+
- env:
13+
- name: OTEL_NODE_IP
14+
valueFrom:
15+
fieldRef:
16+
fieldPath: status.hostIP
17+
- name: OTEL_POD_IP
18+
valueFrom:
19+
fieldRef:
20+
fieldPath: status.podIP
21+
- name: SPLUNK_TRACE_RESPONSE_HEADER_ENABLED
22+
value: "true"
23+
- name: OTEL_SERVICE_NAME
24+
value: my-sdk
25+
- name: OTEL_EXPORTER_OTLP_ENDPOINT
26+
value: http://localhost:4317
27+
- name: OTEL_RESOURCE_ATTRIBUTES_POD_NAME
28+
valueFrom:
29+
fieldRef:
30+
apiVersion: v1
31+
fieldPath: metadata.name
32+
- name: OTEL_RESOURCE_ATTRIBUTES_NODE_NAME
33+
valueFrom:
34+
fieldRef:
35+
apiVersion: v1
36+
fieldPath: spec.nodeName
37+
- name: OTEL_PROPAGATORS
38+
value: jaeger,b3
39+
- name: OTEL_TRACES_SAMPLER
40+
value: parentbased_traceidratio
41+
- name: OTEL_TRACES_SAMPLER_ARG
42+
value: "0.25"
43+
- name: OTEL_RESOURCE_ATTRIBUTES
44+
name: myapp
45+
volumeMounts:
46+
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
47+
readOnly: true
48+
- args:
49+
- --config=env:OTEL_CONFIG
50+
name: otc-container
51+
status:
52+
containerStatuses:
53+
- name: myapp
54+
ready: true
55+
started: true
56+
- name: otc-container
57+
ready: true
58+
started: true
59+
phase: Running
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: my-sdk
5+
namespace: my-other-dotnet-ns
6+
spec:
7+
selector:
8+
matchLabels:
9+
app: my-sdk
10+
replicas: 1
11+
template:
12+
metadata:
13+
labels:
14+
app: my-sdk
15+
annotations:
16+
sidecar.opentelemetry.io/inject: "true"
17+
spec:
18+
securityContext:
19+
runAsUser: 1000
20+
runAsGroup: 3000
21+
fsGroup: 3000
22+
containers:
23+
- name: myapp
24+
image: ghcr.io/open-telemetry/opentelemetry-operator/e2e-test-app-python:main
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
2+
apiVersion: chainsaw.kyverno.io/v1alpha1
3+
kind: Test
4+
metadata:
5+
creationTimestamp: null
6+
name: instrumentation-dotnet-multiannotation
7+
spec:
8+
steps:
9+
- name: step-00
10+
try:
11+
# In OpenShift, when a namespace is created, all necessary SCC annotations are automatically added. However, if a namespace is created using a resource file with only selected SCCs, the other auto-added SCCs are not included. Therefore, the UID-range and supplemental groups SCC annotations must be set after the namespace is created.
12+
- command:
13+
entrypoint: kubectl
14+
args:
15+
- annotate
16+
- namespace
17+
- ${NAMESPACE}
18+
- openshift.io/sa.scc.uid-range=1000/1000
19+
- --overwrite
20+
- command:
21+
entrypoint: kubectl
22+
args:
23+
- annotate
24+
- namespace
25+
- ${NAMESPACE}
26+
- openshift.io/sa.scc.supplemental-groups=3000/3000
27+
- --overwrite
28+
- apply:
29+
file: 00-install-collector.yaml
30+
- apply:
31+
file: 00-install-instrumentation.yaml
32+
- name: step-01
33+
try:
34+
- apply:
35+
file: 01-install-app.yaml
36+
- assert:
37+
file: 01-assert.yaml
38+
catch:
39+
- podLogs:
40+
selector: app=my-dotnet
41+
- name: step-02
42+
try:
43+
- apply:
44+
file: 02-install-app.yaml
45+
- assert:
46+
file: 02-assert.yaml
47+
catch:
48+
- podLogs:
49+
selector: app=my-sdk

0 commit comments

Comments
 (0)
Please sign in to comment.