diff --git a/custom/src/main/java/com/solarwinds/opentelemetry/extensions/initialize/ConfigurationLoader.java b/custom/src/main/java/com/solarwinds/opentelemetry/extensions/initialize/ConfigurationLoader.java index d3b5b032..51168d1c 100644 --- a/custom/src/main/java/com/solarwinds/opentelemetry/extensions/initialize/ConfigurationLoader.java +++ b/custom/src/main/java/com/solarwinds/opentelemetry/extensions/initialize/ConfigurationLoader.java @@ -205,6 +205,7 @@ static void configOtelLogExport(ConfigContainer container) { String collectorEndpoint = (String) container.get(ConfigProperty.AGENT_COLLECTOR); if (collectorEndpoint != null) { + collectorEndpoint = collectorEndpoint.split(":")[0]; String[] fragments = collectorEndpoint.split("\\."); if (fragments.length > 2) { // This is based on knowledge of the SWO url format where the third name from the left in diff --git a/custom/src/test/java/com/solarwinds/opentelemetry/extensions/initialize/ConfigurationLoaderTest.java b/custom/src/test/java/com/solarwinds/opentelemetry/extensions/initialize/ConfigurationLoaderTest.java index a4b61b19..82fd149d 100644 --- a/custom/src/test/java/com/solarwinds/opentelemetry/extensions/initialize/ConfigurationLoaderTest.java +++ b/custom/src/test/java/com/solarwinds/opentelemetry/extensions/initialize/ConfigurationLoaderTest.java @@ -31,6 +31,7 @@ import com.solarwinds.opentelemetry.extensions.SpanAttributeNamingScheme; import com.solarwinds.opentelemetry.extensions.TransactionNameManager; import java.io.File; +import java.net.URL; import java.util.Arrays; import java.util.Collections; import org.junit.jupiter.api.Test; @@ -215,6 +216,42 @@ void verifyOtelLogExportEndpointIsProperlyFormed() throws InvalidConfigException System.getProperty("otel.exporter.otlp.logs.endpoint")); } + @Test + @ClearSystemProperty(key = "otel.logs.exporter") + @ClearSystemProperty(key = "otel.exporter.otlp.protocol") + @ClearSystemProperty(key = "otel.exporter.otlp.logs.headers") + @ClearSystemProperty(key = "otel.exporter.otlp.logs.endpoint") + void verifyOtelLogExportEndpointIsProperlyFormedWithPort() throws InvalidConfigException { + ConfigContainer configContainer = new ConfigContainer(); + configContainer.putByStringValue(ConfigProperty.AGENT_SERVICE_KEY, "token:service"); + configContainer.putByStringValue( + ConfigProperty.AGENT_COLLECTOR, "otel.collector.na-01.cloud.solarwinds.com:443"); + + configContainer.putByStringValue(ConfigProperty.AGENT_EXPORT_LOGS_ENABLED, "true"); + ConfigurationLoader.configOtelLogExport(configContainer); + + assertEquals( + "https://otel.collector.na-01.cloud.solarwinds.com", + System.getProperty("otel.exporter.otlp.logs.endpoint")); + } + + @Test + @ClearSystemProperty(key = "otel.logs.exporter") + @ClearSystemProperty(key = "otel.exporter.otlp.protocol") + @ClearSystemProperty(key = "otel.exporter.otlp.logs.headers") + @ClearSystemProperty(key = "otel.exporter.otlp.logs.endpoint") + void verifyOtelLogExportEndpointIsProperlyFormedForPortAndAO() throws InvalidConfigException { + ConfigContainer configContainer = new ConfigContainer(); + configContainer.putByStringValue(ConfigProperty.AGENT_SERVICE_KEY, "token:service"); + configContainer.putByStringValue(ConfigProperty.AGENT_COLLECTOR, "collector.appoptics.com:443"); + + configContainer.putByStringValue(ConfigProperty.AGENT_EXPORT_LOGS_ENABLED, "true"); + ConfigurationLoader.configOtelLogExport(configContainer); + + assertNotNull(System.getProperty("otel.exporter.otlp.logs.endpoint")); + assertDoesNotThrow(() -> new URL(System.getProperty("otel.exporter.otlp.logs.endpoint"))); + } + @Test @ClearSystemProperty(key = "otel.logs.exporter") @ClearSystemProperty(key = "otel.exporter.otlp.protocol")