@@ -78,8 +78,6 @@ public class ConfigurationLoader {
7878 private static final String CONFIG_FILE = "solarwinds-apm-config.json" ;
7979 private static final String SYS_PROPERTIES_PREFIX = "sw.apm" ;
8080
81- private static final String PROTOCOL = "http/protobuf" ;
82-
8381 @ Getter private static String configurationFileDir = null ;
8482
8583 @ Getter private static String runtimeConfigFilename = null ;
@@ -178,7 +176,7 @@ private static void maybeFollowOtelConfigProperties(ConfigContainer configs) {
178176 if (serviceKey != null ) {
179177 String name = ServiceKeyUtils .getServiceName (serviceKey );
180178 if (name != null ) {
181- setSystemProperty ("otel.service.name" , name );
179+ System . setProperty ("otel.service.name" , name );
182180 }
183181 }
184182
@@ -195,54 +193,7 @@ private static void maybeFollowOtelConfigProperties(ConfigContainer configs) {
195193 }
196194 }
197195
198- static void configureOtelLogExport (ConfigContainer container ) throws InvalidConfigException {
199- Boolean exportLog = (Boolean ) container .get (ConfigProperty .AGENT_EXPORT_LOGS_ENABLED );
200- if (exportLog != null && exportLog ) {
201- String serviceKey = (String ) container .get (ConfigProperty .AGENT_SERVICE_KEY );
202- String apiKey = ServiceKeyUtils .getApiKey (serviceKey );
203-
204- String dataCell = "na-01" ;
205- String env = "cloud" ;
206- String collectorEndpoint = (String ) container .get (ConfigProperty .AGENT_COLLECTOR );
207-
208- if (collectorEndpoint != null ) {
209- if (collectorEndpoint .contains ("appoptics.com" )) {
210- throw new InvalidConfigException ("Appoptics is not supported" );
211- }
212- collectorEndpoint = collectorEndpoint .split (":" )[0 ];
213- String [] fragments = collectorEndpoint .split ("\\ ." );
214- if (fragments .length > 2 ) {
215- // This is based on knowledge of the SWO url format where the third name from the left in
216- // the domain is the data-cell name and assumes this format will stay stable.
217- dataCell = fragments [2 ];
218- }
219-
220- if (fragments .length > 3 ) {
221- env = fragments [3 ];
222- }
223- }
224-
225- String protocol = setProtocol ("otel.exporter.otlp.logs.protocol" );
226- setSystemProperty ("otel.logs.exporter" , "otlp" );
227- setSystemProperty (
228- "otel.exporter.otlp.logs.headers" , String .format ("authorization=Bearer %s" , apiKey ));
229-
230- if (protocol .equalsIgnoreCase ("grpc" )) {
231- setEndpoint (
232- "otel.exporter.otlp.logs.endpoint" ,
233- String .format ("https://otel.collector.%s.%s.solarwinds.com" , dataCell , env ),
234- "" );
235- return ;
236- }
237-
238- setEndpoint (
239- "otel.exporter.otlp.logs.endpoint" ,
240- String .format ("https://otel.collector.%s.%s.solarwinds.com/v1/logs" , dataCell , env ),
241- "/v1/logs" );
242- }
243- }
244-
245- static void configureOtelMetricExport (ConfigContainer container ) throws InvalidConfigException {
196+ static void configureOtel (ConfigContainer container ) throws InvalidConfigException {
246197 String serviceKey = (String ) container .get (ConfigProperty .AGENT_SERVICE_KEY );
247198 String apiKey = ServiceKeyUtils .getApiKey (serviceKey );
248199 String dataCell = "na-01" ;
@@ -267,67 +218,16 @@ static void configureOtelMetricExport(ConfigContainer container) throws InvalidC
267218 }
268219 }
269220
270- String protocol = setProtocol ("otel.exporter.otlp.metrics.protocol" );
271- setSystemProperty ("otel.metrics.exporter" , "otlp" );
272- setSystemProperty (
273- "otel.exporter.otlp.metrics.headers" , String .format ("authorization=Bearer %s" , apiKey ));
274-
275- if (protocol .equalsIgnoreCase ("grpc" )) {
276- setEndpoint (
277- "otel.exporter.otlp.metrics.endpoint" ,
278- String .format ("https://otel.collector.%s.%s.solarwinds.com" , dataCell , env ),
279- "" );
280- return ;
281- }
282-
283- setEndpoint (
284- "otel.exporter.otlp.metrics.endpoint" ,
285- String .format ("https://otel.collector.%s.%s.solarwinds.com/v1/metrics" , dataCell , env ),
286- "/v1/metrics" );
287- }
288-
289- static void configureOtelTraceExport (ConfigContainer container ) throws InvalidConfigException {
290- String serviceKey = (String ) container .get (ConfigProperty .AGENT_SERVICE_KEY );
291- String apiKey = ServiceKeyUtils .getApiKey (serviceKey );
292-
293- String dataCell = "na-01" ;
294- String env = "cloud" ;
295- String collectorEndpoint = (String ) container .get (ConfigProperty .AGENT_COLLECTOR );
296-
297- if (collectorEndpoint != null ) {
298- if (collectorEndpoint .contains ("appoptics.com" )) {
299- throw new InvalidConfigException ("Appoptics is not supported" );
300- }
301-
302- collectorEndpoint = collectorEndpoint .split (":" )[0 ];
303- String [] fragments = collectorEndpoint .split ("\\ ." );
304- if (fragments .length > 2 ) {
305- // This is based on knowledge of the SWO url format where the third name from the left in
306- // the domain is the data-cell name and assumes this format will stay stable.
307- dataCell = fragments [2 ];
308- }
309-
310- if (fragments .length > 3 ) {
311- env = fragments [3 ];
312- }
221+ if (isConfigNotSet ("otel.exporter.otlp.headers" )) {
222+ System .setProperty (
223+ "otel.exporter.otlp.headers" , String .format ("authorization=Bearer %s" , apiKey ));
313224 }
314225
315- String protocol = setProtocol ("otel.exporter.otlp.traces.protocol" );
316- setSystemProperty (
317- "otel.exporter.otlp.traces.headers" , String .format ("authorization=Bearer %s" , apiKey ));
318-
319- if (protocol .equalsIgnoreCase ("grpc" )) {
320- setEndpoint (
321- "otel.exporter.otlp.traces.endpoint" ,
322- String .format ("https://otel.collector.%s.%s.solarwinds.com" , dataCell , env ),
323- "" );
324- return ;
226+ if (isConfigNotSet ("otel.exporter.otlp.endpoint" )) {
227+ System .setProperty (
228+ "otel.exporter.otlp.endpoint" ,
229+ String .format ("https://otel.collector.%s.%s.solarwinds.com" , dataCell , env ));
325230 }
326-
327- setEndpoint (
328- "otel.exporter.otlp.traces.endpoint" ,
329- String .format ("https://otel.collector.%s.%s.solarwinds.com/v1/traces" , dataCell , env ),
330- "/v1/traces" );
331231 }
332232
333233 static Map <String , String > mergeEnvWithSysProperties (Map <String , String > env , Properties props ) {
@@ -381,9 +281,7 @@ private static void loadConfigurations() throws InvalidConfigException {
381281 config )); // initialize the logger factory as soon as the config is available
382282 try {
383283 processConfigs (configs );
384- configureOtelLogExport (configs );
385- configureOtelMetricExport (configs );
386- configureOtelTraceExport (configs );
284+ configureOtel (configs );
387285 } catch (InvalidConfigException e ) {
388286 // if there was a config read exception then processConfigs might throw exception due to
389287 // incomplete config container.
@@ -652,47 +550,19 @@ public static void processConfigs(ConfigContainer configs) throws InvalidConfigE
652550 ConfigManager .initialize (configs );
653551 }
654552
655- private static String setSystemProperty (String key , String value ) {
656- String propertyValue = getConfigValue (key );
657- if (propertyValue == null ) {
658- System .setProperty (key , value );
659- return value ;
660- }
661-
662- return propertyValue ;
663- }
664-
665- private static void setEndpoint (String key , String value , String path ) {
666- String endpoint = getConfigValue ("otel.exporter.otlp.endpoint" );
667- if (endpoint == null ) {
668- setSystemProperty (key , value );
669- } else {
670- setSystemProperty (key , String .format ("%s%s" , endpoint , path ));
671- }
672- }
673-
674- private static String setProtocol (String key ) {
675- String protocol = getConfigValue ("otel.exporter.otlp.protocol" );
676- if (protocol == null ) {
677- return setSystemProperty (key , ConfigurationLoader .PROTOCOL );
678- }
679- return protocol ;
680- }
681-
682553 static String normalize (String key ) {
683554 return key .toUpperCase ().replace ("." , "_" );
684555 }
685556
686- private static String getConfigValue (String key ) {
557+ private static boolean isConfigNotSet (String key ) {
687558 String propertyValue = System .getProperty (key );
688559 if (propertyValue == null ) {
689560 propertyValue = System .getenv (normalize (key ));
690561 }
691-
692- return propertyValue ;
562+ return propertyValue == null ;
693563 }
694564
695565 private static boolean isDeclarativeConfigOff () {
696- return getConfigValue ("otel.experimental.config.file" ) == null ;
566+ return isConfigNotSet ("otel.experimental.config.file" );
697567 }
698568}
0 commit comments