Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Commit

Permalink
collect image id (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
LironKS authored Aug 9, 2023
1 parent f32c44f commit f80a700
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/instrumentation/nodejs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
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 @@ -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",
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 @@ -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",
Expand Down

0 comments on commit f80a700

Please sign in to comment.