From ec2d1bde0d1e977ed8978e124f942d34a16d1f02 Mon Sep 17 00:00:00 2001 From: cleverchuk Date: Wed, 18 Feb 2026 10:08:06 -0500 Subject: [PATCH] simplify otel configuration and deprecate `SW_APM_EXPORT_LOGS_ENABLED` --- .../SolarwindsPropertiesSupplier.java | 1 - .../config/ConfigurationLoader.java | 156 +------- .../config/ConfigurationLoaderTest.java | 341 +++--------------- .../extensions/PropertiesSupplier.java | 1 - 4 files changed, 56 insertions(+), 443 deletions(-) diff --git a/custom/src/main/java/com/solarwinds/opentelemetry/extensions/SolarwindsPropertiesSupplier.java b/custom/src/main/java/com/solarwinds/opentelemetry/extensions/SolarwindsPropertiesSupplier.java index cdeed851..1a75e456 100644 --- a/custom/src/main/java/com/solarwinds/opentelemetry/extensions/SolarwindsPropertiesSupplier.java +++ b/custom/src/main/java/com/solarwinds/opentelemetry/extensions/SolarwindsPropertiesSupplier.java @@ -30,7 +30,6 @@ public class SolarwindsPropertiesSupplier implements Supplier 2) { - // This is based on knowledge of the SWO url format where the third name from the left in - // the domain is the data-cell name and assumes this format will stay stable. - dataCell = fragments[2]; - } - - if (fragments.length > 3) { - env = fragments[3]; - } - } - - String protocol = setProtocol("otel.exporter.otlp.logs.protocol"); - setSystemProperty("otel.logs.exporter", "otlp"); - setSystemProperty( - "otel.exporter.otlp.logs.headers", String.format("authorization=Bearer %s", apiKey)); - - if (protocol.equalsIgnoreCase("grpc")) { - setEndpoint( - "otel.exporter.otlp.logs.endpoint", - String.format("https://otel.collector.%s.%s.solarwinds.com", dataCell, env), - ""); - return; - } - - setEndpoint( - "otel.exporter.otlp.logs.endpoint", - String.format("https://otel.collector.%s.%s.solarwinds.com/v1/logs", dataCell, env), - "/v1/logs"); - } - } - - static void configureOtelMetricExport(ConfigContainer container) throws InvalidConfigException { + static void configureOtel(ConfigContainer container) throws InvalidConfigException { String serviceKey = (String) container.get(ConfigProperty.AGENT_SERVICE_KEY); String apiKey = ServiceKeyUtils.getApiKey(serviceKey); String dataCell = "na-01"; @@ -267,67 +218,16 @@ static void configureOtelMetricExport(ConfigContainer container) throws InvalidC } } - String protocol = setProtocol("otel.exporter.otlp.metrics.protocol"); - setSystemProperty("otel.metrics.exporter", "otlp"); - setSystemProperty( - "otel.exporter.otlp.metrics.headers", String.format("authorization=Bearer %s", apiKey)); - - if (protocol.equalsIgnoreCase("grpc")) { - setEndpoint( - "otel.exporter.otlp.metrics.endpoint", - String.format("https://otel.collector.%s.%s.solarwinds.com", dataCell, env), - ""); - return; - } - - setEndpoint( - "otel.exporter.otlp.metrics.endpoint", - String.format("https://otel.collector.%s.%s.solarwinds.com/v1/metrics", dataCell, env), - "/v1/metrics"); - } - - static void configureOtelTraceExport(ConfigContainer container) throws InvalidConfigException { - String serviceKey = (String) container.get(ConfigProperty.AGENT_SERVICE_KEY); - String apiKey = ServiceKeyUtils.getApiKey(serviceKey); - - String dataCell = "na-01"; - String env = "cloud"; - String collectorEndpoint = (String) container.get(ConfigProperty.AGENT_COLLECTOR); - - if (collectorEndpoint != null) { - if (collectorEndpoint.contains("appoptics.com")) { - throw new InvalidConfigException("Appoptics is not supported"); - } - - 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 - // the domain is the data-cell name and assumes this format will stay stable. - dataCell = fragments[2]; - } - - if (fragments.length > 3) { - env = fragments[3]; - } + if (isConfigNotSet("otel.exporter.otlp.headers")) { + System.setProperty( + "otel.exporter.otlp.headers", String.format("authorization=Bearer %s", apiKey)); } - String protocol = setProtocol("otel.exporter.otlp.traces.protocol"); - setSystemProperty( - "otel.exporter.otlp.traces.headers", String.format("authorization=Bearer %s", apiKey)); - - if (protocol.equalsIgnoreCase("grpc")) { - setEndpoint( - "otel.exporter.otlp.traces.endpoint", - String.format("https://otel.collector.%s.%s.solarwinds.com", dataCell, env), - ""); - return; + if (isConfigNotSet("otel.exporter.otlp.endpoint")) { + System.setProperty( + "otel.exporter.otlp.endpoint", + String.format("https://otel.collector.%s.%s.solarwinds.com", dataCell, env)); } - - setEndpoint( - "otel.exporter.otlp.traces.endpoint", - String.format("https://otel.collector.%s.%s.solarwinds.com/v1/traces", dataCell, env), - "/v1/traces"); } static Map mergeEnvWithSysProperties(Map env, Properties props) { @@ -381,9 +281,7 @@ private static void loadConfigurations() throws InvalidConfigException { config)); // initialize the logger factory as soon as the config is available try { processConfigs(configs); - configureOtelLogExport(configs); - configureOtelMetricExport(configs); - configureOtelTraceExport(configs); + configureOtel(configs); } catch (InvalidConfigException e) { // if there was a config read exception then processConfigs might throw exception due to // incomplete config container. @@ -652,47 +550,19 @@ public static void processConfigs(ConfigContainer configs) throws InvalidConfigE ConfigManager.initialize(configs); } - private static String setSystemProperty(String key, String value) { - String propertyValue = getConfigValue(key); - if (propertyValue == null) { - System.setProperty(key, value); - return value; - } - - return propertyValue; - } - - private static void setEndpoint(String key, String value, String path) { - String endpoint = getConfigValue("otel.exporter.otlp.endpoint"); - if (endpoint == null) { - setSystemProperty(key, value); - } else { - setSystemProperty(key, String.format("%s%s", endpoint, path)); - } - } - - private static String setProtocol(String key) { - String protocol = getConfigValue("otel.exporter.otlp.protocol"); - if (protocol == null) { - return setSystemProperty(key, ConfigurationLoader.PROTOCOL); - } - return protocol; - } - static String normalize(String key) { return key.toUpperCase().replace(".", "_"); } - private static String getConfigValue(String key) { + private static boolean isConfigNotSet(String key) { String propertyValue = System.getProperty(key); if (propertyValue == null) { propertyValue = System.getenv(normalize(key)); } - - return propertyValue; + return propertyValue == null; } private static boolean isDeclarativeConfigOff() { - return getConfigValue("otel.experimental.config.file") == null; + return isConfigNotSet("otel.experimental.config.file"); } } diff --git a/custom/src/test/java/com/solarwinds/opentelemetry/extensions/config/ConfigurationLoaderTest.java b/custom/src/test/java/com/solarwinds/opentelemetry/extensions/config/ConfigurationLoaderTest.java index bcc59dd6..28dd2379 100644 --- a/custom/src/test/java/com/solarwinds/opentelemetry/extensions/config/ConfigurationLoaderTest.java +++ b/custom/src/test/java/com/solarwinds/opentelemetry/extensions/config/ConfigurationLoaderTest.java @@ -155,367 +155,112 @@ void verifyThatServiceKeyIsUpdatedWithOtelServiceNameWhenSystemPropertyIsSet() } @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 verifySettingOtelLogExportSystemVariablesWhenEnabled() throws InvalidConfigException { - ConfigContainer configContainer = new ConfigContainer(); - configContainer.putByStringValue(ConfigProperty.AGENT_SERVICE_KEY, "token:service"); - configContainer.putByStringValue( - ConfigProperty.AGENT_COLLECTOR, "apm.collector.na-02.cloud.solarwinds.com"); - - configContainer.putByStringValue(ConfigProperty.AGENT_EXPORT_LOGS_ENABLED, "true"); - ConfigurationLoader.configureOtelLogExport(configContainer); - - assertEquals("otlp", System.getProperty("otel.logs.exporter")); - assertEquals("http/protobuf", System.getProperty("otel.exporter.otlp.logs.protocol")); - - assertEquals( - "https://otel.collector.na-02.cloud.solarwinds.com/v1/logs", - System.getProperty("otel.exporter.otlp.logs.endpoint")); - assertEquals( - "authorization=Bearer token", System.getProperty("otel.exporter.otlp.logs.headers")); - } - - @Test - @ClearSystemProperty(key = "otel.logs.exporter") - @ClearSystemProperty(key = "otel.exporter.otlp.logs.protocol") - @ClearSystemProperty(key = "otel.exporter.otlp.logs.headers") - @ClearSystemProperty(key = "otel.exporter.otlp.logs.endpoint") - void verifyOtelLogExportSystemVariablesAreNotSetWhenNotEnabled() throws InvalidConfigException { - ConfigContainer configContainer = new ConfigContainer(); - configContainer.putByStringValue(ConfigProperty.AGENT_SERVICE_KEY, "token:service"); - configContainer.putByStringValue( - ConfigProperty.AGENT_COLLECTOR, "apm.collector.na-02.cloud.solarwinds.com"); - - ConfigurationLoader.configureOtelLogExport(configContainer); - - assertNull(System.getProperty("otel.logs.exporter")); - assertNull(System.getProperty("otel.exporter.otlp.logs.protocol")); - - assertNull(System.getProperty("otel.exporter.otlp.logs.endpoint")); - assertNull(System.getProperty("otel.exporter.otlp.logs.headers")); - } - - @Test - @ClearSystemProperty(key = "otel.logs.exporter") - @ClearSystemProperty(key = "otel.exporter.otlp.logs.protocol") - @ClearSystemProperty(key = "otel.exporter.otlp.logs.headers") - @ClearSystemProperty(key = "otel.exporter.otlp.logs.endpoint") - void verifyOtelLogExportEndpointIsProperlyFormed() throws InvalidConfigException { + @ClearSystemProperty(key = "otel.exporter.otlp.endpoint") + @ClearSystemProperty(key = "otel.exporter.otlp.headers") + void verifyOtelEndpointIsProperlyFormed() throws InvalidConfigException { ConfigContainer configContainer = new ConfigContainer(); configContainer.putByStringValue(ConfigProperty.AGENT_SERVICE_KEY, "token:service"); configContainer.putByStringValue( ConfigProperty.AGENT_COLLECTOR, "apm.collector.na-02.staging.solarwinds.com"); - configContainer.putByStringValue(ConfigProperty.AGENT_EXPORT_LOGS_ENABLED, "true"); - ConfigurationLoader.configureOtelLogExport(configContainer); + ConfigurationLoader.configureOtel(configContainer); assertEquals( - "https://otel.collector.na-02.staging.solarwinds.com/v1/logs", - System.getProperty("otel.exporter.otlp.logs.endpoint")); + "https://otel.collector.na-02.staging.solarwinds.com", + System.getProperty("otel.exporter.otlp.endpoint")); } @Test - @ClearSystemProperty(key = "otel.logs.exporter") - @ClearSystemProperty(key = "otel.exporter.otlp.logs.protocol") - @ClearSystemProperty(key = "otel.exporter.otlp.logs.headers") - @ClearSystemProperty(key = "otel.exporter.otlp.logs.endpoint") - void verifyOtelLogExportEndpointIsProperlyFormedWithPort() throws InvalidConfigException { + @ClearSystemProperty(key = "otel.exporter.otlp.endpoint") + @ClearSystemProperty(key = "otel.exporter.otlp.headers") + void verifyOtelEndpointIsProperlyFormedWithPort() 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.configureOtelLogExport(configContainer); + ConfigurationLoader.configureOtel(configContainer); assertEquals( - "https://otel.collector.na-01.cloud.solarwinds.com/v1/logs", - System.getProperty("otel.exporter.otlp.logs.endpoint")); - } - - @Test - @ClearSystemProperty(key = "otel.logs.exporter") - @ClearSystemProperty(key = "otel.exporter.otlp.logs.protocol") - @ClearSystemProperty(key = "otel.exporter.otlp.logs.headers") - @ClearSystemProperty(key = "otel.exporter.otlp.logs.endpoint") - void verifyConfigureOtelLogExportThrowsForAO() 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"); - assertThrows( - InvalidConfigException.class, - () -> ConfigurationLoader.configureOtelLogExport(configContainer)); + "https://otel.collector.na-01.cloud.solarwinds.com", + System.getProperty("otel.exporter.otlp.endpoint")); } @Test - @ClearSystemProperty(key = "otel.logs.exporter") - @ClearSystemProperty(key = "otel.exporter.otlp.logs.protocol") - @ClearSystemProperty(key = "otel.exporter.otlp.logs.headers") - @ClearSystemProperty(key = "otel.exporter.otlp.logs.endpoint") - void verifyConfigureOtelTraceExportThrowsForAO() throws InvalidConfigException { + @ClearSystemProperty(key = "otel.exporter.otlp.endpoint") + @ClearSystemProperty(key = "otel.exporter.otlp.headers") + void verifyConfigureOtelThrowsForAoUrl() throws InvalidConfigException { ConfigContainer configContainer = new ConfigContainer(); configContainer.putByStringValue(ConfigProperty.AGENT_SERVICE_KEY, "token:service"); configContainer.putByStringValue(ConfigProperty.AGENT_COLLECTOR, "collector.appoptics.com:443"); assertThrows( - InvalidConfigException.class, - () -> ConfigurationLoader.configureOtelTraceExport(configContainer)); + InvalidConfigException.class, () -> ConfigurationLoader.configureOtel(configContainer)); } @Test - @ClearSystemProperty(key = "otel.logs.exporter") - @ClearSystemProperty(key = "otel.exporter.otlp.logs.protocol") - @ClearSystemProperty(key = "otel.exporter.otlp.logs.headers") - @ClearSystemProperty(key = "otel.exporter.otlp.logs.endpoint") + @ClearSystemProperty(key = "otel.exporter.otlp.endpoint") + @ClearSystemProperty(key = "otel.exporter.otlp.headers") void verifyDefaultEndpointIsUsed() throws InvalidConfigException { ConfigContainer configContainer = new ConfigContainer(); configContainer.putByStringValue(ConfigProperty.AGENT_SERVICE_KEY, "token:service"); configContainer.putByStringValue(ConfigProperty.AGENT_EXPORT_LOGS_ENABLED, "true"); - ConfigurationLoader.configureOtelLogExport(configContainer); + ConfigurationLoader.configureOtel(configContainer); assertEquals( - "https://otel.collector.na-01.cloud.solarwinds.com/v1/logs", - System.getProperty("otel.exporter.otlp.logs.endpoint")); - } - - @Test - @ClearSystemProperty(key = "otel.metrics.exporter") - @ClearSystemProperty(key = "otel.exporter.otlp.metrics.protocol") - @ClearSystemProperty(key = "otel.exporter.otlp.metrics.headers") - @ClearSystemProperty(key = "otel.exporter.otlp.metrics.endpoint") - void verifySettingOtelMetricExportSystemVariablesWhenEnabled() throws InvalidConfigException { - ConfigContainer configContainer = new ConfigContainer(); - configContainer.putByStringValue(ConfigProperty.AGENT_SERVICE_KEY, "token:service"); - configContainer.putByStringValue( - ConfigProperty.AGENT_COLLECTOR, "apm.collector.na-02.cloud.solarwinds.com"); - - configContainer.putByStringValue(ConfigProperty.AGENT_EXPORT_METRICS_ENABLED, "true"); - ConfigurationLoader.configureOtelMetricExport(configContainer); - - assertEquals("otlp", System.getProperty("otel.metrics.exporter")); - assertEquals("http/protobuf", System.getProperty("otel.exporter.otlp.metrics.protocol")); - - assertEquals( - "https://otel.collector.na-02.cloud.solarwinds.com/v1/metrics", - System.getProperty("otel.exporter.otlp.metrics.endpoint")); - assertEquals( - "authorization=Bearer token", System.getProperty("otel.exporter.otlp.metrics.headers")); - } - - @Test - @ClearSystemProperty(key = "otel.metrics.exporter") - @ClearSystemProperty(key = "otel.exporter.otlp.metrics.protocol") - @ClearSystemProperty(key = "otel.exporter.otlp.metrics.headers") - @ClearSystemProperty(key = "otel.exporter.otlp.metrics.endpoint") - void verifyOtelMetricExportSystemVariablesAreSetByDefault() throws InvalidConfigException { - ConfigContainer configContainer = new ConfigContainer(); - configContainer.putByStringValue(ConfigProperty.AGENT_SERVICE_KEY, "token:service"); - configContainer.putByStringValue( - ConfigProperty.AGENT_COLLECTOR, "apm.collector.na-02.cloud.solarwinds.com"); - - ConfigurationLoader.configureOtelMetricExport(configContainer); - - assertNotNull(System.getProperty("otel.metrics.exporter")); - assertNotNull(System.getProperty("otel.exporter.otlp.metrics.protocol")); - - assertNotNull(System.getProperty("otel.exporter.otlp.metrics.endpoint")); - assertNotNull(System.getProperty("otel.exporter.otlp.metrics.headers")); - } - - @Test - @ClearSystemProperty(key = "otel.metrics.exporter") - @ClearSystemProperty(key = "otel.exporter.otlp.metrics.protocol") - @ClearSystemProperty(key = "otel.exporter.otlp.metrics.headers") - @ClearSystemProperty(key = "otel.exporter.otlp.metrics.endpoint") - void verifyOtelMetricExportEndpointIsProperlyFormed() throws InvalidConfigException { - ConfigContainer configContainer = new ConfigContainer(); - configContainer.putByStringValue(ConfigProperty.AGENT_SERVICE_KEY, "token:service"); - configContainer.putByStringValue( - ConfigProperty.AGENT_COLLECTOR, "apm.collector.na-02.staging.solarwinds.com"); - - configContainer.putByStringValue(ConfigProperty.AGENT_EXPORT_METRICS_ENABLED, "true"); - ConfigurationLoader.configureOtelMetricExport(configContainer); - - assertEquals( - "https://otel.collector.na-02.staging.solarwinds.com/v1/metrics", - System.getProperty("otel.exporter.otlp.metrics.endpoint")); - } - - @Test - @ClearSystemProperty(key = "otel.metrics.exporter") - @ClearSystemProperty(key = "otel.exporter.otlp.metrics.protocol") - @ClearSystemProperty(key = "otel.exporter.otlp.metrics.headers") - @ClearSystemProperty(key = "otel.exporter.otlp.metrics.endpoint") - void verifyOtelMetricExportEndpointIsProperlyFormedWithPort() 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_METRICS_ENABLED, "true"); - ConfigurationLoader.configureOtelMetricExport(configContainer); - - assertEquals( - "https://otel.collector.na-01.cloud.solarwinds.com/v1/metrics", - System.getProperty("otel.exporter.otlp.metrics.endpoint")); - } - - @Test - @ClearSystemProperty(key = "otel.metrics.exporter") - @ClearSystemProperty(key = "otel.exporter.otlp.metrics.protocol") - @ClearSystemProperty(key = "otel.exporter.otlp.metrics.headers") - @ClearSystemProperty(key = "otel.exporter.otlp.metrics.endpoint") - void verifyConfigureOtelMetricExportThrowsForAO() 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_METRICS_ENABLED, "true"); - assertThrows( - InvalidConfigException.class, - () -> ConfigurationLoader.configureOtelMetricExport(configContainer)); - } - - @Test - @ClearSystemProperty(key = "otel.metrics.exporter") - @ClearSystemProperty(key = "otel.exporter.otlp.metrics.protocol") - @ClearSystemProperty(key = "otel.exporter.otlp.metrics.headers") - @ClearSystemProperty(key = "otel.exporter.otlp.metrics.endpoint") - void verifyDefaultEndpointIsUsedForMetric() throws InvalidConfigException { - ConfigContainer configContainer = new ConfigContainer(); - configContainer.putByStringValue(ConfigProperty.AGENT_SERVICE_KEY, "token:service"); - - configContainer.putByStringValue(ConfigProperty.AGENT_EXPORT_METRICS_ENABLED, "true"); - ConfigurationLoader.configureOtelMetricExport(configContainer); - - assertEquals( - "https://otel.collector.na-01.cloud.solarwinds.com/v1/metrics", - System.getProperty("otel.exporter.otlp.metrics.endpoint")); - } - - @Test - @ClearSystemProperty(key = "otel.traces.exporter") - @ClearSystemProperty(key = "otel.exporter.otlp.traces.protocol") - @ClearSystemProperty(key = "otel.exporter.otlp.traces.headers") - @ClearSystemProperty(key = "otel.exporter.otlp.traces.endpoint") - void verifyDefaultEndpointIsUsedForTrace() throws InvalidConfigException { - ConfigContainer configContainer = new ConfigContainer(); - configContainer.putByStringValue(ConfigProperty.AGENT_SERVICE_KEY, "token:service"); - - ConfigurationLoader.configureOtelTraceExport(configContainer); - assertEquals( - "https://otel.collector.na-01.cloud.solarwinds.com/v1/traces", - System.getProperty("otel.exporter.otlp.traces.endpoint")); - } - - @Test - @SetSystemProperty( - key = "otel.exporter.otlp.endpoint", - value = "https://otel.collector.na-01.cloud.solarwinds.com") - @ClearSystemProperty(key = "otel.exporter.otlp.metrics.endpoint") - @ClearSystemProperty(key = "otel.exporter.otlp.logs.endpoint") - @ClearSystemProperty(key = "otel.exporter.otlp.traces.endpoint") - void verifyMetricEndpointIsProperlyConfigured() throws InvalidConfigException { - ConfigContainer configContainer = new ConfigContainer(); - configContainer.putByStringValue(ConfigProperty.AGENT_SERVICE_KEY, "token:service"); - - configContainer.putByStringValue(ConfigProperty.AGENT_EXPORT_METRICS_ENABLED, "true"); - ConfigurationLoader.configureOtelMetricExport(configContainer); - - assertEquals( - "https://otel.collector.na-01.cloud.solarwinds.com/v1/metrics", - System.getProperty("otel.exporter.otlp.metrics.endpoint")); + "https://otel.collector.na-01.cloud.solarwinds.com", + System.getProperty("otel.exporter.otlp.endpoint")); } @Test - @SetSystemProperty( - key = "otel.exporter.otlp.endpoint", - value = "https://otel.collector.na-01.cloud.solarwinds.com") - @ClearSystemProperty(key = "otel.exporter.otlp.metrics.endpoint") - @ClearSystemProperty(key = "otel.exporter.otlp.logs.endpoint") - @ClearSystemProperty(key = "otel.exporter.otlp.traces.endpoint") - void verifyLogsEndpointIsProperlyConfigured() throws InvalidConfigException { + @ClearSystemProperty(key = "otel.exporter.otlp.headers") + @ClearSystemProperty(key = "otel.exporter.otlp.endpoint") + void verifyGlobalHeadersAreSetWhenNotConfigured() throws InvalidConfigException { ConfigContainer configContainer = new ConfigContainer(); configContainer.putByStringValue(ConfigProperty.AGENT_SERVICE_KEY, "token:service"); - configContainer.putByStringValue(ConfigProperty.AGENT_EXPORT_LOGS_ENABLED, "true"); - ConfigurationLoader.configureOtelLogExport(configContainer); - assertEquals( - "https://otel.collector.na-01.cloud.solarwinds.com/v1/logs", - System.getProperty("otel.exporter.otlp.logs.endpoint")); + ConfigurationLoader.configureOtel(configContainer); + assertEquals("authorization=Bearer token", System.getProperty("otel.exporter.otlp.headers")); } @Test - @SetSystemProperty( - key = "otel.exporter.otlp.endpoint", - value = "https://otel.collector.na-01.cloud.solarwinds.com") - @ClearSystemProperty(key = "otel.exporter.otlp.metrics.endpoint") - @ClearSystemProperty(key = "otel.exporter.otlp.logs.endpoint") - @ClearSystemProperty(key = "otel.exporter.otlp.traces.endpoint") - void verifyTraceEndpointIsProperlyConfigured() throws InvalidConfigException { + @SetSystemProperty(key = "otel.exporter.otlp.headers", value = "custom=header") + @ClearSystemProperty(key = "otel.exporter.otlp.endpoint") + void verifyGlobalHeadersAreNotClobberedWhenAlreadySet() throws InvalidConfigException { ConfigContainer configContainer = new ConfigContainer(); configContainer.putByStringValue(ConfigProperty.AGENT_SERVICE_KEY, "token:service"); - ConfigurationLoader.configureOtelTraceExport(configContainer); - assertEquals( - "https://otel.collector.na-01.cloud.solarwinds.com/v1/traces", - System.getProperty("otel.exporter.otlp.traces.endpoint")); + ConfigurationLoader.configureOtel(configContainer); + assertEquals("custom=header", System.getProperty("otel.exporter.otlp.headers")); } @Test @SetSystemProperty( key = "otel.exporter.otlp.endpoint", - value = "https://otel.collector.na-01.cloud.solarwinds.com") - @SetSystemProperty(key = "otel.exporter.otlp.metrics.protocol", value = "grpc") - @ClearSystemProperty(key = "otel.exporter.otlp.metrics.endpoint") - void verifyMetricsEndpointIsProperlyConfiguredForGRPC() throws InvalidConfigException { + value = "https://custom.endpoint.example.com") + @ClearSystemProperty(key = "otel.exporter.otlp.headers") + void verifyGlobalEndpointIsNotClobberedWhenAlreadySet() throws InvalidConfigException { ConfigContainer configContainer = new ConfigContainer(); configContainer.putByStringValue(ConfigProperty.AGENT_SERVICE_KEY, "token:service"); - configContainer.putByStringValue(ConfigProperty.AGENT_EXPORT_METRICS_ENABLED, "true"); - ConfigurationLoader.configureOtelMetricExport(configContainer); + ConfigurationLoader.configureOtel(configContainer); assertEquals( - "https://otel.collector.na-01.cloud.solarwinds.com", - System.getProperty("otel.exporter.otlp.metrics.endpoint")); + "https://custom.endpoint.example.com", System.getProperty("otel.exporter.otlp.endpoint")); } @Test - @SetSystemProperty( - key = "otel.exporter.otlp.endpoint", - value = "https://otel.collector.na-01.cloud.solarwinds.com") - @SetSystemProperty(key = "otel.exporter.otlp.traces.protocol", value = "grpc") - @ClearSystemProperty(key = "otel.exporter.otlp.traces.endpoint") - void verifyTracesEndpointIsProperlyConfiguredForGRPC() throws InvalidConfigException { + @ClearSystemProperty(key = "otel.exporter.otlp.endpoint") + @ClearSystemProperty(key = "otel.exporter.otlp.headers") + void verifyOtelHeadersIsProperlyFormed() throws InvalidConfigException { ConfigContainer configContainer = new ConfigContainer(); configContainer.putByStringValue(ConfigProperty.AGENT_SERVICE_KEY, "token:service"); + configContainer.putByStringValue( + ConfigProperty.AGENT_COLLECTOR, "apm.collector.na-02.staging.solarwinds.com"); - ConfigurationLoader.configureOtelTraceExport(configContainer); - assertEquals( - "https://otel.collector.na-01.cloud.solarwinds.com", - System.getProperty("otel.exporter.otlp.traces.endpoint")); - } - - @Test - @SetSystemProperty( - key = "otel.exporter.otlp.endpoint", - value = "https://otel.collector.na-01.cloud.solarwinds.com") - @SetSystemProperty(key = "otel.exporter.otlp.logs.protocol", value = "grpc") - @ClearSystemProperty(key = "otel.exporter.otlp.logs.endpoint") - void verifyLogsEndpointIsProperlyConfiguredForGRPC() throws InvalidConfigException { - ConfigContainer configContainer = new ConfigContainer(); - configContainer.putByStringValue(ConfigProperty.AGENT_SERVICE_KEY, "token:service"); + ConfigurationLoader.configureOtel(configContainer); - configContainer.putByStringValue(ConfigProperty.AGENT_EXPORT_LOGS_ENABLED, "true"); - ConfigurationLoader.configureOtelLogExport(configContainer); - assertEquals( - "https://otel.collector.na-01.cloud.solarwinds.com", - System.getProperty("otel.exporter.otlp.logs.endpoint")); + assertEquals("authorization=Bearer token", System.getProperty("otel.exporter.otlp.headers")); } @Test diff --git a/libs/lambda/src/main/java/com/solarwinds/opentelemetry/extensions/PropertiesSupplier.java b/libs/lambda/src/main/java/com/solarwinds/opentelemetry/extensions/PropertiesSupplier.java index 386ed85d..e7afe65a 100644 --- a/libs/lambda/src/main/java/com/solarwinds/opentelemetry/extensions/PropertiesSupplier.java +++ b/libs/lambda/src/main/java/com/solarwinds/opentelemetry/extensions/PropertiesSupplier.java @@ -33,7 +33,6 @@ public PropertiesSupplier() { defaultProperties.put("otel.instrumentation.runtime-telemetry.enabled", "false"); defaultProperties.put( "otel.java.experimental.span-stacktrace.filter", SPAN_STACKTRACE_FILTER_CLASS); - defaultProperties.put("otel.exporter.otlp.protocol", "grpc"); defaultProperties.put("otel.semconv-stability.opt-in", "database/dup"); defaultProperties.put("otel.exporter.otlp.metrics.temporality.preference", "delta"); defaultProperties.put(