diff --git a/pkg/instrumentation/podmutator_test.go b/pkg/instrumentation/podmutator_test.go index 101d24fe24..3418b5533b 100644 --- a/pkg/instrumentation/podmutator_test.go +++ b/pkg/instrumentation/podmutator_test.go @@ -408,6 +408,10 @@ func TestMutatePod(t *testing.T) { Name: "OTEL_TRACES_EXPORTER", Value: "otlp_proto_http", }, + { + Name: "OTEL_METRICS_EXPORTER", + Value: "none", + }, { Name: "OTEL_EXPORTER_OTLP_ENDPOINT", Value: "http://localhost:4317", @@ -489,6 +493,10 @@ func TestMutatePod(t *testing.T) { Name: "OTEL_TRACES_EXPORTER", Value: "otlp_proto_http", }, + { + Name: "OTEL_METRICS_EXPORTER", + Value: "none", + }, { Name: "OTEL_EXPORTER_OTLP_ENDPOINT", Value: "http://localhost:4317", diff --git a/pkg/instrumentation/python.go b/pkg/instrumentation/python.go index e2c7495b0a..b3956e3530 100644 --- a/pkg/instrumentation/python.go +++ b/pkg/instrumentation/python.go @@ -24,10 +24,11 @@ import ( ) const ( - envPythonPath = "PYTHONPATH" - envOtelTracesExporter = "OTEL_TRACES_EXPORTER" - pythonPathPrefix = "/otel-auto-instrumentation/opentelemetry/instrumentation/auto_instrumentation" - pythonPathSuffix = "/otel-auto-instrumentation" + envPythonPath = "PYTHONPATH" + envOtelTracesExporter = "OTEL_TRACES_EXPORTER" + envOtelMetricsExporter = "OTEL_METRICS_EXPORTER" + pythonPathPrefix = "/otel-auto-instrumentation/opentelemetry/instrumentation/auto_instrumentation" + pythonPathSuffix = "/otel-auto-instrumentation" ) func injectPythonSDK(logger logr.Logger, pythonSpec v1alpha1.Python, pod corev1.Pod, index int) corev1.Pod { @@ -68,6 +69,18 @@ func injectPythonSDK(logger logr.Logger, pythonSpec v1alpha1.Python, pod corev1. }) } + // TODO: https://github.com/open-telemetry/opentelemetry-python/issues/2447 this should + // also be set to `otlp_proto_http` once an exporter is implemented. For now, set + // OTEL_METRICS_EXPORTER to none if not set by user to prevent using the default grpc + // exporter which is not included in the image. + idx = getIndexOfEnv(container.Env, envOtelMetricsExporter) + if idx == -1 { + container.Env = append(container.Env, corev1.EnvVar{ + Name: envOtelMetricsExporter, + Value: "none", + }) + } + container.VolumeMounts = append(container.VolumeMounts, corev1.VolumeMount{ Name: volumeName, MountPath: "/otel-auto-instrumentation", diff --git a/pkg/instrumentation/python_test.go b/pkg/instrumentation/python_test.go index 2d510fca38..c8a4887a19 100644 --- a/pkg/instrumentation/python_test.go +++ b/pkg/instrumentation/python_test.go @@ -80,6 +80,10 @@ func TestInjectPythonSDK(t *testing.T) { Name: "OTEL_TRACES_EXPORTER", Value: "otlp_proto_http", }, + { + Name: "OTEL_METRICS_EXPORTER", + Value: "none", + }, }, }, }, @@ -141,6 +145,10 @@ func TestInjectPythonSDK(t *testing.T) { Name: "OTEL_TRACES_EXPORTER", Value: "otlp_proto_http", }, + { + Name: "OTEL_METRICS_EXPORTER", + Value: "none", + }, }, }, }, @@ -202,6 +210,75 @@ func TestInjectPythonSDK(t *testing.T) { Name: "PYTHONPATH", Value: fmt.Sprintf("%s:%s", pythonPathPrefix, pythonPathSuffix), }, + { + Name: "OTEL_METRICS_EXPORTER", + Value: "none", + }, + }, + }, + }, + }, + }, + }, + { + name: "OTEL_METRICS_EXPORTER defined", + Python: v1alpha1.Python{Image: "foo/bar:1"}, + pod: corev1.Pod{ + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Env: []corev1.EnvVar{ + { + Name: "OTEL_METRICS_EXPORTER", + Value: "somebackend", + }, + }, + }, + }, + }, + }, + expected: corev1.Pod{ + Spec: corev1.PodSpec{ + Volumes: []corev1.Volume{ + { + Name: volumeName, + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{}, + }, + }, + }, + InitContainers: []corev1.Container{ + { + Name: initContainerName, + Image: "foo/bar:1", + Command: []string{"cp", "-a", "/autoinstrumentation/.", "/otel-auto-instrumentation/"}, + VolumeMounts: []corev1.VolumeMount{{ + Name: volumeName, + MountPath: "/otel-auto-instrumentation", + }}, + }, + }, + Containers: []corev1.Container{ + { + VolumeMounts: []corev1.VolumeMount{ + { + Name: volumeName, + MountPath: "/otel-auto-instrumentation", + }, + }, + Env: []corev1.EnvVar{ + { + Name: "OTEL_METRICS_EXPORTER", + Value: "somebackend", + }, + { + Name: "PYTHONPATH", + Value: fmt.Sprintf("%s:%s", pythonPathPrefix, pythonPathSuffix), + }, + { + Name: "OTEL_TRACES_EXPORTER", + Value: "otlp_proto_http", + }, }, }, }, diff --git a/pkg/instrumentation/sdk_test.go b/pkg/instrumentation/sdk_test.go index 31c29282f6..c900193f2d 100644 --- a/pkg/instrumentation/sdk_test.go +++ b/pkg/instrumentation/sdk_test.go @@ -636,6 +636,10 @@ func TestInjectPython(t *testing.T) { Name: "OTEL_TRACES_EXPORTER", Value: "otlp_proto_http", }, + { + Name: "OTEL_METRICS_EXPORTER", + Value: "none", + }, { Name: "OTEL_SERVICE_NAME", Value: "app", diff --git a/tests/e2e/instrumentation-python-multicontainer/01-assert.yaml b/tests/e2e/instrumentation-python-multicontainer/01-assert.yaml index 196be91e8d..41d2a13ea6 100644 --- a/tests/e2e/instrumentation-python-multicontainer/01-assert.yaml +++ b/tests/e2e/instrumentation-python-multicontainer/01-assert.yaml @@ -15,6 +15,8 @@ spec: value: /otel-auto-instrumentation/opentelemetry/instrumentation/auto_instrumentation:/otel-auto-instrumentation - name: OTEL_TRACES_EXPORTER value: otlp_proto_http + - name: OTEL_METRICS_EXPORTER + value: none - name: OTEL_EXPORTER_OTLP_ENDPOINT value: http://localhost:4317 - name: OTEL_EXPORTER_OTLP_TIMEOUT @@ -42,6 +44,8 @@ spec: value: /otel-auto-instrumentation/opentelemetry/instrumentation/auto_instrumentation:/otel-auto-instrumentation - name: OTEL_TRACES_EXPORTER value: otlp_proto_http + - name: OTEL_METRICS_EXPORTER + value: none - name: OTEL_EXPORTER_OTLP_ENDPOINT value: http://localhost:4317 - name: OTEL_EXPORTER_OTLP_TIMEOUT @@ -65,4 +69,4 @@ spec: name: opentelemetry-auto-instrumentation - name: otc-container status: - phase: Running \ No newline at end of file + phase: Running diff --git a/tests/e2e/instrumentation-python-multicontainer/02-assert.yaml b/tests/e2e/instrumentation-python-multicontainer/02-assert.yaml index 66335224b4..3bfcbfcc35 100644 --- a/tests/e2e/instrumentation-python-multicontainer/02-assert.yaml +++ b/tests/e2e/instrumentation-python-multicontainer/02-assert.yaml @@ -18,6 +18,8 @@ spec: value: /otel-auto-instrumentation/opentelemetry/instrumentation/auto_instrumentation:/otel-auto-instrumentation - name: OTEL_TRACES_EXPORTER value: otlp_proto_http + - name: OTEL_METRICS_EXPORTER + value: none - name: OTEL_EXPORTER_OTLP_ENDPOINT value: http://localhost:4317 - name: OTEL_EXPORTER_OTLP_TIMEOUT diff --git a/tests/e2e/instrumentation-python/01-assert.yaml b/tests/e2e/instrumentation-python/01-assert.yaml index c0336b0e3f..a1eb66123c 100644 --- a/tests/e2e/instrumentation-python/01-assert.yaml +++ b/tests/e2e/instrumentation-python/01-assert.yaml @@ -18,6 +18,8 @@ spec: value: http://localhost:4317 - name: PYTHONPATH value: "/otel-auto-instrumentation/opentelemetry/instrumentation/auto_instrumentation:/otel-auto-instrumentation" + - name: OTEL_METRICS_EXPORTER + value: none - name: OTEL_EXPORTER_OTLP_TIMEOUT value: "20" - name: OTEL_TRACES_SAMPLER