Skip to content

Commit 7d59d65

Browse files
authored
instrumentation/python: set OTEL_EXPORTER_OTLP_PROTOCOL to http/protobuf (open-telemetry#3165)
* instrumentation/python: set OTEL_EXPORTER_OTLP_PROTOCOL instead of signal specific env vars Instead of setting the environment variable for each signal use the common one that it is also set by the distro. * Add changelog * WIP e2e * Run gofmt * Update .chloggen/3165-python-otlp-protocol-env-var.yaml
1 parent 03b4bd5 commit 7d59d65

File tree

9 files changed

+146
-126
lines changed

9 files changed

+146
-126
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: enhancement
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: set OTEL_EXPORTER_OTLP_PROTOCOL instead of signal specific env vars in python instrumentation
9+
10+
# One or more tracking issues related to the change
11+
issues: [3165]
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/podmutator_test.go

+19-47
Original file line numberDiff line numberDiff line change
@@ -1309,11 +1309,7 @@ func TestMutatePod(t *testing.T) {
13091309
Value: fmt.Sprintf("%s:%s", pythonPathPrefix, pythonPathSuffix),
13101310
},
13111311
{
1312-
Name: "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL",
1313-
Value: "http/protobuf",
1314-
},
1315-
{
1316-
Name: "OTEL_EXPORTER_OTLP_METRICS_PROTOCOL",
1312+
Name: "OTEL_EXPORTER_OTLP_PROTOCOL",
13171313
Value: "http/protobuf",
13181314
},
13191315
{
@@ -1514,11 +1510,7 @@ func TestMutatePod(t *testing.T) {
15141510
Value: fmt.Sprintf("%s:%s", pythonPathPrefix, pythonPathSuffix),
15151511
},
15161512
{
1517-
Name: "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL",
1518-
Value: "http/protobuf",
1519-
},
1520-
{
1521-
Name: "OTEL_EXPORTER_OTLP_METRICS_PROTOCOL",
1513+
Name: "OTEL_EXPORTER_OTLP_PROTOCOL",
15221514
Value: "http/protobuf",
15231515
},
15241516
{
@@ -1609,11 +1601,7 @@ func TestMutatePod(t *testing.T) {
16091601
Value: fmt.Sprintf("%s:%s", pythonPathPrefix, pythonPathSuffix),
16101602
},
16111603
{
1612-
Name: "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL",
1613-
Value: "http/protobuf",
1614-
},
1615-
{
1616-
Name: "OTEL_EXPORTER_OTLP_METRICS_PROTOCOL",
1604+
Name: "OTEL_EXPORTER_OTLP_PROTOCOL",
16171605
Value: "http/protobuf",
16181606
},
16191607
{
@@ -4065,20 +4053,16 @@ func TestMutatePod(t *testing.T) {
40654053
Value: fmt.Sprintf("%s:%s", pythonPathPrefix, pythonPathSuffix),
40664054
},
40674055
{
4068-
Name: "OTEL_TRACES_EXPORTER",
4069-
Value: "otlp",
4070-
},
4071-
{
4072-
Name: "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL",
4056+
Name: "OTEL_EXPORTER_OTLP_PROTOCOL",
40734057
Value: "http/protobuf",
40744058
},
40754059
{
4076-
Name: "OTEL_METRICS_EXPORTER",
4060+
Name: "OTEL_TRACES_EXPORTER",
40774061
Value: "otlp",
40784062
},
40794063
{
4080-
Name: "OTEL_EXPORTER_OTLP_METRICS_PROTOCOL",
4081-
Value: "http/protobuf",
4064+
Name: "OTEL_METRICS_EXPORTER",
4065+
Value: "otlp",
40824066
},
40834067
{
40844068
Name: "OTEL_SERVICE_NAME",
@@ -4144,20 +4128,16 @@ func TestMutatePod(t *testing.T) {
41444128
Value: fmt.Sprintf("%s:%s", pythonPathPrefix, pythonPathSuffix),
41454129
},
41464130
{
4147-
Name: "OTEL_TRACES_EXPORTER",
4148-
Value: "otlp",
4149-
},
4150-
{
4151-
Name: "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL",
4131+
Name: "OTEL_EXPORTER_OTLP_PROTOCOL",
41524132
Value: "http/protobuf",
41534133
},
41544134
{
4155-
Name: "OTEL_METRICS_EXPORTER",
4135+
Name: "OTEL_TRACES_EXPORTER",
41564136
Value: "otlp",
41574137
},
41584138
{
4159-
Name: "OTEL_EXPORTER_OTLP_METRICS_PROTOCOL",
4160-
Value: "http/protobuf",
4139+
Name: "OTEL_METRICS_EXPORTER",
4140+
Value: "otlp",
41614141
},
41624142
{
41634143
Name: "OTEL_SERVICE_NAME",
@@ -4850,20 +4830,16 @@ func TestMutatePod(t *testing.T) {
48504830
Value: fmt.Sprintf("%s:%s", pythonPathPrefix, pythonPathSuffix),
48514831
},
48524832
{
4853-
Name: "OTEL_TRACES_EXPORTER",
4854-
Value: "otlp",
4855-
},
4856-
{
4857-
Name: "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL",
4833+
Name: "OTEL_EXPORTER_OTLP_PROTOCOL",
48584834
Value: "http/protobuf",
48594835
},
48604836
{
4861-
Name: "OTEL_METRICS_EXPORTER",
4837+
Name: "OTEL_TRACES_EXPORTER",
48624838
Value: "otlp",
48634839
},
48644840
{
4865-
Name: "OTEL_EXPORTER_OTLP_METRICS_PROTOCOL",
4866-
Value: "http/protobuf",
4841+
Name: "OTEL_METRICS_EXPORTER",
4842+
Value: "otlp",
48674843
},
48684844
{
48694845
Name: "OTEL_SERVICE_NAME",
@@ -4929,20 +4905,16 @@ func TestMutatePod(t *testing.T) {
49294905
Value: fmt.Sprintf("%s:%s", pythonPathPrefix, pythonPathSuffix),
49304906
},
49314907
{
4932-
Name: "OTEL_TRACES_EXPORTER",
4933-
Value: "otlp",
4934-
},
4935-
{
4936-
Name: "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL",
4908+
Name: "OTEL_EXPORTER_OTLP_PROTOCOL",
49374909
Value: "http/protobuf",
49384910
},
49394911
{
4940-
Name: "OTEL_METRICS_EXPORTER",
4912+
Name: "OTEL_TRACES_EXPORTER",
49414913
Value: "otlp",
49424914
},
49434915
{
4944-
Name: "OTEL_EXPORTER_OTLP_METRICS_PROTOCOL",
4945-
Value: "http/protobuf",
4916+
Name: "OTEL_METRICS_EXPORTER",
4917+
Value: "otlp",
49464918
},
49474919
{
49484920
Name: "OTEL_SERVICE_NAME",

pkg/instrumentation/python.go

+17-27
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,15 @@ import (
2323
)
2424

2525
const (
26-
envPythonPath = "PYTHONPATH"
27-
envOtelTracesExporter = "OTEL_TRACES_EXPORTER"
28-
envOtelMetricsExporter = "OTEL_METRICS_EXPORTER"
29-
envOtelExporterOTLPTracesProtocol = "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL"
30-
envOtelExporterOTLPMetricsProtocol = "OTEL_EXPORTER_OTLP_METRICS_PROTOCOL"
31-
pythonPathPrefix = "/otel-auto-instrumentation-python/opentelemetry/instrumentation/auto_instrumentation"
32-
pythonPathSuffix = "/otel-auto-instrumentation-python"
33-
pythonInstrMountPath = "/otel-auto-instrumentation-python"
34-
pythonVolumeName = volumeName + "-python"
35-
pythonInitContainerName = initContainerName + "-python"
26+
envPythonPath = "PYTHONPATH"
27+
envOtelTracesExporter = "OTEL_TRACES_EXPORTER"
28+
envOtelMetricsExporter = "OTEL_METRICS_EXPORTER"
29+
envOtelExporterOTLPProtocol = "OTEL_EXPORTER_OTLP_PROTOCOL"
30+
pythonPathPrefix = "/otel-auto-instrumentation-python/opentelemetry/instrumentation/auto_instrumentation"
31+
pythonPathSuffix = "/otel-auto-instrumentation-python"
32+
pythonInstrMountPath = "/otel-auto-instrumentation-python"
33+
pythonVolumeName = volumeName + "-python"
34+
pythonInitContainerName = initContainerName + "-python"
3635
)
3736

3837
func injectPythonSDK(pythonSpec v1alpha1.Python, pod corev1.Pod, index int) (corev1.Pod, error) {
@@ -62,21 +61,21 @@ func injectPythonSDK(pythonSpec v1alpha1.Python, pod corev1.Pod, index int) (cor
6261
container.Env[idx].Value = fmt.Sprintf("%s:%s:%s", pythonPathPrefix, container.Env[idx].Value, pythonPathSuffix)
6362
}
6463

65-
// Set OTEL_TRACES_EXPORTER to HTTP exporter if not set by user because it is what our autoinstrumentation supports.
66-
idx = getIndexOfEnv(container.Env, envOtelTracesExporter)
64+
// Set OTEL_EXPORTER_OTLP_PROTOCOL to http/protobuf if not set by user because it is what our autoinstrumentation supports.
65+
idx = getIndexOfEnv(container.Env, envOtelExporterOTLPProtocol)
6766
if idx == -1 {
6867
container.Env = append(container.Env, corev1.EnvVar{
69-
Name: envOtelTracesExporter,
70-
Value: "otlp",
68+
Name: envOtelExporterOTLPProtocol,
69+
Value: "http/protobuf",
7170
})
7271
}
7372

74-
// Set OTEL_EXPORTER_OTLP_TRACES_PROTOCOL to http/protobuf if not set by user because it is what our autoinstrumentation supports.
75-
idx = getIndexOfEnv(container.Env, envOtelExporterOTLPTracesProtocol)
73+
// Set OTEL_TRACES_EXPORTER to HTTP exporter if not set by user because it is what our autoinstrumentation supports.
74+
idx = getIndexOfEnv(container.Env, envOtelTracesExporter)
7675
if idx == -1 {
7776
container.Env = append(container.Env, corev1.EnvVar{
78-
Name: envOtelExporterOTLPTracesProtocol,
79-
Value: "http/protobuf",
77+
Name: envOtelTracesExporter,
78+
Value: "otlp",
8079
})
8180
}
8281

@@ -89,15 +88,6 @@ func injectPythonSDK(pythonSpec v1alpha1.Python, pod corev1.Pod, index int) (cor
8988
})
9089
}
9190

92-
// Set OTEL_EXPORTER_OTLP_METRICS_PROTOCOL to http/protobuf if not set by user because it is what our autoinstrumentation supports.
93-
idx = getIndexOfEnv(container.Env, envOtelExporterOTLPMetricsProtocol)
94-
if idx == -1 {
95-
container.Env = append(container.Env, corev1.EnvVar{
96-
Name: envOtelExporterOTLPMetricsProtocol,
97-
Value: "http/protobuf",
98-
})
99-
}
100-
10191
container.VolumeMounts = append(container.VolumeMounts, corev1.VolumeMount{
10292
Name: pythonVolumeName,
10393
MountPath: pythonInstrMountPath,

pkg/instrumentation/python_test.go

+81-25
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,16 @@ func TestInjectPythonSDK(t *testing.T) {
7979
Value: fmt.Sprintf("%s:%s", "/otel-auto-instrumentation-python/opentelemetry/instrumentation/auto_instrumentation", "/otel-auto-instrumentation-python"),
8080
},
8181
{
82-
Name: "OTEL_TRACES_EXPORTER",
83-
Value: "otlp",
84-
},
85-
{
86-
Name: "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL",
82+
Name: "OTEL_EXPORTER_OTLP_PROTOCOL",
8783
Value: "http/protobuf",
8884
},
8985
{
90-
Name: "OTEL_METRICS_EXPORTER",
86+
Name: "OTEL_TRACES_EXPORTER",
9187
Value: "otlp",
9288
},
9389
{
94-
Name: "OTEL_EXPORTER_OTLP_METRICS_PROTOCOL",
95-
Value: "http/protobuf",
90+
Name: "OTEL_METRICS_EXPORTER",
91+
Value: "otlp",
9692
},
9793
},
9894
},
@@ -156,20 +152,16 @@ func TestInjectPythonSDK(t *testing.T) {
156152
Value: fmt.Sprintf("%s:%s:%s", "/otel-auto-instrumentation-python/opentelemetry/instrumentation/auto_instrumentation", "/foo:/bar", "/otel-auto-instrumentation-python"),
157153
},
158154
{
159-
Name: "OTEL_TRACES_EXPORTER",
160-
Value: "otlp",
161-
},
162-
{
163-
Name: "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL",
155+
Name: "OTEL_EXPORTER_OTLP_PROTOCOL",
164156
Value: "http/protobuf",
165157
},
166158
{
167-
Name: "OTEL_METRICS_EXPORTER",
159+
Name: "OTEL_TRACES_EXPORTER",
168160
Value: "otlp",
169161
},
170162
{
171-
Name: "OTEL_EXPORTER_OTLP_METRICS_PROTOCOL",
172-
Value: "http/protobuf",
163+
Name: "OTEL_METRICS_EXPORTER",
164+
Value: "otlp",
173165
},
174166
},
175167
},
@@ -236,17 +228,13 @@ func TestInjectPythonSDK(t *testing.T) {
236228
Value: fmt.Sprintf("%s:%s", "/otel-auto-instrumentation-python/opentelemetry/instrumentation/auto_instrumentation", "/otel-auto-instrumentation-python"),
237229
},
238230
{
239-
Name: "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL",
231+
Name: "OTEL_EXPORTER_OTLP_PROTOCOL",
240232
Value: "http/protobuf",
241233
},
242234
{
243235
Name: "OTEL_METRICS_EXPORTER",
244236
Value: "otlp",
245237
},
246-
{
247-
Name: "OTEL_EXPORTER_OTLP_METRICS_PROTOCOL",
248-
Value: "http/protobuf",
249-
},
250238
},
251239
},
252240
},
@@ -311,17 +299,85 @@ func TestInjectPythonSDK(t *testing.T) {
311299
Name: "PYTHONPATH",
312300
Value: fmt.Sprintf("%s:%s", "/otel-auto-instrumentation-python/opentelemetry/instrumentation/auto_instrumentation", "/otel-auto-instrumentation-python"),
313301
},
302+
{
303+
Name: "OTEL_EXPORTER_OTLP_PROTOCOL",
304+
Value: "http/protobuf",
305+
},
314306
{
315307
Name: "OTEL_TRACES_EXPORTER",
316308
Value: "otlp",
317309
},
310+
},
311+
},
312+
},
313+
},
314+
},
315+
err: nil,
316+
},
317+
{
318+
name: "OTEL_EXPORTER_OTLP_PROTOCOL defined",
319+
Python: v1alpha1.Python{Image: "foo/bar:1"},
320+
pod: corev1.Pod{
321+
Spec: corev1.PodSpec{
322+
Containers: []corev1.Container{
323+
{
324+
Env: []corev1.EnvVar{
318325
{
319-
Name: "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL",
320-
Value: "http/protobuf",
326+
Name: "OTEL_EXPORTER_OTLP_PROTOCOL",
327+
Value: "somebackend",
321328
},
329+
},
330+
},
331+
},
332+
},
333+
},
334+
expected: corev1.Pod{
335+
Spec: corev1.PodSpec{
336+
Volumes: []corev1.Volume{
337+
{
338+
Name: "opentelemetry-auto-instrumentation-python",
339+
VolumeSource: corev1.VolumeSource{
340+
EmptyDir: &corev1.EmptyDirVolumeSource{
341+
SizeLimit: &defaultVolumeLimitSize,
342+
},
343+
},
344+
},
345+
},
346+
InitContainers: []corev1.Container{
347+
{
348+
Name: "opentelemetry-auto-instrumentation-python",
349+
Image: "foo/bar:1",
350+
Command: []string{"cp", "-r", "/autoinstrumentation/.", "/otel-auto-instrumentation-python"},
351+
VolumeMounts: []corev1.VolumeMount{{
352+
Name: "opentelemetry-auto-instrumentation-python",
353+
MountPath: "/otel-auto-instrumentation-python",
354+
}},
355+
},
356+
},
357+
Containers: []corev1.Container{
358+
{
359+
VolumeMounts: []corev1.VolumeMount{
322360
{
323-
Name: "OTEL_EXPORTER_OTLP_METRICS_PROTOCOL",
324-
Value: "http/protobuf",
361+
Name: "opentelemetry-auto-instrumentation-python",
362+
MountPath: "/otel-auto-instrumentation-python",
363+
},
364+
},
365+
Env: []corev1.EnvVar{
366+
{
367+
Name: "OTEL_EXPORTER_OTLP_PROTOCOL",
368+
Value: "somebackend",
369+
},
370+
{
371+
Name: "PYTHONPATH",
372+
Value: fmt.Sprintf("%s:%s", "/otel-auto-instrumentation-python/opentelemetry/instrumentation/auto_instrumentation", "/otel-auto-instrumentation-python"),
373+
},
374+
{
375+
Name: "OTEL_TRACES_EXPORTER",
376+
Value: "otlp",
377+
},
378+
{
379+
Name: "OTEL_METRICS_EXPORTER",
380+
Value: "otlp",
325381
},
326382
},
327383
},

0 commit comments

Comments
 (0)