diff --git a/bundle/manifests/opentelemetry.io_instrumentations.yaml b/bundle/manifests/opentelemetry.io_instrumentations.yaml index 7b513cae68..13321f7c89 100644 --- a/bundle/manifests/opentelemetry.io_instrumentations.yaml +++ b/bundle/manifests/opentelemetry.io_instrumentations.yaml @@ -43,7 +43,11 @@ spec: SDK and instrumentation. properties: env: - description: Env defines env vars. + description: 'Env defines common env vars. There are four layers for + env vars'' definitions and the precedence order is: `original container + env vars` > `language specific env vars` > `common env vars` > `instrument + spec configs'' vars`. If the former var had been defined, then the + other vars would be ignored.' items: description: EnvVar represents an environment variable present in a Container. @@ -158,7 +162,11 @@ spec: description: Java defines configuration for java auto-instrumentation. properties: env: - description: Env defines env vars. + description: 'Env defines java specific env vars. There are four + layers for env vars'' definitions and the precedence order is: + `original container env vars` > `language specific env vars` + > `common env vars` > `instrument spec configs'' vars`. If the + former var had been defined, then the other vars would be ignored.' items: description: EnvVar represents an environment variable present in a Container. @@ -276,7 +284,11 @@ spec: description: NodeJS defines configuration for nodejs auto-instrumentation. properties: env: - description: Env defines env vars. + description: 'Env defines nodejs specific env vars. There are + four layers for env vars'' definitions and the precedence order + is: `original container env vars` > `language specific env vars` + > `common env vars` > `instrument spec configs'' vars`. If the + former var had been defined, then the other vars would be ignored.' items: description: EnvVar represents an environment variable present in a Container. @@ -409,7 +421,11 @@ spec: description: Python defines configuration for python auto-instrumentation. properties: env: - description: Env defines env vars. + description: 'Env defines python specific env vars. There are + four layers for env vars'' definitions and the precedence order + is: `original container env vars` > `language specific env vars` + > `common env vars` > `instrument spec configs'' vars`. If the + former var had been defined, then the other vars would be ignored.' items: description: EnvVar represents an environment variable present in a Container. diff --git a/pkg/instrumentation/podmutator_test.go b/pkg/instrumentation/podmutator_test.go index 2512fd832d..aadf3723b2 100644 --- a/pkg/instrumentation/podmutator_test.go +++ b/pkg/instrumentation/podmutator_test.go @@ -53,7 +53,40 @@ func TestMutatePod(t *testing.T) { Namespace: "javaagent", }, Spec: v1alpha1.InstrumentationSpec{ - Java: v1alpha1.Java{}, + Java: v1alpha1.Java{ + Env: []corev1.EnvVar{ + { + Name: "OTEL_JAVAAGENT_DEBUG", + Value: "true", + }, + { + Name: "OTEL_INSTRUMENTATION_JDBC_ENABLED", + Value: "false", + }, + }, + }, + Env: []corev1.EnvVar { + { + Name: "OTEL_TRACES_EXPORTER", + Value: "otlp", + }, + { + Name: "OTEL_EXPORTER_OTLP_ENDPOINT", + Value: "http://localhost:4317", + }, + { + Name: "OTEL_EXPORTER_OTLP_TIMEOUT", + Value: "20", + }, + { + Name: "OTEL_TRACES_SAMPLER", + Value: "parentbased_traceidratio", + }, + { + Name: "OTEL_TRACES_SAMPLER_ARG", + Value: "0.85", + }, + }, Exporter: v1alpha1.Exporter{ Endpoint: "http://collector:12345", }, @@ -103,12 +136,40 @@ func TestMutatePod(t *testing.T) { Name: "app", Env: []corev1.EnvVar{ { - Name: "OTEL_SERVICE_NAME", - Value: "app", + Name: "OTEL_JAVAAGENT_DEBUG", + Value: "true", + }, + { + Name: "OTEL_INSTRUMENTATION_JDBC_ENABLED", + Value: "false", + }, + { + Name: "JAVA_TOOL_OPTIONS", + Value: javaJVMArgument, + }, + { + Name: "OTEL_TRACES_EXPORTER", + Value: "otlp", }, { Name: "OTEL_EXPORTER_OTLP_ENDPOINT", - Value: "http://collector:12345", + Value: "http://localhost:4317", + }, + { + Name: "OTEL_EXPORTER_OTLP_TIMEOUT", + Value: "20", + }, + { + Name: "OTEL_TRACES_SAMPLER", + Value: "parentbased_traceidratio", + }, + { + Name: "OTEL_TRACES_SAMPLER_ARG", + Value: "0.85", + }, + { + Name: "OTEL_SERVICE_NAME", + Value: "app", }, { Name: "OTEL_RESOURCE_ATTRIBUTES_POD_NAME", @@ -130,10 +191,6 @@ func TestMutatePod(t *testing.T) { Name: "OTEL_RESOURCE_ATTRIBUTES", Value: "k8s.container.name=app,k8s.namespace.name=javaagent,k8s.node.name=$(OTEL_RESOURCE_ATTRIBUTES_NODE_NAME),k8s.pod.name=$(OTEL_RESOURCE_ATTRIBUTES_POD_NAME)", }, - { - Name: "JAVA_TOOL_OPTIONS", - Value: javaJVMArgument, - }, }, VolumeMounts: []corev1.VolumeMount{ { @@ -161,6 +218,34 @@ func TestMutatePod(t *testing.T) { Spec: v1alpha1.InstrumentationSpec{ NodeJS: v1alpha1.NodeJS{ Image: "otel/nodejs:1", + Env: []corev1.EnvVar{ + { + Name: "OTEL_NODEJS_DEBUG", + Value: "true", + }, + }, + }, + Env: []corev1.EnvVar { + { + Name: "OTEL_TRACES_EXPORTER", + Value: "otlp", + }, + { + Name: "OTEL_EXPORTER_OTLP_ENDPOINT", + Value: "http://localhost:4317", + }, + { + Name: "OTEL_EXPORTER_OTLP_TIMEOUT", + Value: "20", + }, + { + Name: "OTEL_TRACES_SAMPLER", + Value: "parentbased_traceidratio", + }, + { + Name: "OTEL_TRACES_SAMPLER_ARG", + Value: "0.85", + }, }, Exporter: v1alpha1.Exporter{ Endpoint: "http://collector:12345", @@ -212,12 +297,36 @@ func TestMutatePod(t *testing.T) { Name: "app", Env: []corev1.EnvVar{ { - Name: "OTEL_SERVICE_NAME", - Value: "app", + Name: "OTEL_NODEJS_DEBUG", + Value: "true", + }, + { + Name: "NODE_OPTIONS", + Value: nodeRequireArgument, + }, + { + Name: "OTEL_TRACES_EXPORTER", + Value: "otlp", }, { Name: "OTEL_EXPORTER_OTLP_ENDPOINT", - Value: "http://collector:12345", + Value: "http://localhost:4317", + }, + { + Name: "OTEL_EXPORTER_OTLP_TIMEOUT", + Value: "20", + }, + { + Name: "OTEL_TRACES_SAMPLER", + Value: "parentbased_traceidratio", + }, + { + Name: "OTEL_TRACES_SAMPLER_ARG", + Value: "0.85", + }, + { + Name: "OTEL_SERVICE_NAME", + Value: "app", }, { Name: "OTEL_RESOURCE_ATTRIBUTES_POD_NAME", @@ -239,10 +348,6 @@ func TestMutatePod(t *testing.T) { Name: "OTEL_RESOURCE_ATTRIBUTES", Value: "k8s.container.name=app,k8s.namespace.name=nodejs,k8s.node.name=$(OTEL_RESOURCE_ATTRIBUTES_NODE_NAME),k8s.pod.name=$(OTEL_RESOURCE_ATTRIBUTES_POD_NAME)", }, - { - Name: "NODE_OPTIONS", - Value: nodeRequireArgument, - }, }, VolumeMounts: []corev1.VolumeMount{ { @@ -270,10 +375,38 @@ func TestMutatePod(t *testing.T) { Spec: v1alpha1.InstrumentationSpec{ Python: v1alpha1.Python{ Image: "otel/python:1", + Env: []corev1.EnvVar{ + { + Name: "OTEL_LOG_LEVEL", + Value: "debug", + }, + { + Name: "OTEL_TRACES_EXPORTER", + Value: "otlp_proto_http", + }, + { + Name: "OTEL_EXPORTER_OTLP_ENDPOINT", + Value: "http://localhost:4317", + }, + }, }, Exporter: v1alpha1.Exporter{ Endpoint: "http://collector:12345", }, + Env: []corev1.EnvVar{ + { + Name: "OTEL_EXPORTER_OTLP_TIMEOUT", + Value: "20", + }, + { + Name: "OTEL_TRACES_SAMPLER", + Value: "parentbased_traceidratio", + }, + { + Name: "OTEL_TRACES_SAMPLER_ARG", + Value: "0.85", + }, + }, }, }, pod: corev1.Pod{ @@ -321,12 +454,36 @@ func TestMutatePod(t *testing.T) { Name: "app", Env: []corev1.EnvVar{ { - Name: "OTEL_SERVICE_NAME", - Value: "app", + Name: "OTEL_LOG_LEVEL", + Value: "debug", + }, + { + Name: "OTEL_TRACES_EXPORTER", + Value: "otlp_proto_http", }, { Name: "OTEL_EXPORTER_OTLP_ENDPOINT", - Value: "http://collector:12345", + Value: "http://localhost:4317", + }, + { + Name: "PYTHONPATH", + Value: fmt.Sprintf("%s:%s", pythonPathPrefix, pythonPathSuffix), + }, + { + Name: "OTEL_EXPORTER_OTLP_TIMEOUT", + Value: "20", + }, + { + Name: "OTEL_TRACES_SAMPLER", + Value: "parentbased_traceidratio", + }, + { + Name: "OTEL_TRACES_SAMPLER_ARG", + Value: "0.85", + }, + { + Name: "OTEL_SERVICE_NAME", + Value: "app", }, { Name: "OTEL_RESOURCE_ATTRIBUTES_POD_NAME", @@ -348,14 +505,6 @@ func TestMutatePod(t *testing.T) { Name: "OTEL_RESOURCE_ATTRIBUTES", Value: "k8s.container.name=app,k8s.namespace.name=python,k8s.node.name=$(OTEL_RESOURCE_ATTRIBUTES_NODE_NAME),k8s.pod.name=$(OTEL_RESOURCE_ATTRIBUTES_POD_NAME)", }, - { - Name: "PYTHONPATH", - Value: fmt.Sprintf("%s:%s", pythonPathPrefix, pythonPathSuffix), - }, - { - Name: "OTEL_TRACES_EXPORTER", - Value: "otlp_proto_http", - }, }, VolumeMounts: []corev1.VolumeMount{ { diff --git a/pkg/instrumentation/sdk_test.go b/pkg/instrumentation/sdk_test.go index c667e73619..cd31726c1d 100644 --- a/pkg/instrumentation/sdk_test.go +++ b/pkg/instrumentation/sdk_test.go @@ -431,6 +431,10 @@ func TestInjectJava(t *testing.T) { }, }, Env: []corev1.EnvVar{ + { + Name: "JAVA_TOOL_OPTIONS", + Value: javaJVMArgument, + }, { Name: "OTEL_SERVICE_NAME", Value: "app", @@ -459,10 +463,6 @@ func TestInjectJava(t *testing.T) { Name: "OTEL_RESOURCE_ATTRIBUTES", Value: "k8s.container.name=app,k8s.node.name=$(OTEL_RESOURCE_ATTRIBUTES_NODE_NAME),k8s.pod.name=$(OTEL_RESOURCE_ATTRIBUTES_POD_NAME)", }, - { - Name: "JAVA_TOOL_OPTIONS", - Value: javaJVMArgument, - }, }, }, },