Skip to content

Commit 5a99777

Browse files
author
Reno Seo
authored
Support runtime metrics for Application Signals (#229)
1 parent ca98f33 commit 5a99777

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ func setLangEnvVarsForResource(langStr string, resourceStr string, resource map[
8989
if memory, ok := resource["memory"]; ok {
9090
os.Setenv("AUTO_INSTRUMENTATION_"+langStr+"_MEM_"+resourceStr, memory)
9191
}
92+
if enabled, ok := resource["enabled"]; ok {
93+
os.Setenv("AUTO_INSTRUMENTATION_"+langStr+"_RUNTIME_ENABLED", enabled)
94+
}
9295
}
9396

9497
func setLangEnvVars(langStr string, cfg map[string]map[string]string) {
@@ -98,6 +101,9 @@ func setLangEnvVars(langStr string, cfg map[string]map[string]string) {
98101
if requests, ok := cfg["requests"]; ok {
99102
setLangEnvVarsForResource(langStr, "REQUEST", requests)
100103
}
104+
if runtimeMetrics, ok := cfg["runtime_metrics"]; ok {
105+
setLangEnvVarsForResource(langStr, "", runtimeMetrics)
106+
}
101107
}
102108

103109
func main() {
@@ -143,7 +149,7 @@ func main() {
143149
pflag.Parse()
144150

145151
// set instrumentation cpu and memory limits in environment variables to be used for default instrumentation; default values received from https://github.com/open-telemetry/opentelemetry-operator/blob/main/apis/v1alpha1/instrumentation_webhook.go
146-
autoInstrumentationConfig := map[string]map[string]map[string]string{"java": {"limits": {"cpu": "500m", "memory": "64Mi"}, "requests": {"cpu": "50m", "memory": "64Mi"}}, "python": {"limits": {"cpu": "500m", "memory": "32Mi"}, "requests": {"cpu": "50m", "memory": "32Mi"}}, "dotnet": {"limits": {"cpu": "500m", "memory": "128Mi"}, "requests": {"cpu": "50m", "memory": "128Mi"}}, "nodejs": {"limits": {"cpu": "500m", "memory": "128Mi"}, "requests": {"cpu": "50m", "memory": "128Mi"}}}
152+
autoInstrumentationConfig := map[string]map[string]map[string]string{"java": {"limits": {"cpu": "500m", "memory": "64Mi"}, "requests": {"cpu": "50m", "memory": "64Mi"}, "runtime_metrics": {"enabled": "true"}}, "python": {"limits": {"cpu": "500m", "memory": "32Mi"}, "requests": {"cpu": "50m", "memory": "32Mi"}, "runtime_metrics": {"enabled": "true"}}, "dotnet": {"limits": {"cpu": "500m", "memory": "128Mi"}, "requests": {"cpu": "50m", "memory": "128Mi"}}, "nodejs": {"limits": {"cpu": "500m", "memory": "128Mi"}, "requests": {"cpu": "50m", "memory": "128Mi"}}}
147153
err := json.Unmarshal([]byte(autoInstrumentationConfigStr), &autoInstrumentationConfig)
148154
if err != nil {
149155
setupLog.Info(fmt.Sprintf("Using default values: %v", autoInstrumentationConfig))

pkg/instrumentation/defaultinstrumentation.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ func getJavaEnvs(isAppSignalsEnabled bool, cloudwatchAgentServiceEndpoint, expor
146146
}
147147

148148
if isAppSignalsEnabled {
149+
isJavaRuntimeEnabled, ok := os.LookupEnv("AUTO_INSTRUMENTATION_JAVA_RUNTIME_ENABLED")
150+
if !ok {
151+
isJavaRuntimeEnabled = "true";
152+
}
149153
appSignalsEnvs := []corev1.EnvVar{
150154
{Name: "OTEL_AWS_APP_SIGNALS_ENABLED", Value: "true"}, //TODO: remove in favor of new name once safe
151155
{Name: "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", Value: "true"},
@@ -154,6 +158,7 @@ func getJavaEnvs(isAppSignalsEnabled bool, cloudwatchAgentServiceEndpoint, expor
154158
{Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/traces", exporterPrefix, cloudwatchAgentServiceEndpoint)},
155159
{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
156160
{Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/metrics", exporterPrefix, cloudwatchAgentServiceEndpoint)},
161+
{Name: "OTEL_AWS_APPLICATION_SIGNALS_RUNTIME_ENABLED", Value: isJavaRuntimeEnabled},
157162
}
158163
envs = append(envs, appSignalsEnvs...)
159164
} else {
@@ -178,6 +183,10 @@ func getJavaEnvs(isAppSignalsEnabled bool, cloudwatchAgentServiceEndpoint, expor
178183
func getPythonEnvs(isAppSignalsEnabled bool, cloudwatchAgentServiceEndpoint, exporterPrefix string, additionalEnvs map[string]string) []corev1.EnvVar {
179184
var envs []corev1.EnvVar
180185
if isAppSignalsEnabled {
186+
isPythonRuntimeEnabled, ok := os.LookupEnv("AUTO_INSTRUMENTATION_PYTHON_RUNTIME_ENABLED")
187+
if !ok {
188+
isPythonRuntimeEnabled = "true";
189+
}
181190
envs = []corev1.EnvVar{
182191
{Name: "OTEL_AWS_APP_SIGNALS_ENABLED", Value: "true"}, //TODO: remove in favor of new name once safe
183192
{Name: "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", Value: "true"},
@@ -187,6 +196,7 @@ func getPythonEnvs(isAppSignalsEnabled bool, cloudwatchAgentServiceEndpoint, exp
187196
{Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/traces", exporterPrefix, cloudwatchAgentServiceEndpoint)},
188197
{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
189198
{Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/metrics", exporterPrefix, cloudwatchAgentServiceEndpoint)},
199+
{Name: "OTEL_AWS_APPLICATION_SIGNALS_RUNTIME_ENABLED", Value: isPythonRuntimeEnabled},
190200
{Name: "OTEL_METRICS_EXPORTER", Value: "none"},
191201
{Name: "OTEL_PYTHON_DISTRO", Value: "aws_distro"},
192202
{Name: "OTEL_PYTHON_CONFIGURATOR", Value: "aws_configurator"},

pkg/instrumentation/defaultinstrumentation_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ func Test_getDefaultInstrumentationLinux(t *testing.T) {
3838
os.Setenv("AUTO_INSTRUMENTATION_NODEJS_MEM_LIMIT", "128Mi")
3939
os.Setenv("AUTO_INSTRUMENTATION_NODEJS_CPU_REQUEST", "50m")
4040
os.Setenv("AUTO_INSTRUMENTATION_NODEJS_MEM_REQUEST", "128Mi")
41+
os.Setenv("AUTO_INSTRUMENTATION_JAVA_RUNTIME_ENABLED", "true")
42+
os.Setenv("AUTO_INSTRUMENTATION_PYTHON_RUNTIME_ENABLED", "true")
4143

4244
httpInst := &v1alpha1.Instrumentation{
4345
Status: v1alpha1.InstrumentationStatus{},
@@ -69,6 +71,7 @@ func Test_getDefaultInstrumentationLinux(t *testing.T) {
6971
{Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: "http://cloudwatch-agent.amazon-cloudwatch:4316/v1/traces"},
7072
{Name: "OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT", Value: "http://cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics"}, //TODO: remove in favor of new name once safe
7173
{Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: "http://cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics"},
74+
{Name: "OTEL_AWS_APPLICATION_SIGNALS_RUNTIME_ENABLED", Value: "true"},
7275
},
7376
Resources: corev1.ResourceRequirements{
7477
Limits: corev1.ResourceList{
@@ -92,6 +95,7 @@ func Test_getDefaultInstrumentationLinux(t *testing.T) {
9295
{Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: "http://cloudwatch-agent.amazon-cloudwatch:4316/v1/traces"},
9396
{Name: "OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT", Value: "http://cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics"}, //TODO: remove in favor of new name once safe
9497
{Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: "http://cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics"},
98+
{Name: "OTEL_AWS_APPLICATION_SIGNALS_RUNTIME_ENABLED", Value: "true"},
9599
{Name: "OTEL_METRICS_EXPORTER", Value: "none"},
96100
{Name: "OTEL_PYTHON_DISTRO", Value: "aws_distro"},
97101
{Name: "OTEL_PYTHON_CONFIGURATOR", Value: "aws_configurator"},
@@ -190,6 +194,7 @@ func Test_getDefaultInstrumentationLinux(t *testing.T) {
190194
{Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: "https://cloudwatch-agent.amazon-cloudwatch:4316/v1/traces"},
191195
{Name: "OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT", Value: "https://cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics"}, //TODO: remove in favor of new name once safe
192196
{Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: "https://cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics"},
197+
{Name: "OTEL_AWS_APPLICATION_SIGNALS_RUNTIME_ENABLED", Value: "true"},
193198
},
194199
Resources: corev1.ResourceRequirements{
195200
Limits: corev1.ResourceList{
@@ -213,6 +218,7 @@ func Test_getDefaultInstrumentationLinux(t *testing.T) {
213218
{Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: "https://cloudwatch-agent.amazon-cloudwatch:4316/v1/traces"},
214219
{Name: "OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT", Value: "https://cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics"}, //TODO: remove in favor of new name once safe
215220
{Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: "https://cloudwatch-agent.amazon-cloudwatch:4316/v1/metrics"},
221+
{Name: "OTEL_AWS_APPLICATION_SIGNALS_RUNTIME_ENABLED", Value: "true"},
216222
{Name: "OTEL_METRICS_EXPORTER", Value: "none"},
217223
{Name: "OTEL_PYTHON_DISTRO", Value: "aws_distro"},
218224
{Name: "OTEL_PYTHON_CONFIGURATOR", Value: "aws_configurator"},
@@ -361,6 +367,8 @@ func Test_getDefaultInstrumentationWindows(t *testing.T) {
361367
os.Setenv("AUTO_INSTRUMENTATION_NODEJS_MEM_LIMIT", "128Mi")
362368
os.Setenv("AUTO_INSTRUMENTATION_NODEJS_CPU_REQUEST", "50m")
363369
os.Setenv("AUTO_INSTRUMENTATION_NODEJS_MEM_REQUEST", "128Mi")
370+
os.Setenv("AUTO_INSTRUMENTATION_JAVA_RUNTIME_METRICS", "true")
371+
os.Setenv("AUTO_INSTRUMENTATION_PYTHON_RUNTIME_METRICS", "true")
364372

365373
httpInst := &v1alpha1.Instrumentation{
366374
Status: v1alpha1.InstrumentationStatus{},
@@ -392,6 +400,7 @@ func Test_getDefaultInstrumentationWindows(t *testing.T) {
392400
{Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: "http://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316/v1/traces"},
393401
{Name: "OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT", Value: "http://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316/v1/metrics"}, //TODO: remove in favor of new name once safe
394402
{Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: "http://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316/v1/metrics"},
403+
{Name: "OTEL_AWS_APPLICATION_SIGNALS_RUNTIME_ENABLED", Value: "true"},
395404
},
396405
Resources: corev1.ResourceRequirements{
397406
Limits: corev1.ResourceList{
@@ -415,6 +424,7 @@ func Test_getDefaultInstrumentationWindows(t *testing.T) {
415424
{Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: "http://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316/v1/traces"},
416425
{Name: "OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT", Value: "http://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316/v1/metrics"}, //TODO: remove in favor of new name once safe
417426
{Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: "http://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316/v1/metrics"},
427+
{Name: "OTEL_AWS_APPLICATION_SIGNALS_RUNTIME_ENABLED", Value: "true"},
418428
{Name: "OTEL_METRICS_EXPORTER", Value: "none"},
419429
{Name: "OTEL_PYTHON_DISTRO", Value: "aws_distro"},
420430
{Name: "OTEL_PYTHON_CONFIGURATOR", Value: "aws_configurator"},
@@ -513,6 +523,7 @@ func Test_getDefaultInstrumentationWindows(t *testing.T) {
513523
{Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: "https://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316/v1/traces"},
514524
{Name: "OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT", Value: "https://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316/v1/metrics"}, //TODO: remove in favor of new name once safe
515525
{Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: "https://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316/v1/metrics"},
526+
{Name: "OTEL_AWS_APPLICATION_SIGNALS_RUNTIME_ENABLED", Value: "true"},
516527
},
517528
Resources: corev1.ResourceRequirements{
518529
Limits: corev1.ResourceList{
@@ -536,6 +547,7 @@ func Test_getDefaultInstrumentationWindows(t *testing.T) {
536547
{Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: "https://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316/v1/traces"},
537548
{Name: "OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT", Value: "https://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316/v1/metrics"}, //TODO: remove in favor of new name once safe
538549
{Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: "https://cloudwatch-agent-windows-headless.amazon-cloudwatch.svc.cluster.local:4316/v1/metrics"},
550+
{Name: "OTEL_AWS_APPLICATION_SIGNALS_RUNTIME_ENABLED", Value: "true"},
539551
{Name: "OTEL_METRICS_EXPORTER", Value: "none"},
540552
{Name: "OTEL_PYTHON_DISTRO", Value: "aws_distro"},
541553
{Name: "OTEL_PYTHON_CONFIGURATOR", Value: "aws_configurator"},

0 commit comments

Comments
 (0)