Skip to content

Commit a17cdf2

Browse files
WIP with tests
1 parent 2127e24 commit a17cdf2

File tree

6 files changed

+66
-104
lines changed

6 files changed

+66
-104
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/BraveAutoConfiguration.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,24 @@ public HttpClientHandler<HttpClientRequest, HttpClientResponse> httpClientHandle
153153

154154
@Configuration(proxyBeanMethods = false)
155155
@ConditionalOnMissingClass("io.micrometer.tracing.brave.bridge.BraveTracer")
156+
@Conditional(OnNonCustomPropagationCondition.class)
156157
static class BraveMicrometerMissing {
157158

158159
@Bean
159160
@ConditionalOnMissingBean
161+
@ConditionalOnProperty(value = "management.tracing.propagation", havingValue = "B3", matchIfMissing = true)
160162
Factory bravePropagationFactory() {
161163
return B3Propagation.newFactoryBuilder().injectFormat(B3Propagation.Format.SINGLE_NO_PARENT).build();
162164
}
163165

166+
@Bean
167+
@ConditionalOnMissingBean
168+
@ConditionalOnProperty(value = "management.tracing.propagation", havingValue = "AWS")
169+
@ConditionalOnClass(AWSPropagation.class)
170+
Factory awsPropagationFactory() {
171+
return AWSPropagation.FACTORY;
172+
}
173+
164174
}
165175

