Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set OTEL_METRICS_EXPORTER to none to prevent using the default value #1149

Merged
merged 4 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions pkg/instrumentation/podmutator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
21 changes: 17 additions & 4 deletions pkg/instrumentation/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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",
Expand Down
77 changes: 77 additions & 0 deletions pkg/instrumentation/python_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ func TestInjectPythonSDK(t *testing.T) {
Name: "OTEL_TRACES_EXPORTER",
Value: "otlp_proto_http",
},
{
Name: "OTEL_METRICS_EXPORTER",
Value: "none",
},
},
},
},
Expand Down Expand Up @@ -141,6 +145,10 @@ func TestInjectPythonSDK(t *testing.T) {
Name: "OTEL_TRACES_EXPORTER",
Value: "otlp_proto_http",
},
{
Name: "OTEL_METRICS_EXPORTER",
Value: "none",
},
},
},
},
Expand Down Expand Up @@ -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",
},
},
},
},
Expand Down
4 changes: 4 additions & 0 deletions pkg/instrumentation/sdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down