diff --git a/.chloggen/update-python-metrics-exporter.yaml b/.chloggen/update-python-metrics-exporter.yaml new file mode 100755 index 0000000000..e68545a60e --- /dev/null +++ b/.chloggen/update-python-metrics-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. operator, target allocator, github action) +component: instrumentation/python + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Updates the default exporters to `otlp` and sets `OTEL_EXPORTER_OTLP_[TRACES|METRICS]_PROTOCOL` to `http/protobuf` + +# One or more tracking issues related to the change +issues: [1328] + +# (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: diff --git a/pkg/instrumentation/podmutator_test.go b/pkg/instrumentation/podmutator_test.go index 352f208d63..64a6e1fb0b 100644 --- a/pkg/instrumentation/podmutator_test.go +++ b/pkg/instrumentation/podmutator_test.go @@ -406,15 +406,15 @@ func TestMutatePod(t *testing.T) { }, { Name: "OTEL_TRACES_EXPORTER", - Value: "otlp_proto_http", + Value: "otlp", }, { Name: "OTEL_METRICS_EXPORTER", - Value: "none", + Value: "otlp", }, { Name: "OTEL_EXPORTER_OTLP_ENDPOINT", - Value: "http://localhost:4317", + Value: "http://localhost:4318", }, }, }, @@ -491,20 +491,28 @@ func TestMutatePod(t *testing.T) { }, { Name: "OTEL_TRACES_EXPORTER", - Value: "otlp_proto_http", + Value: "otlp", }, { Name: "OTEL_METRICS_EXPORTER", - Value: "none", + Value: "otlp", }, { Name: "OTEL_EXPORTER_OTLP_ENDPOINT", - Value: "http://localhost:4317", + Value: "http://localhost:4318", }, { Name: "PYTHONPATH", Value: fmt.Sprintf("%s:%s", pythonPathPrefix, pythonPathSuffix), }, + { + Name: "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL", + Value: "http/protobuf", + }, + { + Name: "OTEL_EXPORTER_OTLP_METRICS_PROTOCOL", + Value: "http/protobuf", + }, { Name: "OTEL_EXPORTER_OTLP_TIMEOUT", Value: "20", diff --git a/pkg/instrumentation/python.go b/pkg/instrumentation/python.go index 2662ddc877..b7eaebc681 100644 --- a/pkg/instrumentation/python.go +++ b/pkg/instrumentation/python.go @@ -23,11 +23,13 @@ import ( ) const ( - envPythonPath = "PYTHONPATH" - envOtelTracesExporter = "OTEL_TRACES_EXPORTER" - envOtelMetricsExporter = "OTEL_METRICS_EXPORTER" - pythonPathPrefix = "/otel-auto-instrumentation/opentelemetry/instrumentation/auto_instrumentation" - pythonPathSuffix = "/otel-auto-instrumentation" + envPythonPath = "PYTHONPATH" + envOtelTracesExporter = "OTEL_TRACES_EXPORTER" + envOtelMetricsExporter = "OTEL_METRICS_EXPORTER" + envOtelExporterOTLPTracesProtocol = "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL" + envOtelExporterOTLPMetricsProtocol = "OTEL_EXPORTER_OTLP_METRICS_PROTOCOL" + pythonPathPrefix = "/otel-auto-instrumentation/opentelemetry/instrumentation/auto_instrumentation" + pythonPathSuffix = "/otel-auto-instrumentation" ) func injectPythonSDK(pythonSpec v1alpha1.Python, pod corev1.Pod, index int) (corev1.Pod, error) { @@ -62,19 +64,34 @@ func injectPythonSDK(pythonSpec v1alpha1.Python, pod corev1.Pod, index int) (cor if idx == -1 { container.Env = append(container.Env, corev1.EnvVar{ Name: envOtelTracesExporter, - Value: "otlp_proto_http", + Value: "otlp", }) } - // 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. + // Set OTEL_EXPORTER_OTLP_TRACES_PROTOCOL to http/protobuf if not set by user because it is what our autoinstrumentation supports. + idx = getIndexOfEnv(container.Env, envOtelExporterOTLPTracesProtocol) + if idx == -1 { + container.Env = append(container.Env, corev1.EnvVar{ + Name: envOtelExporterOTLPTracesProtocol, + Value: "http/protobuf", + }) + } + + // Set OTEL_METRICS_EXPORTER to HTTP 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{ Name: envOtelMetricsExporter, - Value: "none", + Value: "otlp", + }) + } + + // Set OTEL_EXPORTER_OTLP_METRICS_PROTOCOL to http/protobuf if not set by user because it is what our autoinstrumentation supports. + idx = getIndexOfEnv(container.Env, envOtelExporterOTLPMetricsProtocol) + if idx == -1 { + container.Env = append(container.Env, corev1.EnvVar{ + Name: envOtelExporterOTLPMetricsProtocol, + Value: "http/protobuf", }) } diff --git a/pkg/instrumentation/python_test.go b/pkg/instrumentation/python_test.go index 910a35ba61..716f21fb30 100644 --- a/pkg/instrumentation/python_test.go +++ b/pkg/instrumentation/python_test.go @@ -78,11 +78,19 @@ func TestInjectPythonSDK(t *testing.T) { }, { Name: "OTEL_TRACES_EXPORTER", - Value: "otlp_proto_http", + Value: "otlp", + }, + { + Name: "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL", + Value: "http/protobuf", }, { Name: "OTEL_METRICS_EXPORTER", - Value: "none", + Value: "otlp", + }, + { + Name: "OTEL_EXPORTER_OTLP_METRICS_PROTOCOL", + Value: "http/protobuf", }, }, }, @@ -144,11 +152,19 @@ func TestInjectPythonSDK(t *testing.T) { }, { Name: "OTEL_TRACES_EXPORTER", - Value: "otlp_proto_http", + Value: "otlp", + }, + { + Name: "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL", + Value: "http/protobuf", }, { Name: "OTEL_METRICS_EXPORTER", - Value: "none", + Value: "otlp", + }, + { + Name: "OTEL_EXPORTER_OTLP_METRICS_PROTOCOL", + Value: "http/protobuf", }, }, }, @@ -212,9 +228,17 @@ func TestInjectPythonSDK(t *testing.T) { Name: "PYTHONPATH", Value: fmt.Sprintf("%s:%s", pythonPathPrefix, pythonPathSuffix), }, + { + Name: "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL", + Value: "http/protobuf", + }, { Name: "OTEL_METRICS_EXPORTER", - Value: "none", + Value: "otlp", + }, + { + Name: "OTEL_EXPORTER_OTLP_METRICS_PROTOCOL", + Value: "http/protobuf", }, }, }, @@ -280,7 +304,15 @@ func TestInjectPythonSDK(t *testing.T) { }, { Name: "OTEL_TRACES_EXPORTER", - Value: "otlp_proto_http", + Value: "otlp", + }, + { + Name: "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL", + Value: "http/protobuf", + }, + { + Name: "OTEL_EXPORTER_OTLP_METRICS_PROTOCOL", + Value: "http/protobuf", }, }, }, diff --git a/pkg/instrumentation/sdk_test.go b/pkg/instrumentation/sdk_test.go index 077b0f34df..24e457ce76 100644 --- a/pkg/instrumentation/sdk_test.go +++ b/pkg/instrumentation/sdk_test.go @@ -634,11 +634,19 @@ func TestInjectPython(t *testing.T) { }, { Name: "OTEL_TRACES_EXPORTER", - Value: "otlp_proto_http", + Value: "otlp", + }, + { + Name: "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL", + Value: "http/protobuf", }, { Name: "OTEL_METRICS_EXPORTER", - Value: "none", + Value: "otlp", + }, + { + Name: "OTEL_EXPORTER_OTLP_METRICS_PROTOCOL", + Value: "http/protobuf", }, { Name: "OTEL_SERVICE_NAME", diff --git a/tests/e2e/instrumentation-python-multicontainer/01-assert.yaml b/tests/e2e/instrumentation-python-multicontainer/01-assert.yaml index 41d2a13ea6..280312a896 100644 --- a/tests/e2e/instrumentation-python-multicontainer/01-assert.yaml +++ b/tests/e2e/instrumentation-python-multicontainer/01-assert.yaml @@ -14,9 +14,13 @@ spec: - name: PYTHONPATH value: /otel-auto-instrumentation/opentelemetry/instrumentation/auto_instrumentation:/otel-auto-instrumentation - name: OTEL_TRACES_EXPORTER - value: otlp_proto_http + value: otlp + - name: OTEL_EXPORTER_OTLP_TRACES_PROTOCOL + value: http/protobuf - name: OTEL_METRICS_EXPORTER - value: none + value: otlp + - name: OTEL_EXPORTER_OTLP_METRICS_PROTOCOL + value: http/protobuf - name: OTEL_EXPORTER_OTLP_ENDPOINT value: http://localhost:4317 - name: OTEL_EXPORTER_OTLP_TIMEOUT @@ -43,9 +47,13 @@ spec: - name: PYTHONPATH value: /otel-auto-instrumentation/opentelemetry/instrumentation/auto_instrumentation:/otel-auto-instrumentation - name: OTEL_TRACES_EXPORTER - value: otlp_proto_http + value: otlp + - name: OTEL_EXPORTER_OTLP_TRACES_PROTOCOL + value: http/protobuf - name: OTEL_METRICS_EXPORTER - value: none + value: otlp + - name: OTEL_EXPORTER_OTLP_METRICS_PROTOCOL + value: http/protobuf - name: OTEL_EXPORTER_OTLP_ENDPOINT value: http://localhost:4317 - name: OTEL_EXPORTER_OTLP_TIMEOUT diff --git a/tests/e2e/instrumentation-python-multicontainer/02-assert.yaml b/tests/e2e/instrumentation-python-multicontainer/02-assert.yaml index 3bfcbfcc35..24e3f7d1e4 100644 --- a/tests/e2e/instrumentation-python-multicontainer/02-assert.yaml +++ b/tests/e2e/instrumentation-python-multicontainer/02-assert.yaml @@ -17,9 +17,13 @@ spec: - name: PYTHONPATH value: /otel-auto-instrumentation/opentelemetry/instrumentation/auto_instrumentation:/otel-auto-instrumentation - name: OTEL_TRACES_EXPORTER - value: otlp_proto_http + value: otlp + - name: OTEL_EXPORTER_OTLP_TRACES_PROTOCOL + value: http/protobuf - name: OTEL_METRICS_EXPORTER - value: none + value: otlp + - name: OTEL_EXPORTER_OTLP_METRICS_PROTOCOL + value: http/protobuf - name: OTEL_EXPORTER_OTLP_ENDPOINT value: http://localhost:4317 - name: OTEL_EXPORTER_OTLP_TIMEOUT diff --git a/tests/e2e/instrumentation-python/00-install-instrumentation.yaml b/tests/e2e/instrumentation-python/00-install-instrumentation.yaml index ab4bd669c9..a2b7d65a2d 100644 --- a/tests/e2e/instrumentation-python/00-install-instrumentation.yaml +++ b/tests/e2e/instrumentation-python/00-install-instrumentation.yaml @@ -25,6 +25,6 @@ spec: - name: OTEL_LOG_LEVEL value: "debug" - name: OTEL_TRACES_EXPORTER - value: otlp_proto_http + value: otlp - name: OTEL_EXPORTER_OTLP_ENDPOINT - value: http://localhost:4317 + value: http://localhost:4318 diff --git a/tests/e2e/instrumentation-python/01-assert.yaml b/tests/e2e/instrumentation-python/01-assert.yaml index a1eb66123c..4b7c122ae0 100644 --- a/tests/e2e/instrumentation-python/01-assert.yaml +++ b/tests/e2e/instrumentation-python/01-assert.yaml @@ -13,13 +13,17 @@ spec: - name: OTEL_LOG_LEVEL value: "debug" - name: OTEL_TRACES_EXPORTER - value: otlp_proto_http + value: otlp - name: OTEL_EXPORTER_OTLP_ENDPOINT - value: http://localhost:4317 + value: http://localhost:4318 - name: PYTHONPATH value: "/otel-auto-instrumentation/opentelemetry/instrumentation/auto_instrumentation:/otel-auto-instrumentation" + - name: OTEL_EXPORTER_OTLP_TRACES_PROTOCOL + value: http/protobuf - name: OTEL_METRICS_EXPORTER - value: none + value: otlp + - name: OTEL_EXPORTER_OTLP_METRICS_PROTOCOL + value: http/protobuf - name: OTEL_EXPORTER_OTLP_TIMEOUT value: "20" - name: OTEL_TRACES_SAMPLER