@@ -14,6 +14,7 @@ import (
1414
1515 "github.com/aws/amazon-cloudwatch-agent-operator/apis/v1alpha1"
1616 "github.com/aws/amazon-cloudwatch-agent-operator/internal/manifests/collector/adapters"
17+ "github.com/aws/amazon-cloudwatch-agent-operator/pkg/instrumentation/jmx"
1718)
1819
1920const (
@@ -49,7 +50,7 @@ func getInstrumentationConfigForResource(langStr string, resourceStr string) cor
4950 return instrumentationConfigForResource
5051}
5152
52- 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 ) {
5354 javaInstrumentationImage , ok := os .LookupEnv ("AUTO_INSTRUMENTATION_JAVA" )
5455 if ! ok {
5556 return nil , errors .New ("unable to determine java instrumentation image" )
@@ -76,9 +77,10 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo
7677
7778 // set protocol by checking cloudwatch agent config for tls setting
7879 exporterPrefix := http
79- if agentConfig != nil {
80- appSignalsConfig := agentConfig .GetApplicationSignalsConfig ()
81- if appSignalsConfig != nil && appSignalsConfig .TLS != nil {
80+ isApplicationSignalsEnabled := agentConfig != nil && agentConfig .GetApplicationSignalsConfig () != nil
81+
82+ if isApplicationSignalsEnabled {
83+ if agentConfig .GetApplicationSignalsConfig ().TLS != nil {
8284 exporterPrefix = https
8385 }
8486 }
@@ -102,77 +104,31 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo
102104 },
103105 Java : v1alpha1.Java {
104106 Image : javaInstrumentationImage ,
105- Env : []corev1.EnvVar {
106- {Name : "OTEL_AWS_APP_SIGNALS_ENABLED" , Value : "true" }, //TODO: remove in favor of new name once safe
107- {Name : "OTEL_AWS_APPLICATION_SIGNALS_ENABLED" , Value : "true" },
108- {Name : "OTEL_TRACES_SAMPLER_ARG" , Value : fmt .Sprintf ("endpoint=%s://%s:2000" , http , cloudwatchAgentServiceEndpoint )},
109- {Name : "OTEL_TRACES_SAMPLER" , Value : "xray" },
110- {Name : "OTEL_EXPORTER_OTLP_PROTOCOL" , Value : "http/protobuf" },
111- {Name : "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" , Value : fmt .Sprintf ("%s://%s:4316/v1/traces" , exporterPrefix , cloudwatchAgentServiceEndpoint )},
112- {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
113- {Name : "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT" , Value : fmt .Sprintf ("%s://%s:4316/v1/metrics" , exporterPrefix , cloudwatchAgentServiceEndpoint )},
114- {Name : "OTEL_METRICS_EXPORTER" , Value : "none" },
115- {Name : "OTEL_LOGS_EXPORTER" , Value : "none" },
116- },
107+ Env : getJavaEnvs (isApplicationSignalsEnabled , cloudwatchAgentServiceEndpoint , exporterPrefix , additionalEnvs [TypeJava ]),
117108 Resources : corev1.ResourceRequirements {
118109 Limits : getInstrumentationConfigForResource (java , limit ),
119110 Requests : getInstrumentationConfigForResource (java , request ),
120111 },
121112 },
122113 Python : v1alpha1.Python {
123114 Image : pythonInstrumentationImage ,
124- Env : []corev1.EnvVar {
125- {Name : "OTEL_AWS_APP_SIGNALS_ENABLED" , Value : "true" }, //TODO: remove in favor of new name once safe
126- {Name : "OTEL_AWS_APPLICATION_SIGNALS_ENABLED" , Value : "true" },
127- {Name : "OTEL_TRACES_SAMPLER_ARG" , Value : fmt .Sprintf ("endpoint=%s://%s:2000" , http , cloudwatchAgentServiceEndpoint )},
128- {Name : "OTEL_TRACES_SAMPLER" , Value : "xray" },
129- {Name : "OTEL_EXPORTER_OTLP_PROTOCOL" , Value : "http/protobuf" },
130- {Name : "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" , Value : fmt .Sprintf ("%s://%s:4316/v1/traces" , exporterPrefix , cloudwatchAgentServiceEndpoint )},
131- {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
132- {Name : "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT" , Value : fmt .Sprintf ("%s://%s:4316/v1/metrics" , exporterPrefix , cloudwatchAgentServiceEndpoint )},
133- {Name : "OTEL_METRICS_EXPORTER" , Value : "none" },
134- {Name : "OTEL_PYTHON_DISTRO" , Value : "aws_distro" },
135- {Name : "OTEL_PYTHON_CONFIGURATOR" , Value : "aws_configurator" },
136- {Name : "OTEL_LOGS_EXPORTER" , Value : "none" },
137- },
115+ Env : getPythonEnvs (isApplicationSignalsEnabled , cloudwatchAgentServiceEndpoint , exporterPrefix , additionalEnvs [TypePython ]),
138116 Resources : corev1.ResourceRequirements {
139117 Limits : getInstrumentationConfigForResource (python , limit ),
140118 Requests : getInstrumentationConfigForResource (python , request ),
141119 },
142120 },
143121 DotNet : v1alpha1.DotNet {
144122 Image : dotNetInstrumentationImage ,
145- Env : []corev1.EnvVar {
146- {Name : "OTEL_AWS_APPLICATION_SIGNALS_ENABLED" , Value : "true" },
147- {Name : "OTEL_TRACES_SAMPLER_ARG" , Value : fmt .Sprintf ("endpoint=%s://%s:2000" , http , cloudwatchAgentServiceEndpoint )},
148- {Name : "OTEL_TRACES_SAMPLER" , Value : "xray" },
149- {Name : "OTEL_EXPORTER_OTLP_PROTOCOL" , Value : "http/protobuf" },
150- {Name : "OTEL_EXPORTER_OTLP_ENDPOINT" , Value : fmt .Sprintf ("%s://%s:4316" , exporterPrefix , cloudwatchAgentServiceEndpoint )},
151- {Name : "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" , Value : fmt .Sprintf ("%s://%s:4316/v1/traces" , exporterPrefix , cloudwatchAgentServiceEndpoint )},
152- {Name : "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT" , Value : fmt .Sprintf ("%s://%s:4316/v1/metrics" , exporterPrefix , cloudwatchAgentServiceEndpoint )},
153- {Name : "OTEL_METRICS_EXPORTER" , Value : "none" },
154- {Name : "OTEL_DOTNET_DISTRO" , Value : "aws_distro" },
155- {Name : "OTEL_DOTNET_CONFIGURATOR" , Value : "aws_configurator" },
156- {Name : "OTEL_LOGS_EXPORTER" , Value : "none" },
157- {Name : "OTEL_DOTNET_AUTO_PLUGINS" , Value : "AWS.Distro.OpenTelemetry.AutoInstrumentation.Plugin, AWS.Distro.OpenTelemetry.AutoInstrumentation" },
158- },
123+ Env : getDotNetEnvs (isApplicationSignalsEnabled , cloudwatchAgentServiceEndpoint , exporterPrefix , additionalEnvs [TypeDotNet ]),
159124 Resources : corev1.ResourceRequirements {
160125 Limits : getInstrumentationConfigForResource (dotNet , limit ),
161126 Requests : getInstrumentationConfigForResource (dotNet , request ),
162127 },
163128 },
164129 NodeJS : v1alpha1.NodeJS {
165130 Image : nodeJSInstrumentationImage ,
166- Env : []corev1.EnvVar {
167- {Name : "OTEL_AWS_APPLICATION_SIGNALS_ENABLED" , Value : "true" },
168- {Name : "OTEL_TRACES_SAMPLER_ARG" , Value : fmt .Sprintf ("endpoint=%s://%s:2000" , exporterPrefix , cloudwatchAgentServiceEndpoint )},
169- {Name : "OTEL_TRACES_SAMPLER" , Value : "xray" },
170- {Name : "OTEL_EXPORTER_OTLP_PROTOCOL" , Value : "http/protobuf" },
171- {Name : "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" , Value : fmt .Sprintf ("%s://%s:4316/v1/traces" , exporterPrefix , cloudwatchAgentServiceEndpoint )},
172- {Name : "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT" , Value : fmt .Sprintf ("%s://%s:4316/v1/metrics" , exporterPrefix , cloudwatchAgentServiceEndpoint )},
173- {Name : "OTEL_METRICS_EXPORTER" , Value : "none" },
174- {Name : "OTEL_LOGS_EXPORTER" , Value : "none" },
175- },
131+ Env : getNodeJSEnvs (isApplicationSignalsEnabled , cloudwatchAgentServiceEndpoint , exporterPrefix , additionalEnvs [TypeDotNet ]),
176132 Resources : corev1.ResourceRequirements {
177133 Limits : getInstrumentationConfigForResource (nodeJS , limit ),
178134 Requests : getInstrumentationConfigForResource (nodeJS , request ),
@@ -181,3 +137,99 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo
181137 },
182138 }, nil
183139}
140+
141+ func getJavaEnvs (isAppSignalsEnabled bool , cloudwatchAgentServiceEndpoint , exporterPrefix string , additionalEnvs map [string ]string ) []corev1.EnvVar {
142+ envs := []corev1.EnvVar {
143+ {Name : "OTEL_EXPORTER_OTLP_PROTOCOL" , Value : "http/protobuf" },
144+ {Name : "OTEL_METRICS_EXPORTER" , Value : "none" },
145+ {Name : "OTEL_LOGS_EXPORTER" , Value : "none" },
146+ }
147+
148+ if isAppSignalsEnabled {
149+ appSignalsEnvs := []corev1.EnvVar {
150+ {Name : "OTEL_AWS_APP_SIGNALS_ENABLED" , Value : "true" }, //TODO: remove in favor of new name once safe
151+ {Name : "OTEL_AWS_APPLICATION_SIGNALS_ENABLED" , Value : "true" },
152+ {Name : "OTEL_TRACES_SAMPLER_ARG" , Value : fmt .Sprintf ("endpoint=%s://%s:2000" , http , cloudwatchAgentServiceEndpoint )},
153+ {Name : "OTEL_TRACES_SAMPLER" , Value : "xray" },
154+ {Name : "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" , Value : fmt .Sprintf ("%s://%s:4316/v1/traces" , exporterPrefix , cloudwatchAgentServiceEndpoint )},
155+ {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
156+ {Name : "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT" , Value : fmt .Sprintf ("%s://%s:4316/v1/metrics" , exporterPrefix , cloudwatchAgentServiceEndpoint )},
157+ }
158+ envs = append (envs , appSignalsEnvs ... )
159+ } else {
160+ envs = append (envs , corev1.EnvVar {
161+ Name : "OTEL_TRACES_EXPORTER" , Value : "none" ,
162+ })
163+ }
164+
165+ var jmxEnvs []corev1.EnvVar
166+ if targetSystems , ok := additionalEnvs [jmx .EnvTargetSystem ]; ok {
167+ jmxEnvs = []corev1.EnvVar {
168+ {Name : "OTEL_AWS_JMX_EXPORTER_METRICS_ENDPOINT" , Value : fmt .Sprintf ("%s://%s:4314/v1/metrics" , http , cloudwatchAgentServiceEndpoint )},
169+ {Name : "OTEL_JMX_TARGET_SYSTEM" , Value : targetSystems },
170+ }
171+ }
172+ if len (jmxEnvs ) != 0 {
173+ envs = append (envs , jmxEnvs ... )
174+ }
175+ return envs
176+ }
177+
178+ func getPythonEnvs (isAppSignalsEnabled bool , cloudwatchAgentServiceEndpoint , exporterPrefix string , additionalEnvs map [string ]string ) []corev1.EnvVar {
179+ var envs []corev1.EnvVar
180+ if isAppSignalsEnabled {
181+ envs = []corev1.EnvVar {
182+ {Name : "OTEL_AWS_APP_SIGNALS_ENABLED" , Value : "true" }, //TODO: remove in favor of new name once safe
183+ {Name : "OTEL_AWS_APPLICATION_SIGNALS_ENABLED" , Value : "true" },
184+ {Name : "OTEL_TRACES_SAMPLER_ARG" , Value : fmt .Sprintf ("endpoint=%s://%s:2000" , http , cloudwatchAgentServiceEndpoint )},
185+ {Name : "OTEL_TRACES_SAMPLER" , Value : "xray" },
186+ {Name : "OTEL_EXPORTER_OTLP_PROTOCOL" , Value : "http/protobuf" },
187+ {Name : "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" , Value : fmt .Sprintf ("%s://%s:4316/v1/traces" , exporterPrefix , cloudwatchAgentServiceEndpoint )},
188+ {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
189+ {Name : "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT" , Value : fmt .Sprintf ("%s://%s:4316/v1/metrics" , exporterPrefix , cloudwatchAgentServiceEndpoint )},
190+ {Name : "OTEL_METRICS_EXPORTER" , Value : "none" },
191+ {Name : "OTEL_PYTHON_DISTRO" , Value : "aws_distro" },
192+ {Name : "OTEL_PYTHON_CONFIGURATOR" , Value : "aws_configurator" },
193+ {Name : "OTEL_LOGS_EXPORTER" , Value : "none" },
194+ }
195+ }
196+ return envs
197+ }
198+
199+ func getDotNetEnvs (isAppSignalsEnabled bool , cloudwatchAgentServiceEndpoint , exporterPrefix string , additionalEnvs map [string ]string ) []corev1.EnvVar {
200+ var envs []corev1.EnvVar
201+ if isAppSignalsEnabled {
202+ envs = []corev1.EnvVar {
203+ {Name : "OTEL_AWS_APPLICATION_SIGNALS_ENABLED" , Value : "true" },
204+ {Name : "OTEL_TRACES_SAMPLER_ARG" , Value : fmt .Sprintf ("endpoint=%s://%s:2000" , http , cloudwatchAgentServiceEndpoint )},
205+ {Name : "OTEL_TRACES_SAMPLER" , Value : "xray" },
206+ {Name : "OTEL_EXPORTER_OTLP_PROTOCOL" , Value : "http/protobuf" },
207+ {Name : "OTEL_EXPORTER_OTLP_ENDPOINT" , Value : fmt .Sprintf ("%s://%s:4316" , exporterPrefix , cloudwatchAgentServiceEndpoint )},
208+ {Name : "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" , Value : fmt .Sprintf ("%s://%s:4316/v1/traces" , exporterPrefix , cloudwatchAgentServiceEndpoint )},
209+ {Name : "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT" , Value : fmt .Sprintf ("%s://%s:4316/v1/metrics" , exporterPrefix , cloudwatchAgentServiceEndpoint )},
210+ {Name : "OTEL_METRICS_EXPORTER" , Value : "none" },
211+ {Name : "OTEL_DOTNET_DISTRO" , Value : "aws_distro" },
212+ {Name : "OTEL_DOTNET_CONFIGURATOR" , Value : "aws_configurator" },
213+ {Name : "OTEL_LOGS_EXPORTER" , Value : "none" },
214+ {Name : "OTEL_DOTNET_AUTO_PLUGINS" , Value : "AWS.Distro.OpenTelemetry.AutoInstrumentation.Plugin, AWS.Distro.OpenTelemetry.AutoInstrumentation" },
215+ }
216+ }
217+ return envs
218+ }
219+
220+ func getNodeJSEnvs (isAppSignalsEnabled bool , cloudwatchAgentServiceEndpoint , exporterPrefix string , additionalEnvs map [string ]string ) []corev1.EnvVar {
221+ var envs []corev1.EnvVar
222+ if isAppSignalsEnabled {
223+ envs = []corev1.EnvVar {
224+ {Name : "OTEL_AWS_APPLICATION_SIGNALS_ENABLED" , Value : "true" },
225+ {Name : "OTEL_TRACES_SAMPLER_ARG" , Value : fmt .Sprintf ("endpoint=%s://%s:2000" , exporterPrefix , cloudwatchAgentServiceEndpoint )},
226+ {Name : "OTEL_TRACES_SAMPLER" , Value : "xray" },
227+ {Name : "OTEL_EXPORTER_OTLP_PROTOCOL" , Value : "http/protobuf" },
228+ {Name : "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" , Value : fmt .Sprintf ("%s://%s:4316/v1/traces" , exporterPrefix , cloudwatchAgentServiceEndpoint )},
229+ {Name : "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT" , Value : fmt .Sprintf ("%s://%s:4316/v1/metrics" , exporterPrefix , cloudwatchAgentServiceEndpoint )},
230+ {Name : "OTEL_METRICS_EXPORTER" , Value : "none" },
231+ {Name : "OTEL_LOGS_EXPORTER" , Value : "none" },
232+ }
233+ }
234+ return envs
235+ }
0 commit comments