Skip to content

Commit ffcef74

Browse files
committed
Set OTEL_LOGS_EXPORTER for python
1 parent 91759b0 commit ffcef74

File tree

4 files changed

+144
-2
lines changed

4 files changed

+144
-2
lines changed

pkg/instrumentation/podmutator_test.go

+32
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,10 @@ func TestMutatePod(t *testing.T) {
11971197
Name: "OTEL_METRICS_EXPORTER",
11981198
Value: "otlp",
11991199
},
1200+
{
1201+
Name: "OTEL_LOGS_EXPORTER",
1202+
Value: "otlp",
1203+
},
12001204
{
12011205
Name: "OTEL_EXPORTER_OTLP_ENDPOINT",
12021206
Value: "http://localhost:4318",
@@ -1300,6 +1304,10 @@ func TestMutatePod(t *testing.T) {
13001304
Name: "OTEL_METRICS_EXPORTER",
13011305
Value: "otlp",
13021306
},
1307+
{
1308+
Name: "OTEL_LOGS_EXPORTER",
1309+
Value: "otlp",
1310+
},
13031311
{
13041312
Name: "OTEL_EXPORTER_OTLP_ENDPOINT",
13051313
Value: "http://localhost:4318",
@@ -1393,6 +1401,10 @@ func TestMutatePod(t *testing.T) {
13931401
Name: "OTEL_METRICS_EXPORTER",
13941402
Value: "otlp",
13951403
},
1404+
{
1405+
Name: "OTEL_LOGS_EXPORTER",
1406+
Value: "otlp",
1407+
},
13961408
{
13971409
Name: "OTEL_EXPORTER_OTLP_ENDPOINT",
13981410
Value: "http://localhost:4318",
@@ -1501,6 +1513,10 @@ func TestMutatePod(t *testing.T) {
15011513
Name: "OTEL_METRICS_EXPORTER",
15021514
Value: "otlp",
15031515
},
1516+
{
1517+
Name: "OTEL_LOGS_EXPORTER",
1518+
Value: "otlp",
1519+
},
15041520
{
15051521
Name: "OTEL_EXPORTER_OTLP_ENDPOINT",
15061522
Value: "http://localhost:4318",
@@ -1592,6 +1608,10 @@ func TestMutatePod(t *testing.T) {
15921608
Name: "OTEL_METRICS_EXPORTER",
15931609
Value: "otlp",
15941610
},
1611+
{
1612+
Name: "OTEL_LOGS_EXPORTER",
1613+
Value: "otlp",
1614+
},
15951615
{
15961616
Name: "OTEL_EXPORTER_OTLP_ENDPOINT",
15971617
Value: "http://localhost:4318",
@@ -1685,6 +1705,10 @@ func TestMutatePod(t *testing.T) {
16851705
Name: "OTEL_METRICS_EXPORTER",
16861706
Value: "otlp",
16871707
},
1708+
{
1709+
Name: "OTEL_LOGS_EXPORTER",
1710+
Value: "otlp",
1711+
},
16881712
{
16891713
Name: "OTEL_EXPORTER_OTLP_ENDPOINT",
16901714
Value: "http://localhost:4318",
@@ -4064,6 +4088,10 @@ func TestMutatePod(t *testing.T) {
40644088
Name: "OTEL_METRICS_EXPORTER",
40654089
Value: "otlp",
40664090
},
4091+
{
4092+
Name: "OTEL_LOGS_EXPORTER",
4093+
Value: "otlp",
4094+
},
40674095
{
40684096
Name: "OTEL_SERVICE_NAME",
40694097
Value: "python1",
@@ -4139,6 +4167,10 @@ func TestMutatePod(t *testing.T) {
41394167
Name: "OTEL_METRICS_EXPORTER",
41404168
Value: "otlp",
41414169
},
4170+
{
4171+
Name: "OTEL_LOGS_EXPORTER",
4172+
Value: "otlp",
4173+
},
41424174
{
41434175
Name: "OTEL_SERVICE_NAME",
41444176
Value: "python2",

pkg/instrumentation/python.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const (
2626
envPythonPath = "PYTHONPATH"
2727
envOtelTracesExporter = "OTEL_TRACES_EXPORTER"
2828
envOtelMetricsExporter = "OTEL_METRICS_EXPORTER"
29+
envOtelLogsExporter = "OTEL_LOGS_EXPORTER"
2930
envOtelExporterOTLPProtocol = "OTEL_EXPORTER_OTLP_PROTOCOL"
3031
pythonPathPrefix = "/otel-auto-instrumentation-python/opentelemetry/instrumentation/auto_instrumentation"
3132
pythonPathSuffix = "/otel-auto-instrumentation-python"
@@ -70,7 +71,7 @@ func injectPythonSDK(pythonSpec v1alpha1.Python, pod corev1.Pod, index int) (cor
7071
})
7172
}
7273

73-
// Set OTEL_TRACES_EXPORTER to HTTP exporter if not set by user because it is what our autoinstrumentation supports.
74+
// Set OTEL_TRACES_EXPORTER to oltp exporter if not set by user because it is what our autoinstrumentation supports.
7475
idx = getIndexOfEnv(container.Env, envOtelTracesExporter)
7576
if idx == -1 {
7677
container.Env = append(container.Env, corev1.EnvVar{
@@ -79,7 +80,7 @@ func injectPythonSDK(pythonSpec v1alpha1.Python, pod corev1.Pod, index int) (cor
7980
})
8081
}
8182

82-
// Set OTEL_METRICS_EXPORTER to HTTP exporter if not set by user because it is what our autoinstrumentation supports.
83+
// Set OTEL_METRICS_EXPORTER to oltp exporter if not set by user because it is what our autoinstrumentation supports.
8384
idx = getIndexOfEnv(container.Env, envOtelMetricsExporter)
8485
if idx == -1 {
8586
container.Env = append(container.Env, corev1.EnvVar{
@@ -88,6 +89,15 @@ func injectPythonSDK(pythonSpec v1alpha1.Python, pod corev1.Pod, index int) (cor
8889
})
8990
}
9091

92+
// Set OTEL_LOGS_EXPORTER to oltp exporter if not set by user because it is what our autoinstrumentation supports.
93+
idx = getIndexOfEnv(container.Env, envOtelLogsExporter)
94+
if idx == -1 {
95+
container.Env = append(container.Env, corev1.EnvVar{
96+
Name: envOtelLogsExporter,
97+
Value: "otlp",
98+
})
99+
}
100+
91101
container.VolumeMounts = append(container.VolumeMounts, corev1.VolumeMount{
92102
Name: pythonVolumeName,
93103
MountPath: pythonInstrMountPath,

pkg/instrumentation/python_test.go

+96
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ func TestInjectPythonSDK(t *testing.T) {
9090
Name: "OTEL_METRICS_EXPORTER",
9191
Value: "otlp",
9292
},
93+
{
94+
Name: "OTEL_LOGS_EXPORTER",
95+
Value: "otlp",
96+
},
9397
},
9498
},
9599
},
@@ -163,6 +167,10 @@ func TestInjectPythonSDK(t *testing.T) {
163167
Name: "OTEL_METRICS_EXPORTER",
164168
Value: "otlp",
165169
},
170+
{
171+
Name: "OTEL_LOGS_EXPORTER",
172+
Value: "otlp",
173+
},
166174
},
167175
},
168176
},
@@ -235,6 +243,10 @@ func TestInjectPythonSDK(t *testing.T) {
235243
Name: "OTEL_METRICS_EXPORTER",
236244
Value: "otlp",
237245
},
246+
{
247+
Name: "OTEL_LOGS_EXPORTER",
248+
Value: "otlp",
249+
},
238250
},
239251
},
240252
},
@@ -307,6 +319,86 @@ func TestInjectPythonSDK(t *testing.T) {
307319
Name: "OTEL_TRACES_EXPORTER",
308320
Value: "otlp",
309321
},
322+
{
323+
Name: "OTEL_LOGS_EXPORTER",
324+
Value: "otlp",
325+
},
326+
},
327+
},
328+
},
329+
},
330+
},
331+
err: nil,
332+
},
333+
{
334+
name: "OTEL_LOGS_EXPORTER defined",
335+
Python: v1alpha1.Python{Image: "foo/bar:1"},
336+
pod: corev1.Pod{
337+
Spec: corev1.PodSpec{
338+
Containers: []corev1.Container{
339+
{
340+
Env: []corev1.EnvVar{
341+
{
342+
Name: "OTEL_LOGS_EXPORTER",
343+
Value: "somebackend",
344+
},
345+
},
346+
},
347+
},
348+
},
349+
},
350+
expected: corev1.Pod{
351+
Spec: corev1.PodSpec{
352+
Volumes: []corev1.Volume{
353+
{
354+
Name: "opentelemetry-auto-instrumentation-python",
355+
VolumeSource: corev1.VolumeSource{
356+
EmptyDir: &corev1.EmptyDirVolumeSource{
357+
SizeLimit: &defaultVolumeLimitSize,
358+
},
359+
},
360+
},
361+
},
362+
InitContainers: []corev1.Container{
363+
{
364+
Name: "opentelemetry-auto-instrumentation-python",
365+
Image: "foo/bar:1",
366+
Command: []string{"cp", "-r", "/autoinstrumentation/.", "/otel-auto-instrumentation-python"},
367+
VolumeMounts: []corev1.VolumeMount{{
368+
Name: "opentelemetry-auto-instrumentation-python",
369+
MountPath: "/otel-auto-instrumentation-python",
370+
}},
371+
},
372+
},
373+
Containers: []corev1.Container{
374+
{
375+
VolumeMounts: []corev1.VolumeMount{
376+
{
377+
Name: "opentelemetry-auto-instrumentation-python",
378+
MountPath: "/otel-auto-instrumentation-python",
379+
},
380+
},
381+
Env: []corev1.EnvVar{
382+
{
383+
Name: "OTEL_LOGS_EXPORTER",
384+
Value: "somebackend",
385+
},
386+
{
387+
Name: "PYTHONPATH",
388+
Value: fmt.Sprintf("%s:%s", "/otel-auto-instrumentation-python/opentelemetry/instrumentation/auto_instrumentation", "/otel-auto-instrumentation-python"),
389+
},
390+
{
391+
Name: "OTEL_EXPORTER_OTLP_PROTOCOL",
392+
Value: "http/protobuf",
393+
},
394+
{
395+
Name: "OTEL_TRACES_EXPORTER",
396+
Value: "otlp",
397+
},
398+
{
399+
Name: "OTEL_METRICS_EXPORTER",
400+
Value: "otlp",
401+
},
310402
},
311403
},
312404
},
@@ -379,6 +471,10 @@ func TestInjectPythonSDK(t *testing.T) {
379471
Name: "OTEL_METRICS_EXPORTER",
380472
Value: "otlp",
381473
},
474+
{
475+
Name: "OTEL_LOGS_EXPORTER",
476+
Value: "otlp",
477+
},
382478
},
383479
},
384480
},

pkg/instrumentation/sdk_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,10 @@ func TestInjectPython(t *testing.T) {
12611261
Name: "OTEL_METRICS_EXPORTER",
12621262
Value: "otlp",
12631263
},
1264+
{
1265+
Name: "OTEL_LOGS_EXPORTER",
1266+
Value: "otlp",
1267+
},
12641268
{
12651269
Name: "OTEL_SERVICE_NAME",
12661270
Value: "app",

0 commit comments

Comments
 (0)