Skip to content

Commit

Permalink
Update default python exporters to use OTLP (#1328)
Browse files Browse the repository at this point in the history
* Update default python metrics exporter

* Update sdk test

* Update python to use `otlp` and OTEL_EXPORTER_OTLP_*_PROTOCOL

* add changelog

* Update e2e tests

* Update how protocol is set
  • Loading branch information
TylerHelmuth committed Jan 4, 2023
1 parent 1c4e2c7 commit fde6b95
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 36 deletions.
16 changes: 16 additions & 0 deletions .chloggen/update-python-metrics-exporter.yaml
Original file line number Diff line number Diff line change
@@ -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:
20 changes: 14 additions & 6 deletions pkg/instrumentation/podmutator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
},
Expand Down Expand Up @@ -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",
Expand Down
39 changes: 28 additions & 11 deletions pkg/instrumentation/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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",
})
}

Expand Down
44 changes: 38 additions & 6 deletions pkg/instrumentation/python_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
},
Expand Down Expand Up @@ -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",
},
},
},
Expand Down Expand Up @@ -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",
},
},
},
Expand Down Expand Up @@ -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",
},
},
},
Expand Down
12 changes: 10 additions & 2 deletions pkg/instrumentation/sdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 12 additions & 4 deletions tests/e2e/instrumentation-python-multicontainer/01-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 7 additions & 3 deletions tests/e2e/instrumentation-python/01-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fde6b95

Please sign in to comment.