166176
@Configuration(proxyBeanMethods = false)
@@ -191,6 +201,7 @@ BraveHttpClientHandler braveHttpClientHandler(
191201

192202
@Configuration(proxyBeanMethods = false)
193203
@ConditionalOnProperty(value = "management.tracing.baggage.enabled", matchIfMissing = true)
204+
@Conditional(OnNonCustomPropagationCondition.class)
194205
static class BraveBaggageConfiguration {
195206

196207
@Bean
@@ -203,7 +214,7 @@ BaggagePropagation.FactoryBuilder w3cPropagationFactory(TracingProperties tracin
203214

204215
@Bean
205216
@ConditionalOnMissingBean
206-
@ConditionalOnProperty(value = "management.tracing.propagation", havingValue = "B3", matchIfMissing = true)
217+
@ConditionalOnProperty(value = "management.tracing.propagation", havingValue = "B3")
207218
BaggagePropagation.FactoryBuilder b3PropagationFactory() {
208219
return BaggagePropagation.newFactoryBuilder(
209220
B3Propagation.newFactoryBuilder().injectFormat(B3Propagation.Format.SINGLE_NO_PARENT).build());
@@ -219,7 +230,7 @@ BaggagePropagation.FactoryBuilder awsPropagationFactory() {
219230

220231
@Bean
221232
@ConditionalOnMissingBean
222-
Propagation.Factory micrometerTracingPropagationWithB3Baggage(
233+
Propagation.Factory micrometerTracingPropagationWithBaggage(
223234
BaggagePropagation.FactoryBuilder factoryBuilder, TracingProperties tracingProperties,
224235
ObjectProvider<List<BaggagePropagationCustomizer>> baggagePropagationCustomizers) {
225236
List<String> localFields = tracingProperties.getBaggage().getLocalFields();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2012-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.actuate.autoconfigure.tracing;
18+
19+
import org.springframework.boot.autoconfigure.condition.ConditionMessage;
20+
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
21+
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
22+
import org.springframework.context.annotation.Condition;
23+
import org.springframework.context.annotation.ConditionContext;
24+
import org.springframework.core.type.AnnotatedTypeMetadata;
25+
26+
/**
27+
* {@link Condition} that checks if propagation is not {@link TracingProperties.Propagation.PropagationType#CUSTOM}.
28+
*
29+
* @author Marcin Grzejszczak
30+
*/
31+
class OnNonCustomPropagationCondition extends SpringBootCondition {
32+
33+
private static final String PROPERTY_NAME = "management.tracing.propagation.type";
34+
35+
@Override
36+
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
37+
TracingProperties.Propagation.PropagationType type = context.getEnvironment().getProperty(PROPERTY_NAME, TracingProperties.Propagation.PropagationType.class);
38+
return new ConditionOutcome(type != TracingProperties.Propagation.PropagationType.CUSTOM, ConditionMessage.forCondition("Tracing Propagation Type must not be custom")
39+
.because(PROPERTY_NAME + " is " + TracingProperties.Propagation.PropagationType.CUSTOM.name()));
40+
}
41+
42+
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/OpenTelemetryConfigurations.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,8 @@ OtelTracer micrometerOtelTracer(Tracer tracer, EventPublisher eventPublisher,
159159

160160
@Bean
161161
@ConditionalOnMissingBean
162-
EventPublisher otelTracerEventPublisher(TracingProperties tracingProperties) {
163-
return new OTelEventPublisher(List.of(new Slf4JEventListener(),
164-
new Slf4JBaggageEventListener(tracingProperties.getBaggage().getCorrelationFields())));
162+
EventPublisher otelTracerEventPublisher(TracingProperties tracingProperties, List<EventListener> eventListeners) {
163+
return new OTelEventPublisher(eventListeners);
165164
}
166165

167166
@Bean
@@ -205,11 +204,12 @@ public void publishEvent(Object event) {
205204
}
206205

207206
@Configuration(proxyBeanMethods = false)
207+
@Conditional(OnNonCustomPropagationCondition.class)
208208
static class PropagationConfiguration {
209209

210210
@Bean
211211
@ConditionalOnMissingBean
212-
@ConditionalOnProperty(value = "management.tracing.propagation", havingValue = "B3", matchIfMissing = true)
212+
@ConditionalOnProperty(value = "management.tracing.propagation", havingValue = "B3")
213213
B3Propagator b3TextMapPropagator() {
214214
return B3Propagator.injectingSingleHeader();
215215
}
@@ -227,7 +227,7 @@ static class NoBaggagePropagatorConfiguration {
227227

228228
@Bean
229229
@ConditionalOnMissingBean
230-
@ConditionalOnProperty(value = "management.tracing.propagation", havingValue = "W3C")
230+
@ConditionalOnProperty(value = "management.tracing.propagation", havingValue = "W3C", matchIfMissing = true)
231231
W3CTraceContextPropagator w3cTextMapPropagator() {
232232
return W3CTraceContextPropagator.getInstance();
233233
}
@@ -247,7 +247,7 @@ BaggageTextMapPropagator baggageTextMapPropagator(TracingProperties properties,
247247

248248
@Bean
249249
@ConditionalOnMissingBean
250-
@ConditionalOnProperty(value = "management.tracing.propagation", havingValue = "W3C")
250+
@ConditionalOnProperty(value = "management.tracing.propagation", havingValue = "W3C", matchIfMissing = true)
251251
TextMapPropagator w3cTextMapPropagator() {
252252
return TextMapPropagator.composite(W3CTraceContextPropagator.getInstance(),
253253
W3CBaggagePropagator.getInstance());
@@ -287,9 +287,9 @@ static class Slf4jConfiguration {
287287

288288
@Bean
289289
@ConditionalOnMissingBean
290-
OpenTelemetrySlf4jBaggageApplicationListener otelSlf4jBaggageApplicationListener(
290+
Slf4JBaggageEventListener otelSlf4JBaggageEventListener(
291291
TracingProperties tracingProperties) {
292-
return new OpenTelemetrySlf4jBaggageApplicationListener(
292+
return new Slf4JBaggageEventListener(
293293
tracingProperties.getBaggage().getCorrelationFields());
294294
}
295295

@@ -305,8 +305,8 @@ static class Slf4jConfiguration {
305305

306306
@Bean
307307
@ConditionalOnMissingBean
308-
OpenTelemetrySlf4jApplicationListener otelSlf4jApplicationListener() {
309-
return new OpenTelemetrySlf4jApplicationListener();
308+
Slf4JEventListener otelSlf4JEventListener() {
309+
return new Slf4JEventListener();
310310
}
311311

312312
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/OpenTelemetrySlf4jApplicationListener.java

Lines changed: 0 additions & 39 deletions
This file was deleted.

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/OpenTelemetrySlf4jBaggageApplicationListener.java

Lines changed: 0 additions & 45 deletions
This file was deleted.

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/TracingProperties.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ public static class Propagation {
151151
/**
152152
* Tracing context propagation types.
153153
*/
154-
// TODO: Should this be the default?
155-
private PropagationType type = PropagationType.B3;
154+
private PropagationType type = PropagationType.W3C;
156155

157156
public PropagationType getType() {
158157
return this.type;
@@ -179,12 +178,6 @@ enum PropagationType {
179178
*/
180179
W3C,
181180

182-
/**
183-
* Jaeger propagation type.
184-
*/
185-
JAEGER, // TODO: Supported by OTel, not by Brave - my suggestion is not to
186-
// support it
187-
188181
/**
189182
* Custom propagation type. If picked, requires bean registration overriding
190183
* the default propagation mechanisms.

0 commit comments

Comments
 (0)