@@ -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" )
@@ -77,9 +77,10 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo
7777
7878 // set protocol by checking cloudwatch agent config for tls setting
7979 exporterPrefix := http
80- if agentConfig != nil {
81- appSignalsConfig := agentConfig .GetApplicationSignalsConfig ()
82- if appSignalsConfig != nil && appSignalsConfig .TLS != nil {
80+ isApplicationSignalsEnabled := agentConfig != nil && agentConfig .GetApplicationSignalsConfig () != nil
81+
82+ if isApplicationSignalsEnabled {
83+ if agentConfig .GetApplicationSignalsConfig ().TLS != nil {
8384 exporterPrefix = https
8485 }
8586 }
@@ -103,77 +104,31 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo
103104 },
104105 Java : v1alpha1.Java {
105106 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- },
107+ Env : getJavaEnvs (isApplicationSignalsEnabled , cloudwatchAgentServiceEndpoint , exporterPrefix , additionalEnvs [TypeJava ]),
118108 Resources : corev1.ResourceRequirements {
119109 Limits : getInstrumentationConfigForResource (java , limit ),
120110 Requests : getInstrumentationConfigForResource (java , request ),
121111 },
122112 },
123113 Python : v1alpha1.Python {
124114 Image : pythonInstrumentationImage ,
125- Env : []corev1.EnvVar {
126- {Name : "OTEL_AWS_APP_SIGNALS_ENABLED" , Value : "true" }, //TODO: remove in favor of new name once safe
127- {Name : "OTEL_AWS_APPLICATION_SIGNALS_ENABLED" , Value : "true" },
128- {Name : "OTEL_TRACES_SAMPLER_ARG" , Value : fmt .Sprintf ("endpoint=%s://%s:2000" , http , cloudwatchAgentServiceEndpoint )},
129- {Name : "OTEL_TRACES_SAMPLER" , Value : "xray" },
130- {Name : "OTEL_EXPORTER_OTLP_PROTOCOL" , Value : "http/protobuf" },
131- {Name : "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" , Value : fmt .Sprintf ("%s://%s:4316/v1/traces" , exporterPrefix , cloudwatchAgentServiceEndpoint )},
132- {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
133- {Name : "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT" , Value : fmt .Sprintf ("%s://%s:4316/v1/metrics" , exporterPrefix , cloudwatchAgentServiceEndpoint )},
134- {Name : "OTEL_METRICS_EXPORTER" , Value : "none" },
135- {Name : "OTEL_PYTHON_DISTRO" , Value : "aws_distro" },
136- {Name : "OTEL_PYTHON_CONFIGURATOR" , Value : "aws_configurator" },
137- {Name : "OTEL_LOGS_EXPORTER" , Value : "none" },
138- },
115+ Env : getPythonEnvs (isApplicationSignalsEnabled , cloudwatchAgentServiceEndpoint , exporterPrefix , additionalEnvs [TypePython ]),
139116 Resources : corev1.ResourceRequirements {
140117 Limits : getInstrumentationConfigForResource (python , limit ),
141118 Requests : getInstrumentationConfigForResource (python , request ),
142119 },
143120 },
144121 DotNet : v1alpha1.DotNet {
145122 Image : dotNetInstrumentationImage ,
146- Env : []corev1.EnvVar {
147- {Name : "OTEL_AWS_APPLICATION_SIGNALS_ENABLED" , Value : "true" },
148- {Name : "OTEL_TRACES_SAMPLER_ARG" , Value : fmt .Sprintf ("endpoint=%s://%s:2000" , http , cloudwatchAgentServiceEndpoint )},
149- {Name : "OTEL_TRACES_SAMPLER" , Value : "xray" },
150- {Name : "OTEL_EXPORTER_OTLP_PROTOCOL" , Value : "http/protobuf" },
151- {Name : "OTEL_EXPORTER_OTLP_ENDPOINT" , Value : fmt .Sprintf ("%s://%s:4316" , exporterPrefix , cloudwatchAgentServiceEndpoint )},
152- {Name : "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" , Value : fmt .Sprintf ("%s://%s:4316/v1/traces" , exporterPrefix , cloudwatchAgentServiceEndpoint )},
153- {Name : "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT" , Value : fmt .Sprintf ("%s://%s:4316/v1/metrics" , exporterPrefix , cloudwatchAgentServiceEndpoint )},
154- {Name : "OTEL_METRICS_EXPORTER" , Value : "none" },
155- {Name : "OTEL_DOTNET_DISTRO" , Value : "aws_distro" },
156- {Name : "OTEL_DOTNET_CONFIGURATOR" , Value : "aws_configurator" },
157- {Name : "OTEL_LOGS_EXPORTER" , Value : "none" },
158- {Name : "OTEL_DOTNET_AUTO_PLUGINS" , Value : "AWS.Distro.OpenTelemetry.AutoInstrumentation.Plugin, AWS.Distro.OpenTelemetry.AutoInstrumentation" },
159- },
123+ Env : getDotNetEnvs (isApplicationSignalsEnabled , cloudwatchAgentServiceEndpoint , exporterPrefix , additionalEnvs [TypeDotNet ]),
160124 Resources : corev1.ResourceRequirements {
161125 Limits : getInstrumentationConfigForResource (dotNet , limit ),
162126 Requests : getInstrumentationConfigForResource (dotNet , request ),
163127 },
164128 },
165129 NodeJS : v1alpha1.NodeJS {
166130 Image : nodeJSInstrumentationImage ,
167- Env : []corev1.EnvVar {
168- {Name : "OTEL_AWS_APPLICATION_SIGNALS_ENABLED" , Value : "true" },
169- {Name : "OTEL_TRACES_SAMPLER_ARG" , Value : fmt .Sprintf ("endpoint=%s://%s:2000" , exporterPrefix , cloudwatchAgentServiceEndpoint )},
170- {Name : "OTEL_TRACES_SAMPLER" , Value : "xray" },
171- {Name : "OTEL_EXPORTER_OTLP_PROTOCOL" , Value : "http/protobuf" },
172- {Name : "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" , Value : fmt .Sprintf ("%s://%s:4316/v1/traces" , exporterPrefix , cloudwatchAgentServiceEndpoint )},
173- {Name : "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT" , Value : fmt .Sprintf ("%s://%s:4316/v1/metrics" , exporterPrefix , cloudwatchAgentServiceEndpoint )},
174- {Name : "OTEL_METRICS_EXPORTER" , Value : "none" },
175- {Name : "OTEL_LOGS_EXPORTER" , Value : "none" },
176- },
131+ Env : getNodeJSEnvs (isApplicationSignalsEnabled , cloudwatchAgentServiceEndpoint , exporterPrefix , additionalEnvs [TypeDotNet ]),
177132 Resources : corev1.ResourceRequirements {
178133 Limits : getInstrumentationConfigForResource (nodeJS , limit ),
179134 Requests : getInstrumentationConfigForResource (nodeJS , request ),
@@ -182,3 +137,99 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo
182137 },
183138 }, nil
184139}
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