Skip to content

Commit

Permalink
Merge pull request #286 from solarwinds/cc/NH-93486
Browse files Browse the repository at this point in the history
NH-93486: honor user system property config
  • Loading branch information
cleverchuk authored Dec 9, 2024
2 parents 5c7e3bc + 569a2d3 commit d538bf8
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ env:
SW_APM_DEBUG_LEVEL: trace
AGENT_DOWNLOAD_URL: https://agent-binaries.global.st-ssp.solarwinds.com/apm/java/latest/solarwinds-apm-agent.jar
SW_APM_COLLECTOR: ${{ secrets.SW_APM_COLLECTOR }}
OTEL_EXPORTER_OTLP_ENDPOINT: ${{ secrets.OTEL_EXPORTER_OTLP_ENDPOINT }}
SW_APM_SERVICE_KEY_AO: ${{ secrets.SW_APM_SERVICE_KEY_AO }}
SW_APM_SERVICE_KEY: ${{ secrets.SW_APM_SERVICE_KEY }}
GITHUB_USERNAME: ${{ github.actor }}
Expand Down Expand Up @@ -171,6 +170,7 @@ jobs:
- s3-stage-upload
env:
LAMBDA: "true"
OTEL_EXPORTER_OTLP_ENDPOINT: ${{ secrets.OTEL_EXPORTER_OTLP_ENDPOINT }}
steps:
- uses: actions/checkout@v4

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private static void maybeFollowOtelConfigProperties(ConfigContainer configs) {
if (serviceKey != null) {
String name = ServiceKeyUtils.getServiceName(serviceKey);
if (name != null) {
System.setProperty("otel.service.name", name);
setSystemProperty("otel.service.name", name);
}
}

Expand Down Expand Up @@ -223,12 +223,12 @@ static void configureOtelLogExport(ConfigContainer container) {
}
}

System.setProperty("otel.exporter.otlp.logs.protocol", "grpc");
System.setProperty("otel.logs.exporter", "otlp");
System.setProperty(
setSystemProperty("otel.exporter.otlp.logs.protocol", "grpc");
setSystemProperty("otel.logs.exporter", "otlp");
setSystemProperty(
"otel.exporter.otlp.logs.headers", String.format("authorization=Bearer %s", apiKey));

System.setProperty(
setEndpoint(
"otel.exporter.otlp.logs.endpoint",
String.format("https://otel.collector.%s.%s.solarwinds.com", dataCell, env));
}
Expand Down Expand Up @@ -261,12 +261,12 @@ static void configureOtelMetricExport(ConfigContainer container) {
}
}

System.setProperty("otel.exporter.otlp.metrics.protocol", "grpc");
System.setProperty("otel.metrics.exporter", "otlp");
System.setProperty(
setSystemProperty("otel.exporter.otlp.metrics.protocol", "grpc");
setSystemProperty("otel.metrics.exporter", "otlp");
setSystemProperty(
"otel.exporter.otlp.metrics.headers", String.format("authorization=Bearer %s", apiKey));

System.setProperty(
setEndpoint(
"otel.exporter.otlp.metrics.endpoint",
String.format("https://otel.collector.%s.%s.solarwinds.com", dataCell, env));
}
Expand All @@ -282,7 +282,7 @@ static void configureOtelTraceExport(ConfigContainer container) {

if (collectorEndpoint != null) {
if (collectorEndpoint.contains("appoptics.com")) {
System.setProperty("otel.traces.exporter", COMPONENT_NAME);
setSystemProperty("otel.traces.exporter", COMPONENT_NAME);
return;
}

Expand All @@ -299,11 +299,11 @@ static void configureOtelTraceExport(ConfigContainer container) {
}
}

System.setProperty("otel.exporter.otlp.traces.protocol", "grpc");
System.setProperty(
setSystemProperty("otel.exporter.otlp.traces.protocol", "grpc");
setSystemProperty(
"otel.exporter.otlp.traces.headers", String.format("authorization=Bearer %s", apiKey));

System.setProperty(
setEndpoint(
"otel.exporter.otlp.traces.endpoint",
String.format("https://otel.collector.%s.%s.solarwinds.com", dataCell, env));
}
Expand Down Expand Up @@ -637,4 +637,34 @@ public static boolean shouldUseOtlpForMetrics() {
return (enabled == null || enabled)
&& (collectorEndpoint == null || !collectorEndpoint.contains("appoptics.com"));
}

private static void setSystemProperty(String key, String value) {
String propertyValue = getConfigValue(key);
if (propertyValue == null) {
propertyValue = value;
System.setProperty(key, value);
}

logger.debug(
String.format("System configuration set with key-value -> %s = %s", key, propertyValue));
}

private static void setEndpoint(String key, String value) {
if (getConfigValue("otel.exporter.otlp.endpoint") == null) {
setSystemProperty(key, value);
}
}

static String normalize(String key) {
return key.toUpperCase().replace(".", "_");
}

private static String getConfigValue(String key) {
String propertyValue = System.getProperty(key);
if (propertyValue == null) {
propertyValue = System.getenv(normalize(key));
}

return propertyValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -402,4 +402,11 @@ void returnFalseWhenDisabledForMetric() throws InvalidConfigException {
assertFalse(ConfigurationLoader.shouldUseOtlpForMetrics());
ConfigManager.removeConfig(ConfigProperty.AGENT_EXPORT_METRICS_ENABLED);
}

@Test
void returnEnvironmentVariableEquivalent() {
assertEquals(
"OTEL_EXPORTER_OTLP_ENDPOINT",
ConfigurationLoader.normalize("otel.exporter.otlp.endpoint"));
}
}

0 comments on commit d538bf8

Please sign in to comment.