16
16
17
17
package org .springframework .boot .actuate .autoconfigure .tracing ;
18
18
19
- import java .util .ArrayList ;
20
- import java .util .Arrays ;
21
- import java .util .Collection ;
22
19
import java .util .Collections ;
23
20
import java .util .List ;
24
21
35
32
import io .micrometer .tracing .otel .bridge .Slf4JEventListener ;
36
33
import io .micrometer .tracing .otel .propagation .BaggageTextMapPropagator ;
37
34
import io .opentelemetry .api .OpenTelemetry ;
38
- import io .opentelemetry .api .baggage .propagation .W3CBaggagePropagator ;
39
35
import io .opentelemetry .api .common .Attributes ;
40
36
import io .opentelemetry .api .trace .Tracer ;
41
- import io .opentelemetry .api .trace .propagation .W3CTraceContextPropagator ;
42
37
import io .opentelemetry .context .ContextStorage ;
43
38
import io .opentelemetry .context .propagation .ContextPropagators ;
44
39
import io .opentelemetry .context .propagation .TextMapPropagator ;
45
- import io .opentelemetry .extension .trace .propagation .B3Propagator ;
46
40
import io .opentelemetry .sdk .OpenTelemetrySdk ;
47
41
import io .opentelemetry .sdk .resources .Resource ;
48
42
import io .opentelemetry .sdk .trace .SdkTracerProvider ;
55
49
56
50
import org .springframework .beans .factory .ObjectProvider ;
57
51
import org .springframework .boot .SpringBootVersion ;
58
- import org .springframework .boot .actuate .autoconfigure .tracing .TracingProperties .Propagation .PropagationType ;
59
52
import org .springframework .boot .autoconfigure .AutoConfiguration ;
60
53
import org .springframework .boot .autoconfigure .EnableAutoConfiguration ;
61
54
import org .springframework .boot .autoconfigure .condition .ConditionalOnClass ;
@@ -194,11 +187,8 @@ TextMapPropagator textMapPropagatorWithBaggage(OtelCurrentTraceContext otelCurre
194
187
List <String > remoteFields = this .tracingProperties .getBaggage ().getRemoteFields ();
195
188
BaggageTextMapPropagator baggagePropagator = new BaggageTextMapPropagator (remoteFields ,
196
189
new OtelBaggageManager (otelCurrentTraceContext , remoteFields , Collections .emptyList ()));
197
- List <TextMapPropagator > injectors = new ArrayList <>(
198
- TextMapPropagatorFactory .forTypes (this .tracingProperties .getPropagation ().getType (), true ));
199
- injectors .add (baggagePropagator );
200
- List <TextMapPropagator > extractors = TextMapPropagatorFactory .forTypes (PropagationType .values (), true );
201
- return new CompositeTextMapPropagator (injectors , extractors , List .of (baggagePropagator ));
190
+ return CompositeTextMapPropagator .create (baggagePropagator ,
191
+ this .tracingProperties .getPropagation ().getType ());
202
192
}
203
193
204
194
@ Bean
@@ -217,10 +207,7 @@ static class NoBaggageConfiguration {
217
207
218
208
@ Bean
219
209
TextMapPropagator textMapPropagator (TracingProperties properties ) {
220
- List <TextMapPropagator > injectors = TextMapPropagatorFactory .forTypes (properties .getPropagation ().getType (),
221
- false );
222
- List <TextMapPropagator > extractors = TextMapPropagatorFactory .forTypes (PropagationType .values (), false );
223
- return new CompositeTextMapPropagator (injectors , extractors );
210
+ return CompositeTextMapPropagator .create (properties .getPropagation ().getType ());
224
211
}
225
212
226
213
}
@@ -242,63 +229,4 @@ public void publishEvent(Object event) {
242
229
243
230
}
244
231
245
- /**
246
- * Factory for {@link TextMapPropagator TextMapPropagators}.
247
- */
248
- private static final class TextMapPropagatorFactory {
249
-
250
- private TextMapPropagatorFactory () {
251
- }
252
-
253
- /**
254
- * Creates a new B3 propagator using a single B3 header.
255
- * @return the B3 propagator
256
- */
257
- private static TextMapPropagator b3Single () {
258
- return B3Propagator .injectingSingleHeader ();
259
- }
260
-
261
- /**
262
- * Creates a new B3 propagator using multiple B3 headers.
263
- * @return the B3 propagator
264
- */
265
- private static TextMapPropagator b3Multi () {
266
- return B3Propagator .injectingMultiHeaders ();
267
- }
268
-
269
- /**
270
- * Creates a new W3C propagator.
271
- * @param baggage whether baggage propagation should be supported
272
- * @return the W3C propagator
273
- */
274
- private static TextMapPropagator w3c (boolean baggage ) {
275
- if (!baggage ) {
276
- return W3CTraceContextPropagator .getInstance ();
277
- }
278
- return TextMapPropagator .composite (W3CTraceContextPropagator .getInstance (),
279
- W3CBaggagePropagator .getInstance ());
280
- }
281
-
282
- private static TextMapPropagator forType (PropagationType type , boolean baggage ) {
283
- return switch (type ) {
284
- case B3 -> b3Single ();
285
- case B3_MULTI -> b3Multi ();
286
- case W3C -> w3c (baggage );
287
- };
288
- }
289
-
290
- private static List <TextMapPropagator > forTypes (Collection <PropagationType > types , boolean baggage ) {
291
- List <TextMapPropagator > result = new ArrayList <>(types .size ());
292
- for (PropagationType type : types ) {
293
- result .add (forType (type , baggage ));
294
- }
295
- return result ;
296
- }
297
-
298
- private static List <TextMapPropagator > forTypes (PropagationType [] types , boolean baggage ) {
299
- return forTypes (Arrays .stream (types ).toList (), baggage );
300
- }
301
-
302
- }
303
-
304
232
}
0 commit comments