From 607a7b02d5138f3c54de2a8719407ba68b65bce8 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Mon, 7 Oct 2024 10:53:02 +0200 Subject: [PATCH 1/8] Set OTEL_LOGS_EXPORTER for python --- pkg/instrumentation/podmutator_test.go | 32 +++++++++ pkg/instrumentation/python.go | 14 +++- pkg/instrumentation/python_test.go | 96 ++++++++++++++++++++++++++ pkg/instrumentation/sdk_test.go | 4 ++ 4 files changed, 144 insertions(+), 2 deletions(-) diff --git a/pkg/instrumentation/podmutator_test.go b/pkg/instrumentation/podmutator_test.go index 400d44c22b..dd471ad789 100644 --- a/pkg/instrumentation/podmutator_test.go +++ b/pkg/instrumentation/podmutator_test.go @@ -1258,6 +1258,10 @@ func TestMutatePod(t *testing.T) { Name: "OTEL_METRICS_EXPORTER", Value: "otlp", }, + { + Name: "OTEL_LOGS_EXPORTER", + Value: "otlp", + }, { Name: "OTEL_EXPORTER_OTLP_ENDPOINT", Value: "http://localhost:4318", @@ -1361,6 +1365,10 @@ func TestMutatePod(t *testing.T) { Name: "OTEL_METRICS_EXPORTER", Value: "otlp", }, + { + Name: "OTEL_LOGS_EXPORTER", + Value: "otlp", + }, { Name: "OTEL_EXPORTER_OTLP_ENDPOINT", Value: "http://localhost:4318", @@ -1454,6 +1462,10 @@ func TestMutatePod(t *testing.T) { Name: "OTEL_METRICS_EXPORTER", Value: "otlp", }, + { + Name: "OTEL_LOGS_EXPORTER", + Value: "otlp", + }, { Name: "OTEL_EXPORTER_OTLP_ENDPOINT", Value: "http://localhost:4318", @@ -1562,6 +1574,10 @@ func TestMutatePod(t *testing.T) { Name: "OTEL_METRICS_EXPORTER", Value: "otlp", }, + { + Name: "OTEL_LOGS_EXPORTER", + Value: "otlp", + }, { Name: "OTEL_EXPORTER_OTLP_ENDPOINT", Value: "http://localhost:4318", @@ -1653,6 +1669,10 @@ func TestMutatePod(t *testing.T) { Name: "OTEL_METRICS_EXPORTER", Value: "otlp", }, + { + Name: "OTEL_LOGS_EXPORTER", + Value: "otlp", + }, { Name: "OTEL_EXPORTER_OTLP_ENDPOINT", Value: "http://localhost:4318", @@ -1746,6 +1766,10 @@ func TestMutatePod(t *testing.T) { Name: "OTEL_METRICS_EXPORTER", Value: "otlp", }, + { + Name: "OTEL_LOGS_EXPORTER", + Value: "otlp", + }, { Name: "OTEL_EXPORTER_OTLP_ENDPOINT", Value: "http://localhost:4318", @@ -4125,6 +4149,10 @@ func TestMutatePod(t *testing.T) { Name: "OTEL_METRICS_EXPORTER", Value: "otlp", }, + { + Name: "OTEL_LOGS_EXPORTER", + Value: "otlp", + }, { Name: "OTEL_SERVICE_NAME", Value: "python1", @@ -4200,6 +4228,10 @@ func TestMutatePod(t *testing.T) { Name: "OTEL_METRICS_EXPORTER", Value: "otlp", }, + { + Name: "OTEL_LOGS_EXPORTER", + Value: "otlp", + }, { Name: "OTEL_SERVICE_NAME", Value: "python2", diff --git a/pkg/instrumentation/python.go b/pkg/instrumentation/python.go index d3cfc51ca4..079672e8cf 100644 --- a/pkg/instrumentation/python.go +++ b/pkg/instrumentation/python.go @@ -26,6 +26,7 @@ const ( envPythonPath = "PYTHONPATH" envOtelTracesExporter = "OTEL_TRACES_EXPORTER" envOtelMetricsExporter = "OTEL_METRICS_EXPORTER" + envOtelLogsExporter = "OTEL_LOGS_EXPORTER" envOtelExporterOTLPProtocol = "OTEL_EXPORTER_OTLP_PROTOCOL" pythonPathPrefix = "/otel-auto-instrumentation-python/opentelemetry/instrumentation/auto_instrumentation" pythonPathSuffix = "/otel-auto-instrumentation-python" @@ -70,7 +71,7 @@ func injectPythonSDK(pythonSpec v1alpha1.Python, pod corev1.Pod, index int) (cor }) } - // Set OTEL_TRACES_EXPORTER to HTTP exporter if not set by user because it is what our autoinstrumentation supports. + // Set OTEL_TRACES_EXPORTER to oltp exporter if not set by user because it is what our autoinstrumentation supports. idx = getIndexOfEnv(container.Env, envOtelTracesExporter) if idx == -1 { container.Env = append(container.Env, corev1.EnvVar{ @@ -79,7 +80,7 @@ func injectPythonSDK(pythonSpec v1alpha1.Python, pod corev1.Pod, index int) (cor }) } - // Set OTEL_METRICS_EXPORTER to HTTP exporter if not set by user because it is what our autoinstrumentation supports. + // Set OTEL_METRICS_EXPORTER to oltp exporter if not set by user because it is what our autoinstrumentation supports. idx = getIndexOfEnv(container.Env, envOtelMetricsExporter) if idx == -1 { container.Env = append(container.Env, corev1.EnvVar{ @@ -88,6 +89,15 @@ func injectPythonSDK(pythonSpec v1alpha1.Python, pod corev1.Pod, index int) (cor }) } + // Set OTEL_LOGS_EXPORTER to oltp exporter if not set by user because it is what our autoinstrumentation supports. + idx = getIndexOfEnv(container.Env, envOtelLogsExporter) + if idx == -1 { + container.Env = append(container.Env, corev1.EnvVar{ + Name: envOtelLogsExporter, + Value: "otlp", + }) + } + container.VolumeMounts = append(container.VolumeMounts, corev1.VolumeMount{ Name: pythonVolumeName, MountPath: pythonInstrMountPath, diff --git a/pkg/instrumentation/python_test.go b/pkg/instrumentation/python_test.go index 2ced01bb07..01fe9b1665 100644 --- a/pkg/instrumentation/python_test.go +++ b/pkg/instrumentation/python_test.go @@ -90,6 +90,10 @@ func TestInjectPythonSDK(t *testing.T) { Name: "OTEL_METRICS_EXPORTER", Value: "otlp", }, + { + Name: "OTEL_LOGS_EXPORTER", + Value: "otlp", + }, }, }, }, @@ -163,6 +167,10 @@ func TestInjectPythonSDK(t *testing.T) { Name: "OTEL_METRICS_EXPORTER", Value: "otlp", }, + { + Name: "OTEL_LOGS_EXPORTER", + Value: "otlp", + }, }, }, }, @@ -235,6 +243,10 @@ func TestInjectPythonSDK(t *testing.T) { Name: "OTEL_METRICS_EXPORTER", Value: "otlp", }, + { + Name: "OTEL_LOGS_EXPORTER", + Value: "otlp", + }, }, }, }, @@ -307,6 +319,86 @@ func TestInjectPythonSDK(t *testing.T) { Name: "OTEL_TRACES_EXPORTER", Value: "otlp", }, + { + Name: "OTEL_LOGS_EXPORTER", + Value: "otlp", + }, + }, + }, + }, + }, + }, + err: nil, + }, + { + name: "OTEL_LOGS_EXPORTER defined", + Python: v1alpha1.Python{Image: "foo/bar:1"}, + pod: corev1.Pod{ + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Env: []corev1.EnvVar{ + { + Name: "OTEL_LOGS_EXPORTER", + Value: "somebackend", + }, + }, + }, + }, + }, + }, + expected: corev1.Pod{ + Spec: corev1.PodSpec{ + Volumes: []corev1.Volume{ + { + Name: "opentelemetry-auto-instrumentation-python", + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{ + SizeLimit: &defaultVolumeLimitSize, + }, + }, + }, + }, + InitContainers: []corev1.Container{ + { + Name: "opentelemetry-auto-instrumentation-python", + Image: "foo/bar:1", + Command: []string{"cp", "-r", "/autoinstrumentation/.", "/otel-auto-instrumentation-python"}, + VolumeMounts: []corev1.VolumeMount{{ + Name: "opentelemetry-auto-instrumentation-python", + MountPath: "/otel-auto-instrumentation-python", + }}, + }, + }, + Containers: []corev1.Container{ + { + VolumeMounts: []corev1.VolumeMount{ + { + Name: "opentelemetry-auto-instrumentation-python", + MountPath: "/otel-auto-instrumentation-python", + }, + }, + Env: []corev1.EnvVar{ + { + Name: "OTEL_LOGS_EXPORTER", + Value: "somebackend", + }, + { + Name: "PYTHONPATH", + Value: fmt.Sprintf("%s:%s", "/otel-auto-instrumentation-python/opentelemetry/instrumentation/auto_instrumentation", "/otel-auto-instrumentation-python"), + }, + { + Name: "OTEL_EXPORTER_OTLP_PROTOCOL", + Value: "http/protobuf", + }, + { + Name: "OTEL_TRACES_EXPORTER", + Value: "otlp", + }, + { + Name: "OTEL_METRICS_EXPORTER", + Value: "otlp", + }, }, }, }, @@ -379,6 +471,10 @@ func TestInjectPythonSDK(t *testing.T) { Name: "OTEL_METRICS_EXPORTER", Value: "otlp", }, + { + Name: "OTEL_LOGS_EXPORTER", + Value: "otlp", + }, }, }, }, diff --git a/pkg/instrumentation/sdk_test.go b/pkg/instrumentation/sdk_test.go index c3abedac04..38013ed3ac 100644 --- a/pkg/instrumentation/sdk_test.go +++ b/pkg/instrumentation/sdk_test.go @@ -1261,6 +1261,10 @@ func TestInjectPython(t *testing.T) { Name: "OTEL_METRICS_EXPORTER", Value: "otlp", }, + { + Name: "OTEL_LOGS_EXPORTER", + Value: "otlp", + }, { Name: "OTEL_SERVICE_NAME", Value: "app", From cdb49f9612a78bd7d4c56fda17d750be0278d89e Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Mon, 7 Oct 2024 11:00:30 +0200 Subject: [PATCH 2/8] Add changelog --- .chloggen/3330-python-otel-logs-exporter.yaml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .chloggen/3330-python-otel-logs-exporter.yaml diff --git a/.chloggen/3330-python-otel-logs-exporter.yaml b/.chloggen/3330-python-otel-logs-exporter.yaml new file mode 100644 index 0000000000..0a4afe0145 --- /dev/null +++ b/.chloggen/3330-python-otel-logs-exporter.yaml @@ -0,0 +1,16 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action) +component: auto-instrumentation + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: set OTEL_LOGS_EXPORTER env var to oltp in python instrumentation + +# One or more tracking issues related to the change +issues: [3330] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: From 15c9574749cabe7c95cfab3a4ec63dbdf92c1696 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Mon, 7 Oct 2024 14:35:28 +0200 Subject: [PATCH 3/8] Update e2e tests --- .../instrumentation-python-multicontainer/01-assert.yaml | 4 ++++ .../instrumentation-python-multicontainer/02-assert.yaml | 2 ++ .../e2e-instrumentation/instrumentation-python/01-assert.yaml | 2 ++ 3 files changed, 8 insertions(+) diff --git a/tests/e2e-instrumentation/instrumentation-python-multicontainer/01-assert.yaml b/tests/e2e-instrumentation/instrumentation-python-multicontainer/01-assert.yaml index d0e8c12567..72f6e7e712 100644 --- a/tests/e2e-instrumentation/instrumentation-python-multicontainer/01-assert.yaml +++ b/tests/e2e-instrumentation/instrumentation-python-multicontainer/01-assert.yaml @@ -26,6 +26,8 @@ spec: value: otlp - name: OTEL_METRICS_EXPORTER value: otlp + - name: OTEL_LOGS_EXPORTER + value: otlp - name: OTEL_EXPORTER_OTLP_ENDPOINT value: http://localhost:4317 - name: OTEL_EXPORTER_OTLP_TIMEOUT @@ -74,6 +76,8 @@ spec: value: otlp - name: OTEL_METRICS_EXPORTER value: otlp + - name: OTEL_LOGS_EXPORTER + value: otlp - name: OTEL_EXPORTER_OTLP_ENDPOINT value: http://localhost:4317 - name: OTEL_EXPORTER_OTLP_TIMEOUT diff --git a/tests/e2e-instrumentation/instrumentation-python-multicontainer/02-assert.yaml b/tests/e2e-instrumentation/instrumentation-python-multicontainer/02-assert.yaml index da7c987e54..5e2cbf06e2 100644 --- a/tests/e2e-instrumentation/instrumentation-python-multicontainer/02-assert.yaml +++ b/tests/e2e-instrumentation/instrumentation-python-multicontainer/02-assert.yaml @@ -37,6 +37,8 @@ spec: value: otlp - name: OTEL_METRICS_EXPORTER value: otlp + - name: OTEL_LOGS_EXPORTER + value: otlp - name: OTEL_EXPORTER_OTLP_ENDPOINT value: http://localhost:4317 - name: OTEL_EXPORTER_OTLP_TIMEOUT diff --git a/tests/e2e-instrumentation/instrumentation-python/01-assert.yaml b/tests/e2e-instrumentation/instrumentation-python/01-assert.yaml index 62cf682ba0..d1319e3144 100644 --- a/tests/e2e-instrumentation/instrumentation-python/01-assert.yaml +++ b/tests/e2e-instrumentation/instrumentation-python/01-assert.yaml @@ -21,6 +21,8 @@ spec: value: debug - name: OTEL_TRACES_EXPORTER value: otlp + - name: OTEL_LOGS_EXPORTER + value: otlp - name: OTEL_EXPORTER_OTLP_ENDPOINT value: http://localhost:4318 - name: PYTHONPATH From b474a15d881a37fd4ffad68e9b461f48a7e62232 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Mon, 14 Oct 2024 17:04:44 +0200 Subject: [PATCH 4/8] Fix some e2e --- .../instrumentation-multi-multicontainer-go/02-assert.yaml | 2 ++ .../instrumentation-multi-multicontainer/01-assert.yaml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tests/e2e-multi-instrumentation/instrumentation-multi-multicontainer-go/02-assert.yaml b/tests/e2e-multi-instrumentation/instrumentation-multi-multicontainer-go/02-assert.yaml index 71d4e05d06..63c9e239e3 100644 --- a/tests/e2e-multi-instrumentation/instrumentation-multi-multicontainer-go/02-assert.yaml +++ b/tests/e2e-multi-instrumentation/instrumentation-multi-multicontainer-go/02-assert.yaml @@ -43,6 +43,8 @@ spec: value: otlp - name: OTEL_METRICS_EXPORTER value: otlp + - name: OTEL_LOGS_EXPORTER + value: otlp - name: OTEL_EXPORTER_OTLP_TIMEOUT value: "20" - name: OTEL_TRACES_SAMPLER diff --git a/tests/e2e-multi-instrumentation/instrumentation-multi-multicontainer/01-assert.yaml b/tests/e2e-multi-instrumentation/instrumentation-multi-multicontainer/01-assert.yaml index 61eabd4e91..b0edc6701f 100644 --- a/tests/e2e-multi-instrumentation/instrumentation-multi-multicontainer/01-assert.yaml +++ b/tests/e2e-multi-instrumentation/instrumentation-multi-multicontainer/01-assert.yaml @@ -185,6 +185,8 @@ spec: value: otlp - name: OTEL_METRICS_EXPORTER value: otlp + - name: OTEL_LOGS_EXPORTER + value: otlp - name: OTEL_TRACES_SAMPLER value: parentbased_traceidratio - name: OTEL_TRACES_SAMPLER_ARG From 201092427f72623d24f13262793459a766d647b2 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Mon, 14 Oct 2024 17:06:35 +0200 Subject: [PATCH 5/8] Fix instrumentation python test --- tests/e2e-instrumentation/instrumentation-python/01-assert.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/e2e-instrumentation/instrumentation-python/01-assert.yaml b/tests/e2e-instrumentation/instrumentation-python/01-assert.yaml index d1319e3144..62cf682ba0 100644 --- a/tests/e2e-instrumentation/instrumentation-python/01-assert.yaml +++ b/tests/e2e-instrumentation/instrumentation-python/01-assert.yaml @@ -21,8 +21,6 @@ spec: value: debug - name: OTEL_TRACES_EXPORTER value: otlp - - name: OTEL_LOGS_EXPORTER - value: otlp - name: OTEL_EXPORTER_OTLP_ENDPOINT value: http://localhost:4318 - name: PYTHONPATH From aad65c0f5366a19895daa634d674fd9157643474 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Mon, 14 Oct 2024 17:47:50 +0200 Subject: [PATCH 6/8] Another e2e fix --- tests/e2e-instrumentation/instrumentation-python/01-assert.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/e2e-instrumentation/instrumentation-python/01-assert.yaml b/tests/e2e-instrumentation/instrumentation-python/01-assert.yaml index 62cf682ba0..94ff9058d7 100644 --- a/tests/e2e-instrumentation/instrumentation-python/01-assert.yaml +++ b/tests/e2e-instrumentation/instrumentation-python/01-assert.yaml @@ -29,6 +29,8 @@ spec: value: http/protobuf - name: OTEL_METRICS_EXPORTER value: otlp + - name: OTEL_LOGS_EXPORTER + value: otlp - name: OTEL_EXPORTER_OTLP_TIMEOUT value: "20" - name: OTEL_TRACES_SAMPLER From fa2259c5a6a841cb06c95e21bc16a8fac9a14bc1 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Tue, 15 Oct 2024 12:04:27 +0200 Subject: [PATCH 7/8] Apply suggestions from code review --- pkg/instrumentation/python.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/instrumentation/python.go b/pkg/instrumentation/python.go index 079672e8cf..c0745cd814 100644 --- a/pkg/instrumentation/python.go +++ b/pkg/instrumentation/python.go @@ -71,7 +71,7 @@ func injectPythonSDK(pythonSpec v1alpha1.Python, pod corev1.Pod, index int) (cor }) } - // Set OTEL_TRACES_EXPORTER to oltp exporter if not set by user because it is what our autoinstrumentation supports. + // Set OTEL_TRACES_EXPORTER to otlp exporter if not set by user because it is what our autoinstrumentation supports. idx = getIndexOfEnv(container.Env, envOtelTracesExporter) if idx == -1 { container.Env = append(container.Env, corev1.EnvVar{ @@ -80,7 +80,7 @@ func injectPythonSDK(pythonSpec v1alpha1.Python, pod corev1.Pod, index int) (cor }) } - // Set OTEL_METRICS_EXPORTER to oltp exporter if not set by user because it is what our autoinstrumentation supports. + // Set OTEL_METRICS_EXPORTER to otlp exporter if not set by user because it is what our autoinstrumentation supports. idx = getIndexOfEnv(container.Env, envOtelMetricsExporter) if idx == -1 { container.Env = append(container.Env, corev1.EnvVar{ @@ -89,7 +89,7 @@ func injectPythonSDK(pythonSpec v1alpha1.Python, pod corev1.Pod, index int) (cor }) } - // Set OTEL_LOGS_EXPORTER to oltp exporter if not set by user because it is what our autoinstrumentation supports. + // Set OTEL_LOGS_EXPORTER to otlp exporter if not set by user because it is what our autoinstrumentation supports. idx = getIndexOfEnv(container.Env, envOtelLogsExporter) if idx == -1 { container.Env = append(container.Env, corev1.EnvVar{ From f8fd419038c1b0ef4f91db1420d4fe448b37013e Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Tue, 15 Oct 2024 21:37:46 +0200 Subject: [PATCH 8/8] Update .chloggen/3330-python-otel-logs-exporter.yaml Co-authored-by: Jacob Aronoff --- .chloggen/3330-python-otel-logs-exporter.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chloggen/3330-python-otel-logs-exporter.yaml b/.chloggen/3330-python-otel-logs-exporter.yaml index 0a4afe0145..021c205811 100644 --- a/.chloggen/3330-python-otel-logs-exporter.yaml +++ b/.chloggen/3330-python-otel-logs-exporter.yaml @@ -5,7 +5,7 @@ change_type: enhancement component: auto-instrumentation # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). -note: set OTEL_LOGS_EXPORTER env var to oltp in python instrumentation +note: set OTEL_LOGS_EXPORTER env var to otlp in python instrumentation # One or more tracking issues related to the change issues: [3330]