Skip to content

Commit c4c5cc8

Browse files
xrmxjaronoff97
andauthored
Set OTEL_LOGS_EXPORTER for python (#3330)
* Set OTEL_LOGS_EXPORTER for python * Add changelog * Update e2e tests * Fix some e2e * Fix instrumentation python test * Another e2e fix * Apply suggestions from code review * Update .chloggen/3330-python-otel-logs-exporter.yaml Co-authored-by: Jacob Aronoff <[email protected]> --------- Co-authored-by: Jacob Aronoff <[email protected]>
1 parent a748078 commit c4c5cc8

File tree

10 files changed

+172
-2
lines changed

10 files changed

+172
-2
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_LOGS_EXPORTER env var to otlp in python instrumentation
9+
10+
# One or more tracking issues related to the change
11+
issues: [3330]
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

+32
Original file line numberDiff line numberDiff line change
@@ -1258,6 +1258,10 @@ func TestMutatePod(t *testing.T) {
12581258
Name: "OTEL_METRICS_EXPORTER",
12591259
Value: "otlp",
12601260
},
1261+
{
1262+
Name: "OTEL_LOGS_EXPORTER",
1263+
Value: "otlp",
1264+
},
12611265
{
12621266
Name: "OTEL_EXPORTER_OTLP_ENDPOINT",
12631267
Value: "http://localhost:4318",
@@ -1361,6 +1365,10 @@ func TestMutatePod(t *testing.T) {
13611365
Name: "OTEL_METRICS_EXPORTER",
13621366
Value: "otlp",
13631367
},
1368+
{
1369+
Name: "OTEL_LOGS_EXPORTER",
1370+
Value: "otlp",
1371+
},
13641372
{
13651373
Name: "OTEL_EXPORTER_OTLP_ENDPOINT",
13661374
Value: "http://localhost:4318",
@@ -1454,6 +1462,10 @@ func TestMutatePod(t *testing.T) {
14541462
Name: "OTEL_METRICS_EXPORTER",
14551463
Value: "otlp",
14561464
},
1465+
{
1466+
Name: "OTEL_LOGS_EXPORTER",
1467+
Value: "otlp",
1468+
},
14571469
{
14581470
Name: "OTEL_EXPORTER_OTLP_ENDPOINT",
14591471
Value: "http://localhost:4318",
@@ -1562,6 +1574,10 @@ func TestMutatePod(t *testing.T) {
15621574
Name: "OTEL_METRICS_EXPORTER",
15631575
Value: "otlp",
15641576
},
1577+
{
1578+
Name: "OTEL_LOGS_EXPORTER",
1579+
Value: "otlp",
1580+
},
15651581
{
15661582
Name: "OTEL_EXPORTER_OTLP_ENDPOINT",
15671583
Value: "http://localhost:4318",
@@ -1653,6 +1669,10 @@ func TestMutatePod(t *testing.T) {
16531669
Name: "OTEL_METRICS_EXPORTER",
16541670
Value: "otlp",
16551671
},
1672+
{
1673+
Name: "OTEL_LOGS_EXPORTER",
1674+
Value: "otlp",
1675+
},
16561676
{
16571677
Name: "OTEL_EXPORTER_OTLP_ENDPOINT",
16581678
Value: "http://localhost:4318",
@@ -1746,6 +1766,10 @@ func TestMutatePod(t *testing.T) {
17461766
Name: "OTEL_METRICS_EXPORTER",
17471767
Value: "otlp",
17481768
},
1769+
{
1770+
Name: "OTEL_LOGS_EXPORTER",
1771+
Value: "otlp",
1772+
},
17491773
{
17501774
Name: "OTEL_EXPORTER_OTLP_ENDPOINT",
17511775
Value: "http://localhost:4318",
@@ -4125,6 +4149,10 @@ func TestMutatePod(t *testing.T) {
41254149
Name: "OTEL_METRICS_EXPORTER",
41264150
Value: "otlp",
41274151
},
4152+
{
4153+
Name: "OTEL_LOGS_EXPORTER",
4154+
Value: "otlp",
4155+
},
41284156
{
41294157
Name: "OTEL_SERVICE_NAME",
41304158
Value: "python1",
@@ -4200,6 +4228,10 @@ func TestMutatePod(t *testing.T) {
42004228
Name: "OTEL_METRICS_EXPORTER",
42014229
Value: "otlp",
42024230
},
4231+
{
4232+
Name: "OTEL_LOGS_EXPORTER",
4233+
Value: "otlp",
4234+
},
42034235
{
42044236
Name: "OTEL_SERVICE_NAME",
42054237
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 otlp 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 otlp 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 otlp 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",

tests/e2e-instrumentation/instrumentation-python-multicontainer/01-assert.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ spec:
2626
value: otlp
2727
- name: OTEL_METRICS_EXPORTER
2828
value: otlp
29+
- name: OTEL_LOGS_EXPORTER
30+
value: otlp
2931
- name: OTEL_EXPORTER_OTLP_ENDPOINT
3032
value: http://localhost:4317
3133
- name: OTEL_EXPORTER_OTLP_TIMEOUT
@@ -74,6 +76,8 @@ spec:
7476
value: otlp
7577
- name: OTEL_METRICS_EXPORTER
7678
value: otlp
79+
- name: OTEL_LOGS_EXPORTER
80+
value: otlp
7781
- name: OTEL_EXPORTER_OTLP_ENDPOINT
7882
value: http://localhost:4317
7983
- name: OTEL_EXPORTER_OTLP_TIMEOUT

tests/e2e-instrumentation/instrumentation-python-multicontainer/02-assert.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ spec:
3737
value: otlp
3838
- name: OTEL_METRICS_EXPORTER
3939
value: otlp
40+
- name: OTEL_LOGS_EXPORTER
41+
value: otlp
4042
- name: OTEL_EXPORTER_OTLP_ENDPOINT
4143
value: http://localhost:4317
4244
- name: OTEL_EXPORTER_OTLP_TIMEOUT

tests/e2e-instrumentation/instrumentation-python/01-assert.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ spec:
2929
value: http/protobuf
3030
- name: OTEL_METRICS_EXPORTER
3131
value: otlp
32+
- name: OTEL_LOGS_EXPORTER
33+
value: otlp
3234
- name: OTEL_EXPORTER_OTLP_TIMEOUT
3335
value: "20"
3436
- name: OTEL_TRACES_SAMPLER

tests/e2e-multi-instrumentation/instrumentation-multi-multicontainer-go/02-assert.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ spec:
4343
value: otlp
4444
- name: OTEL_METRICS_EXPORTER
4545
value: otlp
46+
- name: OTEL_LOGS_EXPORTER
47+
value: otlp
4648
- name: OTEL_EXPORTER_OTLP_TIMEOUT
4749
value: "20"
4850
- name: OTEL_TRACES_SAMPLER

tests/e2e-multi-instrumentation/instrumentation-multi-multicontainer/01-assert.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ spec:
185185
value: otlp
186186
- name: OTEL_METRICS_EXPORTER
187187
value: otlp
188+
- name: OTEL_LOGS_EXPORTER
189+
value: otlp
188190
- name: OTEL_TRACES_SAMPLER
189191
value: parentbased_traceidratio
190192
- name: OTEL_TRACES_SAMPLER_ARG

0 commit comments

Comments
 (0)