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

Update Python auto-instrumentation injection #962

Closed
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ When using sidecar mode the OpenTelemetry collector container will have the envi

The operator can inject and configure OpenTelemetry auto-instrumentation libraries. Currently Java, NodeJS and Python are supported.

Each auto-instrumentation supports different exporters. Make sure your endpoint is configured properly:
mat-rumian marked this conversation as resolved.
Show resolved Hide resolved
* Java - by default `OTLP gRPC exporter` is used (default port 4317). To change configuration please see [OT Java Auto-Instrumentation](https://github.com/open-telemetry/opentelemetry-java/blob/main/sdk-extensions/autoconfigure/README.md#exporters)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the list, however, what are the implications for the user? We should document what value of spec.exporter.endpoint should be set for each language.

Then if the exporter endpoint differs per language how can the CR be configured for multiple languages?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added little bit about Instrumentation resource and some information about each supported auto-instrumentation. I think it will make easier for end user to run it.

* NodeJS - only [OTLP gRPC exporter](https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/exporter-trace-otlp-grpc) is supported (default port 4317)
* Python - only [OTLP Proto HTTP exporter](https://github.com/open-telemetry/opentelemetry-python/tree/main/exporter/opentelemetry-exporter-otlp-proto-http) is supported (default port 4318)
mat-rumian marked this conversation as resolved.
Show resolved Hide resolved

To use auto-instrumentation, configure an `Instrumentation` resource with the configuration for the SDK and instrumentation.

```yaml
Expand Down
4 changes: 4 additions & 0 deletions pkg/instrumentation/podmutator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,10 @@ func TestMutatePod(t *testing.T) {
Name: "PYTHONPATH",
Value: fmt.Sprintf("%s:%s", pythonPathPrefix, pythonPathSuffix),
},
{
Name: "OTEL_METRICS_EXPORTER",
Value: "otlp_proto_http",
},
{
Name: "OTEL_EXPORTER_OTLP_TIMEOUT",
Value: "20",
Expand Down
21 changes: 16 additions & 5 deletions pkg/instrumentation/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ 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"
envValOtelHttpExporter = "otlp_proto_http"
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 @@ -64,7 +66,16 @@ func injectPythonSDK(logger logr.Logger, pythonSpec v1alpha1.Python, pod corev1.
if idx == -1 {
container.Env = append(container.Env, corev1.EnvVar{
Name: envOtelTracesExporter,
Value: "otlp_proto_http",
Value: envValOtelHttpExporter,
})
}

// 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: envValOtelHttpExporter,
})
}

Expand Down
99 changes: 88 additions & 11 deletions pkg/instrumentation/python_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,16 @@ func TestInjectPythonSDK(t *testing.T) {
},
Env: []corev1.EnvVar{
{
Name: "PYTHONPATH",
Name: envPythonPath,
Value: fmt.Sprintf("%s:%s", pythonPathPrefix, pythonPathSuffix),
},
{
Name: "OTEL_TRACES_EXPORTER",
Value: "otlp_proto_http",
Name: envOtelTracesExporter,
Value: envValOtelHttpExporter,
},
{
Name: envOtelMetricsExporter,
Value: envValOtelHttpExporter,
},
},
},
Expand All @@ -95,7 +99,7 @@ func TestInjectPythonSDK(t *testing.T) {
{
Env: []corev1.EnvVar{
{
Name: "PYTHONPATH",
Name: envPythonPath,
Value: "/foo:/bar",
},
},
Expand Down Expand Up @@ -138,8 +142,12 @@ func TestInjectPythonSDK(t *testing.T) {
Value: fmt.Sprintf("%s:%s:%s", pythonPathPrefix, "/foo:/bar", pythonPathSuffix),
},
{
Name: "OTEL_TRACES_EXPORTER",
Value: "otlp_proto_http",
Name: envOtelTracesExporter,
Value: envValOtelHttpExporter,
},
{
Name: envOtelMetricsExporter,
Value: envValOtelHttpExporter,
},
},
},
Expand All @@ -156,7 +164,7 @@ func TestInjectPythonSDK(t *testing.T) {
{
Env: []corev1.EnvVar{
{
Name: "OTEL_TRACES_EXPORTER",
Name: envOtelTracesExporter,
Value: "zipkin",
},
},
Expand Down Expand Up @@ -195,13 +203,82 @@ func TestInjectPythonSDK(t *testing.T) {
},
Env: []corev1.EnvVar{
{
Name: "OTEL_TRACES_EXPORTER",
Name: envOtelTracesExporter,
Value: "zipkin",
},
{
Name: "PYTHONPATH",
Name: envPythonPath,
Value: fmt.Sprintf("%s:%s", pythonPathPrefix, pythonPathSuffix),
},
{
Name: envOtelMetricsExporter,
Value: envValOtelHttpExporter,
},
},
},
},
},
},
},
{
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: envOtelMetricsExporter,
Value: "zipkin",
},
},
},
},
},
},
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: envOtelMetricsExporter,
Value: "zipkin",
},
{
Name: envPythonPath,
Value: fmt.Sprintf("%s:%s", pythonPathPrefix, pythonPathSuffix),
},
{
Name: envOtelTracesExporter,
Value: envValOtelHttpExporter,
},
},
},
},
Expand All @@ -217,7 +294,7 @@ func TestInjectPythonSDK(t *testing.T) {
{
Env: []corev1.EnvVar{
{
Name: "PYTHONPATH",
Name: envPythonPath,
ValueFrom: &corev1.EnvVarSource{},
},
},
Expand All @@ -231,7 +308,7 @@ func TestInjectPythonSDK(t *testing.T) {
{
Env: []corev1.EnvVar{
{
Name: "PYTHONPATH",
Name: envPythonPath,
ValueFrom: &corev1.EnvVarSource{},
},
},
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: "otlp_proto_http",
},
{
Name: "OTEL_SERVICE_NAME",
Value: "app",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: otlp_proto_http
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: http://localhost:4317
- name: OTEL_EXPORTER_OTLP_TIMEOUT
Expand Down Expand Up @@ -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: otlp_proto_http
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: http://localhost:4317
- name: OTEL_EXPORTER_OTLP_TIMEOUT
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/instrumentation-python/01-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: otlp_proto_http
- name: OTEL_EXPORTER_OTLP_TIMEOUT
value: "20"
- name: OTEL_TRACES_SAMPLER
Expand Down
2 changes: 1 addition & 1 deletion versions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ autoinstrumentation-nodejs=0.27.0

# Represents the current release of Python instrumentation.
# Should match value in autoinstrumentation/python/requirements.txt
autoinstrumentation-python=0.30b1
autoinstrumentation-python=0.32b0