|
25 | 25 | import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder; |
26 | 26 | import java.text.MessageFormat; |
27 | 27 | import java.time.Duration; |
28 | | -import java.util.HashMap; |
29 | 28 | import java.util.HashSet; |
30 | 29 | import java.util.Map; |
31 | 30 | import java.util.Set; |
32 | 31 | import java.util.logging.Logger; |
| 32 | +import java.util.stream.Collectors; |
| 33 | +import java.util.stream.Stream; |
33 | 34 |
|
34 | 35 | public class CentralConfig { |
35 | 36 | private static final Logger logger = Logger.getLogger(CentralConfig.class.getName()); |
@@ -98,18 +99,19 @@ private static String getServiceName(ConfigProperties properties) { |
98 | 99 | } |
99 | 100 |
|
100 | 101 | public static class Configs { |
101 | | - private static final Map<String, ConfigOption> configNameToConfig = new HashMap<>(); |
| 102 | + private static final Map<String, ConfigOption> configNameToConfig; |
102 | 103 | private static final Set<String> currentNonDefaultConfigsApplied = new HashSet<>(); |
103 | 104 |
|
104 | 105 | static { |
105 | | - ConfigOption option; |
106 | | - configNameToConfig.put((option = new SendLogs()).getConfigName(), option); |
107 | | - configNameToConfig.put((option = new SendMetrics()).getConfigName(), option); |
108 | | - configNameToConfig.put((option = new SendTraces()).getConfigName(), option); |
109 | | - configNameToConfig.put( |
110 | | - (option = new DeactivateAllInstrumentations()).getConfigName(), option); |
111 | | - configNameToConfig.put((option = new DeactivateInstrumentations()).getConfigName(), option); |
112 | | - configNameToConfig.put((option = new LoggingLevel()).getConfigName(), option); |
| 106 | + configNameToConfig = |
| 107 | + Stream.of( |
| 108 | + new SendLogs(), |
| 109 | + new SendMetrics(), |
| 110 | + new SendTraces(), |
| 111 | + new DeactivateAllInstrumentations(), |
| 112 | + new DeactivateInstrumentations(), |
| 113 | + new LoggingLevel()) |
| 114 | + .collect(Collectors.toMap(ConfigOption::getConfigName, option -> option)); |
113 | 115 | } |
114 | 116 |
|
115 | 117 | public static synchronized void applyConfigurations(Map<String, String> configuration) { |
|
0 commit comments