diff --git a/pkg/instrumentation/nodejs.go b/pkg/instrumentation/nodejs.go index 66436cd9a3..05c7a98893 100644 --- a/pkg/instrumentation/nodejs.go +++ b/pkg/instrumentation/nodejs.go @@ -24,6 +24,7 @@ const ( envNodeOptions = "NODE_OPTIONS" nodeRequireArgument = " --require /otel-auto-instrumentation/autoinstrumentation.js" envImageName = "HS_IMAGE_NAME" + envImageId = "HS_IMAGE_ID" ) func injectEnvVarIfNotExists(container *corev1.Container, envVarName, envVarValue string) { @@ -63,6 +64,10 @@ func injectNodeJSSDK(nodeJSSpec v1alpha1.NodeJS, pod corev1.Pod, index int) (cor container.Env[idx].Value = container.Env[idx].Value + nodeRequireArgument } injectEnvVarIfNotExists(container, envImageName, container.Image) + if len(pod.Status.ContainerStatuses) >= index+1 { + containerStatus := pod.Status.ContainerStatuses[index] + injectEnvVarIfNotExists(container, envImageId, containerStatus.ImageID) + } container.VolumeMounts = append(container.VolumeMounts, corev1.VolumeMount{ Name: volumeName, diff --git a/pkg/instrumentation/podmutator_test.go b/pkg/instrumentation/podmutator_test.go index f813a07f22..f646ab0597 100644 --- a/pkg/instrumentation/podmutator_test.go +++ b/pkg/instrumentation/podmutator_test.go @@ -328,6 +328,10 @@ func TestMutatePod(t *testing.T) { Name: "HS_IMAGE_NAME", Value: "", }, + { + Name: "HS_IMAGE_ID", + Value: "", + }, { Name: "OTEL_TRACES_EXPORTER", Value: "otlp", diff --git a/pkg/instrumentation/sdk_test.go b/pkg/instrumentation/sdk_test.go index e371f3c240..1d2df6f80f 100644 --- a/pkg/instrumentation/sdk_test.go +++ b/pkg/instrumentation/sdk_test.go @@ -537,6 +537,10 @@ func TestInjectNodeJS(t *testing.T) { Name: "HS_IMAGE_NAME", Value: "", }, + { + Name: "HS_IMAGE_ID", + Value: "", + }, { Name: "OTEL_SERVICE_NAME", Value: "app",