Skip to content

Commit 594392f

Browse files
add default values for env variable if not set (#1056)
*Issue #, if available:* *Description of changes:* add default values for env variable if not set for non lambda env By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 18a7092 commit 594392f

File tree

2 files changed

+48
-21
lines changed

2 files changed

+48
-21
lines changed

appsignals-tests/contract-tests/src/test/java/software/amazon/opentelemetry/appsignals/test/base/ContractTestBase.java

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -134,27 +134,18 @@ protected int getApplicationPort() {
134134
}
135135

136136
protected Map<String, String> getApplicationEnvironmentVariables() {
137-
return Map.of(
138-
"JAVA_TOOL_OPTIONS",
139-
"-javaagent:" + MOUNT_PATH,
140-
"OTEL_METRIC_EXPORT_INTERVAL",
141-
"100", // 100 ms
142-
"OTEL_AWS_APPLICATION_SIGNALS_ENABLED",
143-
"true",
144-
"OTEL_AWS_APPLICATION_SIGNALS_RUNTIME_ENABLED",
145-
isRuntimeEnabled(),
146-
"OTEL_METRICS_EXPORTER",
147-
"none",
148-
"OTEL_BSP_SCHEDULE_DELAY",
149-
"0", // Don't wait to export spans to the collector
150-
"OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT",
151-
COLLECTOR_HTTP_ENDPOINT,
152-
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT",
153-
COLLECTOR_HTTP_ENDPOINT,
154-
"OTEL_RESOURCE_ATTRIBUTES",
155-
getApplicationOtelResourceAttributes(),
156-
"OTEL_EXPORTER_OTLP_PROTOCOL",
157-
"grpc");
137+
return Map.ofEntries(
138+
Map.entry("JAVA_TOOL_OPTIONS", "-javaagent:" + MOUNT_PATH),
139+
Map.entry("OTEL_METRIC_EXPORT_INTERVAL", "100"), // 100 ms
140+
Map.entry("OTEL_AWS_APPLICATION_SIGNALS_ENABLED", "true"),
141+
Map.entry("OTEL_AWS_APPLICATION_SIGNALS_RUNTIME_ENABLED", isRuntimeEnabled()),
142+
Map.entry("OTEL_METRICS_EXPORTER", "none"),
143+
Map.entry("OTEL_BSP_SCHEDULE_DELAY", "0"), // Don't wait to export spans to the collector
144+
Map.entry("OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", COLLECTOR_HTTP_ENDPOINT),
145+
Map.entry("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", COLLECTOR_HTTP_ENDPOINT),
146+
Map.entry("OTEL_RESOURCE_ATTRIBUTES", getApplicationOtelResourceAttributes()),
147+
Map.entry("OTEL_EXPORTER_OTLP_PROTOCOL", "grpc"),
148+
Map.entry("OTEL_TRACES_SAMPLER", "parentbased_always_on"));
158149
}
159150

160151
protected Map<String, String> getApplicationExtraEnvironmentVariables() {

awsagentprovider/src/main/java/software/amazon/opentelemetry/javaagent/providers/AwsApplicationSignalsCustomizerProvider.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ public class AwsApplicationSignalsCustomizerProvider
102102
private static final String OTEL_BSP_MAX_EXPORT_BATCH_SIZE_CONFIG =
103103
"otel.bsp.max.export.batch.size";
104104

105+
private static final String OTEL_METRICS_EXPORTER = "otel.metrics.exporter";
106+
private static final String OTEL_LOGS_EXPORTER = "otel.logs.exporter";
107+
private static final String OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT =
108+
"otel.aws.application.signals.exporter.endpoint";
109+
private static final String OTEL_EXPORTER_OTLP_PROTOCOL = "otel.exporter.otlp.protocol";
110+
private static final String OTEL_EXPORTER_OTLP_TRACES_ENDPOINT =
111+
"otel.exporter.otlp.traces.endpoint";
112+
private static final String OTEL_TRACES_SAMPLER = "otel.traces.sampler";
113+
private static final String OTEL_TRACES_SAMPLER_ARG = "otel.traces.sampler.arg";
114+
105115
// UDP packet can be upto 64KB. To limit the packet size, we limit the exported batch size.
106116
// This is a bit of a magic number, as there is no simple way to tell how many spans can make a
107117
// 64KB batch since spans can vary in size.
@@ -140,6 +150,32 @@ private Map<String, String> customizeProperties(ConfigProperties configProps) {
140150
// Enable AWS Resource Providers
141151
propsOverride.put(OTEL_RESOURCE_PROVIDERS_AWS_ENABLED, "true");
142152

153+
if (!isLambdaEnvironment()) {
154+
// Check if properties exist in `configProps`, and only set if missing
155+
if (configProps.getString(OTEL_METRICS_EXPORTER) == null) {
156+
propsOverride.put(OTEL_METRICS_EXPORTER, "none");
157+
}
158+
if (configProps.getString(OTEL_LOGS_EXPORTER) == null) {
159+
propsOverride.put(OTEL_LOGS_EXPORTER, "none");
160+
}
161+
if (configProps.getString(OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT) == null) {
162+
propsOverride.put(
163+
OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT, "http://localhost:4316/v1/metrics");
164+
}
165+
if (configProps.getString(OTEL_EXPORTER_OTLP_PROTOCOL) == null) {
166+
propsOverride.put(OTEL_EXPORTER_OTLP_PROTOCOL, "http/protobuf");
167+
}
168+
if (configProps.getString(OTEL_EXPORTER_OTLP_TRACES_ENDPOINT) == null) {
169+
propsOverride.put(OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, "http://localhost:4316/v1/traces");
170+
}
171+
if (configProps.getString(OTEL_TRACES_SAMPLER) == null) {
172+
propsOverride.put(OTEL_TRACES_SAMPLER, "xray");
173+
}
174+
if (configProps.getString(OTEL_TRACES_SAMPLER_ARG) == null) {
175+
propsOverride.put(OTEL_TRACES_SAMPLER_ARG, "endpoint=http://localhost:2000");
176+
}
177+
}
178+
143179
if (isApplicationSignalsRuntimeEnabled(configProps)) {
144180
List<String> list = configProps.getList(OTEL_JMX_TARGET_SYSTEM_CONFIG);
145181
if (list.contains("jvm")) {

0 commit comments

Comments
 (0)