17
17
package org .springframework .boot .actuate .autoconfigure .tracing ;
18
18
19
19
import java .util .ArrayList ;
20
+ import java .util .Collection ;
20
21
import java .util .Collections ;
21
22
import java .util .List ;
22
23
56
57
import io .micrometer .tracing .exporter .SpanReporter ;
57
58
58
59
import org .springframework .beans .factory .ObjectProvider ;
60
+ import org .springframework .boot .actuate .autoconfigure .tracing .TracingProperties .Propagation .PropagationType ;
59
61
import org .springframework .boot .autoconfigure .AutoConfiguration ;
60
62
import org .springframework .boot .autoconfigure .EnableAutoConfiguration ;
61
63
import org .springframework .boot .autoconfigure .condition .ConditionalOnClass ;
81
83
@ ConditionalOnEnabledTracing
82
84
public class BraveAutoConfiguration {
83
85
86
+ private static final BraveBaggageManager BRAVE_BAGGAGE_MANAGER = new BraveBaggageManager ();
87
+
84
88
/**
85
89
* Default value for application name if {@code spring.application.name} is not set.
86
90
*/
@@ -95,25 +99,19 @@ CompositeSpanHandler compositeSpanHandler(ObjectProvider<SpanExportingPredicate>
95
99
filters .orderedStream ().toList ());
96
100
}
97
101
98
- @ Bean
99
- @ ConditionalOnMissingBean
100
- BraveBaggageManager braveBaggageManager () {
101
- return new BraveBaggageManager ();
102
- }
103
-
104
102
@ Bean
105
103
@ ConditionalOnMissingBean
106
104
public Tracing braveTracing (Environment environment , List <SpanHandler > spanHandlers ,
107
105
List <TracingCustomizer > tracingCustomizers , CurrentTraceContext currentTraceContext ,
108
106
Factory propagationFactory , Sampler sampler ) {
109
107
String applicationName = environment .getProperty ("spring.application.name" , DEFAULT_APPLICATION_NAME );
110
108
Builder builder = Tracing .newBuilder ()
111
- .currentTraceContext (currentTraceContext )
112
- .traceId128Bit (true )
113
- .supportsJoin (false )
114
- .propagationFactory (propagationFactory )
115
- .sampler (sampler )
116
- .localServiceName (applicationName );
109
+ .currentTraceContext (currentTraceContext )
110
+ .traceId128Bit (true )
111
+ .supportsJoin (false )
112
+ .propagationFactory (propagationFactory )
113
+ .sampler (sampler )
114
+ .localServiceName (applicationName );
117
115
spanHandlers .forEach (builder ::addSpanHandler );
118
116
for (TracingCustomizer tracingCustomizer : tracingCustomizers ) {
119
117
tracingCustomizer .customize (builder );
@@ -147,9 +145,8 @@ public Sampler braveSampler(TracingProperties properties) {
147
145
148
146
@ Bean
149
147
@ ConditionalOnMissingBean (io .micrometer .tracing .Tracer .class )
150
- BraveTracer braveTracerBridge (brave .Tracer tracer , CurrentTraceContext currentTraceContext ,
151
- BraveBaggageManager braveBaggageManager ) {
152
- return new BraveTracer (tracer , new BraveCurrentTraceContext (currentTraceContext ), braveBaggageManager );
148
+ BraveTracer braveTracerBridge (brave .Tracer tracer , CurrentTraceContext currentTraceContext ) {
149
+ return new BraveTracer (tracer , new BraveCurrentTraceContext (currentTraceContext ), BRAVE_BAGGAGE_MANAGER );
153
150
}
154
151
155
152
@ Bean
@@ -176,19 +173,10 @@ static class BraveNoBaggageConfiguration {
176
173
177
174
@ Bean
178
175
@ ConditionalOnMissingBean
179
- ExtractorFactories extractorFactories () {
180
- return ExtractorFactories .of (PropagationFactoryFactory .factoriesFor (PropagationType .values ()));
181
- }
182
-
183
- @ Bean
184
- @ ConditionalOnMissingBean
185
- InjectorFactories injectorFactories (TracingProperties tracing ) {
186
- return InjectorFactories .of (PropagationFactoryFactory .factoriesFor (tracing .getPropagation ().getType ()));
187
- }
188
-
189
- @ Bean
190
- @ ConditionalOnMissingBean
191
- Factory propagationFactory (InjectorFactories injectorFactories , ExtractorFactories extractorFactories ) {
176
+ Factory propagationFactory (TracingProperties properties ) {
177
+ Iterable <Factory > injectorFactories = PropagationFactoryFactory
178
+ .factoriesFor (properties .getPropagation ().getType ());
179
+ Iterable <Factory > extractorFactories = PropagationFactoryFactory .factoriesFor (PropagationType .values ());
192
180
return new CompositePropagationFactory (injectorFactories , extractorFactories );
193
181
}
194
182
@@ -204,25 +192,14 @@ static class BraveBaggageConfiguration {
204
192
this .tracingProperties = tracingProperties ;
205
193
}
206
194
207
- @ Bean
208
- @ ConditionalOnMissingBean
209
- ExtractorFactories extractorFactories (BraveBaggageManager braveBaggageManager ) {
210
- return ExtractorFactories
211
- .of (PropagationFactoryFactory .factoriesFor (braveBaggageManager , PropagationType .values ()));
212
- }
213
-
214
- @ Bean
215
- @ ConditionalOnMissingBean
216
- InjectorFactories injectorFactories (BraveBaggageManager braveBaggageManager ) {
217
- return InjectorFactories .of (PropagationFactoryFactory .factoriesFor (braveBaggageManager ,
218
- this .tracingProperties .getPropagation ().getType ()));
219
- }
220
-
221
195
@ Bean
222
196
@ ConditionalOnMissingBean
223
197
BaggagePropagation .FactoryBuilder propagationFactoryBuilder (
224
- ObjectProvider <BaggagePropagationCustomizer > baggagePropagationCustomizers ,
225
- InjectorFactories injectorFactories , ExtractorFactories extractorFactories ) {
198
+ ObjectProvider <BaggagePropagationCustomizer > baggagePropagationCustomizers ) {
199
+ Iterable <Factory > injectorFactories = PropagationFactoryFactory .factoriesFor (BRAVE_BAGGAGE_MANAGER ,
200
+ this .tracingProperties .getPropagation ().getType ());
201
+ Iterable <Factory > extractorFactories = PropagationFactoryFactory .factoriesFor (BRAVE_BAGGAGE_MANAGER ,
202
+ PropagationType .values ());
226
203
Factory delegate = new CompositePropagationFactory (injectorFactories , extractorFactories );
227
204
FactoryBuilder builder = BaggagePropagation .newFactoryBuilder (delegate );
228
205
baggagePropagationCustomizers .orderedStream ().forEach ((customizer ) -> customizer .customize (builder ));
@@ -264,8 +241,8 @@ CorrelationScopeCustomizer correlationFieldsCorrelationScopeCustomizer() {
264
241
List <String > correlationFields = this .tracingProperties .getBaggage ().getCorrelation ().getFields ();
265
242
for (String field : correlationFields ) {
266
243
builder .add (CorrelationScopeConfig .SingleCorrelationField .newBuilder (BaggageField .create (field ))
267
- .flushOnUpdate ()
268
- .build ());
244
+ .flushOnUpdate ()
245
+ .build ());
269
246
}
270
247
};
271
248
}
@@ -278,60 +255,6 @@ ScopeDecorator correlationScopeDecorator(CorrelationScopeDecorator.Builder build
278
255
279
256
}
280
257
281
- /**
282
- * A collection of {@link Factory factories} used for trace context extraction.
283
- *
284
- * @author Moritz Halbritter
285
- * @since 3.0.8
286
- */
287
- public interface ExtractorFactories extends Iterable <Factory > {
288
-
289
- /**
290
- * Creates an {@link ExtractorFactories} object from the given factories.
291
- * @param factories factories
292
- * @return {@link ExtractorFactories} object
293
- */
294
- static ExtractorFactories of (Iterable <Factory > factories ) {
295
- return factories ::iterator ;
296
- }
297
-
298
- static ExtractorFactories of (PropagationType ... types ) {
299
- return of (PropagationFactoryFactory .factoriesFor (types ));
300
- }
301
-
302
- static ExtractorFactories of (BaggageManager baggageManager , PropagationType ... types ) {
303
- return of (PropagationFactoryFactory .factoriesFor (baggageManager , types ));
304
- }
305
-
306
- }
307
-
308
- /**
309
- * A collection of {@link Factory factories} used for trace context injection.
310
- *
311
- * @author Moritz Halbritter
312
- * @since 3.0.8
313
- */
314
- public interface InjectorFactories extends Iterable <Factory > {
315
-
316
- /**
317
- * Creates an {@link InjectorFactories} object from the given factories.
318
- * @param factories factories
319
- * @return {@link InjectorFactories} object
320
- */
321
- static InjectorFactories of (Iterable <Factory > factories ) {
322
- return factories ::iterator ;
323
- }
324
-
325
- static InjectorFactories of (PropagationType ... types ) {
326
- return of (PropagationFactoryFactory .factoriesFor (types ));
327
- }
328
-
329
- static InjectorFactories of (BaggageManager baggageManager , PropagationType ... types ) {
330
- return of (PropagationFactoryFactory .factoriesFor (baggageManager , types ));
331
- }
332
-
333
- }
334
-
335
258
/**
336
259
* Factory for {@link Factory propagation factories}.
337
260
*/
@@ -365,10 +288,18 @@ private static Factory forType(BaggageManager baggageManager, PropagationType ty
365
288
};
366
289
}
367
290
291
+ private static List <Factory > factoriesFor (Collection <PropagationType > types ) {
292
+ return factoriesFor (null , types .toArray (PropagationType []::new ));
293
+ }
294
+
368
295
private static List <Factory > factoriesFor (PropagationType ... types ) {
369
296
return factoriesFor (null , types );
370
297
}
371
298
299
+ private static List <Factory > factoriesFor (BaggageManager baggageManager , Collection <PropagationType > types ) {
300
+ return factoriesFor (baggageManager , types .toArray (PropagationType []::new ));
301
+ }
302
+
372
303
private static List <Factory > factoriesFor (BaggageManager baggageManager , PropagationType ... types ) {
373
304
List <Factory > result = new ArrayList <>(types .length );
374
305
for (PropagationType type : types ) {
0 commit comments