@@ -8,13 +8,13 @@ import (
88 "fmt"
99 "os"
1010
11- "k8s.io/apimachinery/pkg/api/resource"
12-
1311 corev1 "k8s.io/api/core/v1"
12+ "k8s.io/apimachinery/pkg/api/resource"
1413 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1514
1615 "github.com/aws/amazon-cloudwatch-agent-operator/apis/v1alpha1"
1716 "github.com/aws/amazon-cloudwatch-agent-operator/internal/manifests/collector/adapters"
17+ "github.com/aws/amazon-cloudwatch-agent-operator/pkg/instrumentation/jmx"
1818)
1919
2020const (
@@ -50,7 +50,7 @@ func getInstrumentationConfigForResource(langStr string, resourceStr string) cor
5050 return instrumentationConfigForResource
5151}
5252
53- func getDefaultInstrumentation (agentConfig * adapters.CwaConfig , isWindowsPod bool ) (* v1alpha1.Instrumentation , error ) {
53+ func getDefaultInstrumentation (agentConfig * adapters.CwaConfig , additionalEnvs map [ Type ] map [ string ] string , isWindowsPod bool ) (* v1alpha1.Instrumentation , error ) {
5454 javaInstrumentationImage , ok := os .LookupEnv ("AUTO_INSTRUMENTATION_JAVA" )
5555 if ! ok {
5656 return nil , errors .New ("unable to determine java instrumentation image" )
@@ -103,18 +103,7 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo
103103 },
104104 Java : v1alpha1.Java {
105105 Image : javaInstrumentationImage ,
106- Env : []corev1.EnvVar {
107- {Name : "OTEL_AWS_APP_SIGNALS_ENABLED" , Value : "true" }, //TODO: remove in favor of new name once safe
108- {Name : "OTEL_AWS_APPLICATION_SIGNALS_ENABLED" , Value : "true" },
109- {Name : "OTEL_TRACES_SAMPLER_ARG" , Value : fmt .Sprintf ("endpoint=%s://%s:2000" , http , cloudwatchAgentServiceEndpoint )},
110- {Name : "OTEL_TRACES_SAMPLER" , Value : "xray" },
111- {Name : "OTEL_EXPORTER_OTLP_PROTOCOL" , Value : "http/protobuf" },
112- {Name : "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" , Value : fmt .Sprintf ("%s://%s:4316/v1/traces" , exporterPrefix , cloudwatchAgentServiceEndpoint )},
113- {Name : "OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT" , Value : fmt .Sprintf ("%s://%s:4316/v1/metrics" , exporterPrefix , cloudwatchAgentServiceEndpoint )}, //TODO: remove in favor of new name once safe
114- {Name : "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT" , Value : fmt .Sprintf ("%s://%s:4316/v1/metrics" , exporterPrefix , cloudwatchAgentServiceEndpoint )},
115- {Name : "OTEL_METRICS_EXPORTER" , Value : "none" },
116- {Name : "OTEL_LOGS_EXPORTER" , Value : "none" },
117- },
106+ Env : getJavaEnvs (cloudwatchAgentServiceEndpoint , exporterPrefix , additionalEnvs [TypeJava ]),
118107 Resources : corev1.ResourceRequirements {
119108 Limits : getInstrumentationConfigForResource (java , limit ),
120109 Requests : getInstrumentationConfigForResource (java , request ),
@@ -182,3 +171,38 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo
182171 },
183172 }, nil
184173}
174+
175+ func getJavaEnvs (cloudwatchAgentServiceEndpoint , exporterPrefix string , additionalEnvs map [string ]string ) []corev1.EnvVar {
176+ envs := []corev1.EnvVar {
177+ {Name : "OTEL_AWS_APP_SIGNALS_ENABLED" , Value : "true" }, //TODO: remove in favor of new name once safe
178+ {Name : "OTEL_AWS_APPLICATION_SIGNALS_ENABLED" , Value : "true" },
179+ {Name : "OTEL_TRACES_SAMPLER_ARG" , Value : fmt .Sprintf ("endpoint=%s://%s:2000" , http , cloudwatchAgentServiceEndpoint )},
180+ {Name : "OTEL_TRACES_SAMPLER" , Value : "xray" },
181+ {Name : "OTEL_EXPORTER_OTLP_PROTOCOL" , Value : "http/protobuf" },
182+ {Name : "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" , Value : fmt .Sprintf ("%s://%s:4316/v1/traces" , exporterPrefix , cloudwatchAgentServiceEndpoint )},
183+ {Name : "OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT" , Value : fmt .Sprintf ("%s://%s:4316/v1/metrics" , exporterPrefix , cloudwatchAgentServiceEndpoint )}, //TODO: remove in favor of new name once safe
184+ {Name : "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT" , Value : fmt .Sprintf ("%s://%s:4316/v1/metrics" , exporterPrefix , cloudwatchAgentServiceEndpoint )},
185+ }
186+ var jmxEnvs []corev1.EnvVar
187+ if targetSystems , ok := additionalEnvs [jmx .EnvTargetSystem ]; ok {
188+ jmxEnvs = []corev1.EnvVar {
189+ {Name : "OTEL_EXPORTER_OTLP_METRICS_ENDPOINT" , Value : fmt .Sprintf ("%s://%s:4314/v1/metrics" , http , cloudwatchAgentServiceEndpoint )},
190+ {Name : "OTEL_INSTRUMENTATION_RUNTIME_TELEMETRY_ENABLED" , Value : "false" },
191+ {Name : "OTEL_INSTRUMENTATION_COMMON_DEFAULT_ENABLED" , Value : "false" },
192+ {Name : "OTEL_JMX_ENABLED" , Value : "true" },
193+ {Name : "OTEL_JMX_TARGET_SYSTEM" , Value : targetSystems },
194+ {Name : "OTEL_EXPERIMENTAL_METRICS_VIEW_CONFIG" , Value : "classpath:/jmx/view.yaml" },
195+ }
196+ }
197+ if len (jmxEnvs ) == 0 {
198+ envs = append (
199+ envs ,
200+ corev1.EnvVar {Name : "OTEL_METRICS_EXPORTER" , Value : "none" },
201+ corev1.EnvVar {Name : "OTEL_LOGS_EXPORTER" , Value : "none" },
202+ )
203+ } else {
204+ envs = append (envs , corev1.EnvVar {Name : "OTEL_LOGS_EXPORTER" , Value : "none" })
205+ envs = append (envs , jmxEnvs ... )
206+ }
207+ return envs
208+ }
0 commit comments