|
10 | 10 | import io.opentelemetry.sdk.autoconfigure.internal.NamedSpiManager; |
11 | 11 | import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper; |
12 | 12 | import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; |
13 | | -import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException; |
14 | 13 | import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; |
15 | 14 | import io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSamplerProvider; |
16 | 15 | import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.JaegerRemote; |
@@ -116,16 +115,38 @@ public Sampler create( |
116 | 115 | "jaeger remote sampler")); |
117 | 116 | } |
118 | 117 |
|
119 | | - // TODO(jack-berg): add support for generic SPI samplers |
120 | | - if (!model.getAdditionalProperties().isEmpty()) { |
121 | | - throw new ConfigurationException( |
122 | | - "Unrecognized sampler(s): " |
123 | | - + model.getAdditionalProperties().keySet().stream().collect(joining(",", "[", "]"))); |
| 118 | + Map<String, Object> additionalProperties = model.getAdditionalProperties(); |
| 119 | + if (!additionalProperties.isEmpty()) { |
| 120 | + for (Map.Entry<String, Object> entry : additionalProperties.entrySet()) { |
| 121 | + String samplerName = entry.getKey(); |
| 122 | + ConfigProperties configProperties = |
| 123 | + new ExtendedConfigProperties(toConfigMap(entry.getValue())); |
| 124 | + return FileConfigUtil.addAndReturn( |
| 125 | + closeables, |
| 126 | + FileConfigUtil.assertNotNull( |
| 127 | + samplerSpiManager(configProperties, spiHelper).getByName(samplerName), |
| 128 | + samplerName)); |
| 129 | + } |
124 | 130 | } |
125 | 131 |
|
126 | 132 | return Sampler.parentBased(Sampler.alwaysOn()); |
127 | 133 | } |
128 | 134 |
|
| 135 | + private static Map<String, Object> toConfigMap(Object object) { |
| 136 | + if (!(object instanceof Map)) { |
| 137 | + return Collections.emptyMap(); |
| 138 | + } |
| 139 | + Map<String, Object> map = new HashMap<>(); |
| 140 | + for (Map.Entry<?, ?> entry : ((Map<?, ?>) object).entrySet()) { |
| 141 | + Object key = entry.getKey(); |
| 142 | + if (!(key instanceof String)) { |
| 143 | + continue; |
| 144 | + } |
| 145 | + map.put((String) key, entry.getValue()); |
| 146 | + } |
| 147 | + return Collections.unmodifiableMap(map); |
| 148 | + } |
| 149 | + |
129 | 150 | private static NamedSpiManager<Sampler> samplerSpiManager( |
130 | 151 | ConfigProperties config, SpiHelper spiHelper) { |
131 | 152 | return spiHelper.loadConfigurable( |
|
0 commit comments