|
24 | 24 | import brave.Tracing;
|
25 | 25 | import brave.Tracing.Builder;
|
26 | 26 | import brave.TracingCustomizer;
|
27 |
| -import brave.baggage.BaggageField; |
28 |
| -import brave.baggage.BaggagePropagation; |
29 |
| -import brave.baggage.BaggagePropagation.FactoryBuilder; |
30 |
| -import brave.baggage.BaggagePropagationConfig; |
31 |
| -import brave.baggage.BaggagePropagationCustomizer; |
32 |
| -import brave.baggage.CorrelationScopeConfig.SingleCorrelationField; |
33 |
| -import brave.baggage.CorrelationScopeCustomizer; |
34 |
| -import brave.baggage.CorrelationScopeDecorator; |
35 |
| -import brave.context.slf4j.MDCScopeDecorator; |
36 | 27 | import brave.handler.SpanHandler;
|
37 | 28 | import brave.propagation.CurrentTraceContext;
|
38 |
| -import brave.propagation.CurrentTraceContext.ScopeDecorator; |
39 | 29 | import brave.propagation.CurrentTraceContextCustomizer;
|
40 |
| -import brave.propagation.Propagation; |
41 | 30 | import brave.propagation.Propagation.Factory;
|
42 |
| -import brave.propagation.Propagation.KeyFactory; |
43 | 31 | import brave.propagation.ThreadLocalCurrentTraceContext;
|
44 | 32 | import brave.sampler.Sampler;
|
45 | 33 | import io.micrometer.tracing.brave.bridge.BraveBaggageManager;
|
|
53 | 41 | import io.micrometer.tracing.exporter.SpanReporter;
|
54 | 42 |
|
55 | 43 | import org.springframework.beans.factory.ObjectProvider;
|
56 |
| -import org.springframework.boot.actuate.autoconfigure.tracing.TracingProperties.Baggage.Correlation; |
57 | 44 | import org.springframework.boot.actuate.autoconfigure.tracing.TracingProperties.Propagation.PropagationType;
|
58 | 45 | import org.springframework.boot.autoconfigure.AutoConfiguration;
|
59 | 46 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
60 | 47 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
61 | 48 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
62 |
| -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
63 | 49 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
64 | 50 | import org.springframework.boot.context.properties.IncompatibleConfigurationException;
|
65 | 51 | import org.springframework.context.annotation.Bean;
|
66 |
| -import org.springframework.context.annotation.Configuration; |
| 52 | +import org.springframework.context.annotation.Import; |
67 | 53 | import org.springframework.core.Ordered;
|
68 | 54 | import org.springframework.core.annotation.Order;
|
69 | 55 | import org.springframework.core.env.Environment;
|
|
79 | 65 | @AutoConfiguration(before = MicrometerTracingAutoConfiguration.class)
|
80 | 66 | @ConditionalOnClass({ Tracer.class, BraveTracer.class })
|
81 | 67 | @EnableConfigurationProperties(TracingProperties.class)
|
| 68 | +@Import({ BravePropagationConfigurations.PropagationWithoutBaggage.class, |
| 69 | + BravePropagationConfigurations.PropagationWithBaggage.class, |
| 70 | + BravePropagationConfigurations.NoPropagation.class }) |
82 | 71 | public class BraveAutoConfiguration {
|
83 | 72 |
|
84 |
| - private static final BraveBaggageManager BRAVE_BAGGAGE_MANAGER = new BraveBaggageManager(); |
| 73 | + static final BraveBaggageManager BRAVE_BAGGAGE_MANAGER = new BraveBaggageManager(); |
85 | 74 |
|
86 | 75 | /**
|
87 | 76 | * Default value for application name if {@code spring.application.name} is not set.
|
@@ -182,108 +171,4 @@ BraveSpanCustomizer braveSpanCustomizer(SpanCustomizer spanCustomizer) {
|
182 | 171 | return new BraveSpanCustomizer(spanCustomizer);
|
183 | 172 | }
|
184 | 173 |
|
185 |
| - @Configuration(proxyBeanMethods = false) |
186 |
| - @ConditionalOnProperty(value = "management.tracing.baggage.enabled", havingValue = "false") |
187 |
| - static class BraveNoBaggageConfiguration { |
188 |
| - |
189 |
| - @Bean |
190 |
| - @ConditionalOnMissingBean |
191 |
| - Factory propagationFactory(TracingProperties properties) { |
192 |
| - return CompositePropagationFactory.create(properties.getPropagation()); |
193 |
| - } |
194 |
| - |
195 |
| - } |
196 |
| - |
197 |
| - @Configuration(proxyBeanMethods = false) |
198 |
| - @ConditionalOnProperty(value = "management.tracing.baggage.enabled", matchIfMissing = true) |
199 |
| - static class BraveBaggageConfiguration { |
200 |
| - |
201 |
| - private final TracingProperties tracingProperties; |
202 |
| - |
203 |
| - BraveBaggageConfiguration(TracingProperties tracingProperties) { |
204 |
| - this.tracingProperties = tracingProperties; |
205 |
| - } |
206 |
| - |
207 |
| - @Bean |
208 |
| - @ConditionalOnMissingBean |
209 |
| - BaggagePropagation.FactoryBuilder propagationFactoryBuilder( |
210 |
| - ObjectProvider<BaggagePropagationCustomizer> baggagePropagationCustomizers) { |
211 |
| - // There's a chicken-and-egg problem here: to create a builder, we need a |
212 |
| - // factory. But the CompositePropagationFactory needs data from the builder. |
213 |
| - // We create a throw-away builder with a throw-away factory, and then copy the |
214 |
| - // config to the real builder. |
215 |
| - FactoryBuilder throwAwayBuilder = BaggagePropagation.newFactoryBuilder(createThrowAwayFactory()); |
216 |
| - baggagePropagationCustomizers.orderedStream() |
217 |
| - .forEach((customizer) -> customizer.customize(throwAwayBuilder)); |
218 |
| - CompositePropagationFactory propagationFactory = CompositePropagationFactory.create( |
219 |
| - this.tracingProperties.getPropagation(), BRAVE_BAGGAGE_MANAGER, |
220 |
| - LocalBaggageFields.extractFrom(throwAwayBuilder)); |
221 |
| - FactoryBuilder builder = BaggagePropagation.newFactoryBuilder(propagationFactory); |
222 |
| - throwAwayBuilder.configs().forEach(builder::add); |
223 |
| - return builder; |
224 |
| - } |
225 |
| - |
226 |
| - @SuppressWarnings("deprecation") |
227 |
| - private Factory createThrowAwayFactory() { |
228 |
| - return new Factory() { |
229 |
| - |
230 |
| - @Override |
231 |
| - public <K> Propagation<K> create(KeyFactory<K> keyFactory) { |
232 |
| - return null; |
233 |
| - } |
234 |
| - |
235 |
| - }; |
236 |
| - } |
237 |
| - |
238 |
| - @Bean |
239 |
| - @Order(0) |
240 |
| - BaggagePropagationCustomizer remoteFieldsBaggagePropagationCustomizer() { |
241 |
| - return (builder) -> { |
242 |
| - List<String> remoteFields = this.tracingProperties.getBaggage().getRemoteFields(); |
243 |
| - for (String fieldName : remoteFields) { |
244 |
| - builder.add(BaggagePropagationConfig.SingleBaggageField.remote(BaggageField.create(fieldName))); |
245 |
| - } |
246 |
| - }; |
247 |
| - } |
248 |
| - |
249 |
| - @Bean |
250 |
| - @ConditionalOnMissingBean |
251 |
| - Factory propagationFactory(BaggagePropagation.FactoryBuilder factoryBuilder) { |
252 |
| - return factoryBuilder.build(); |
253 |
| - } |
254 |
| - |
255 |
| - @Bean |
256 |
| - @ConditionalOnMissingBean |
257 |
| - CorrelationScopeDecorator.Builder mdcCorrelationScopeDecoratorBuilder( |
258 |
| - ObjectProvider<CorrelationScopeCustomizer> correlationScopeCustomizers) { |
259 |
| - CorrelationScopeDecorator.Builder builder = MDCScopeDecorator.newBuilder(); |
260 |
| - correlationScopeCustomizers.orderedStream().forEach((customizer) -> customizer.customize(builder)); |
261 |
| - return builder; |
262 |
| - } |
263 |
| - |
264 |
| - @Bean |
265 |
| - @Order(0) |
266 |
| - @ConditionalOnProperty(prefix = "management.tracing.baggage.correlation", name = "enabled", |
267 |
| - matchIfMissing = true) |
268 |
| - CorrelationScopeCustomizer correlationFieldsCorrelationScopeCustomizer() { |
269 |
| - return (builder) -> { |
270 |
| - Correlation correlationProperties = this.tracingProperties.getBaggage().getCorrelation(); |
271 |
| - for (String field : correlationProperties.getFields()) { |
272 |
| - BaggageField baggageField = BaggageField.create(field); |
273 |
| - SingleCorrelationField correlationField = SingleCorrelationField.newBuilder(baggageField) |
274 |
| - .flushOnUpdate() |
275 |
| - .build(); |
276 |
| - builder.add(correlationField); |
277 |
| - } |
278 |
| - }; |
279 |
| - } |
280 |
| - |
281 |
| - @Bean |
282 |
| - @ConditionalOnMissingBean(CorrelationScopeDecorator.class) |
283 |
| - ScopeDecorator correlationScopeDecorator(CorrelationScopeDecorator.Builder builder) { |
284 |
| - return builder.build(); |
285 |
| - } |
286 |
| - |
287 |
| - } |
288 |
| - |
289 | 174 | }
|
0 commit comments