Skip to content

Commit a2796f1

Browse files
committed
Add distinct properties for consumed and produced propagation types
1 parent 33bcabb commit a2796f1

File tree

5 files changed

+132
-17
lines changed

5 files changed

+132
-17
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ static class BraveNoBaggageConfiguration {
167167
@Bean
168168
@ConditionalOnMissingBean
169169
Factory propagationFactory(TracingProperties properties) {
170-
return CompositePropagationFactory.create(properties.getPropagation().getType(),
171-
properties.getPropagation().getConsumeTypes());
170+
return CompositePropagationFactory.create(properties.getPropagation().getEffectiveProduceTypes(),
171+
properties.getPropagation().getEffectiveConsumeTypes());
172172
}
173173

174174
}
@@ -188,8 +188,8 @@ static class BraveBaggageConfiguration {
188188
BaggagePropagation.FactoryBuilder propagationFactoryBuilder(
189189
ObjectProvider<BaggagePropagationCustomizer> baggagePropagationCustomizers) {
190190
Factory delegate = CompositePropagationFactory.create(BRAVE_BAGGAGE_MANAGER,
191-
this.tracingProperties.getPropagation().getType(),
192-
this.tracingProperties.getPropagation().getConsumeTypes());
191+
this.tracingProperties.getPropagation().getEffectiveProduceTypes(),
192+
this.tracingProperties.getPropagation().getEffectiveConsumeTypes());
193193
FactoryBuilder builder = BaggagePropagation.newFactoryBuilder(delegate);
194194
baggagePropagationCustomizers.orderedStream().forEach((customizer) -> customizer.customize(builder));
195195
return builder;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ TextMapPropagator textMapPropagatorWithBaggage(OtelCurrentTraceContext otelCurre
188188
BaggageTextMapPropagator baggagePropagator = new BaggageTextMapPropagator(remoteFields,
189189
new OtelBaggageManager(otelCurrentTraceContext, remoteFields, Collections.emptyList()));
190190
return CompositeTextMapPropagator.create(baggagePropagator,
191-
this.tracingProperties.getPropagation().getType(),
192-
this.tracingProperties.getPropagation().getConsumeTypes());
191+
this.tracingProperties.getPropagation().getEffectiveProduceTypes(),
192+
this.tracingProperties.getPropagation().getEffectiveConsumeTypes());
193193
}
194194

195195
@Bean
@@ -208,8 +208,8 @@ static class NoBaggageConfiguration {
208208

209209
@Bean
210210
TextMapPropagator textMapPropagator(TracingProperties properties) {
211-
return CompositeTextMapPropagator.create(properties.getPropagation().getType(),
212-
properties.getPropagation().getConsumeTypes());
211+
return CompositeTextMapPropagator.create(properties.getPropagation().getEffectiveProduceTypes(),
212+
properties.getPropagation().getEffectiveConsumeTypes());
213213
}
214214

215215
}

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

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,29 +165,68 @@ public void setFields(List<String> fields) {
165165

166166
public static class Propagation {
167167

168+
/**
169+
* Tracing context propagation types produced and consumed by the application.
170+
* Setting this property overrides the more fine-grained propagation type
171+
* properties.
172+
*/
173+
private List<PropagationType> type;
174+
168175
/**
169176
* Tracing context propagation types produced by the application.
170177
*/
171-
private List<PropagationType> type = List.of(PropagationType.W3C);
178+
private List<PropagationType> produceTypes = List.of(PropagationType.W3C);
172179

173180
/**
174181
* Tracing context propagation types consumed by the application.
175182
*/
176183
private List<PropagationType> consumeTypes = List.of(PropagationType.values());
177184

185+
public void setType(List<PropagationType> type) {
186+
this.type = type;
187+
}
188+
189+
public void setProduceTypes(List<PropagationType> produceTypes) {
190+
this.produceTypes = produceTypes;
191+
}
192+
193+
public void setConsumeTypes(List<PropagationType> consumeTypes) {
194+
this.consumeTypes = consumeTypes;
195+
}
196+
178197
public List<PropagationType> getType() {
179198
return this.type;
180199
}
181200

182-
public void setType(List<PropagationType> type) {
183-
this.type = type;
201+
public List<PropagationType> getProduceTypes() {
202+
return this.produceTypes;
184203
}
185204

186-
void setConsumeTypes(List<PropagationType> consumeTypes) {
187-
this.consumeTypes = consumeTypes;
205+
public List<PropagationType> getConsumeTypes() {
206+
return this.consumeTypes;
207+
}
208+
209+
/**
210+
* Returns the effective context propagation types produced by the application.
211+
* This will be {@link #getType()} if set or {@link #getProduceTypes()} otherwise.
212+
* @return the effective context propagation types produced by the application
213+
*/
214+
List<PropagationType> getEffectiveProduceTypes() {
215+
if (this.type != null) {
216+
return this.type;
217+
}
218+
return this.produceTypes;
188219
}
189220

190-
List<PropagationType> getConsumeTypes() {
221+
/**
222+
* Returns the effective context propagation types consumed by the application.
223+
* This will be {@link #getType()} if set or {@link #getConsumeTypes()} otherwise.
224+
* @return the effective context propagation types consumed by the application
225+
*/
226+
List<PropagationType> getEffectiveConsumeTypes() {
227+
if (this.type != null) {
228+
return this.type;
229+
}
191230
return this.consumeTypes;
192231
}
193232

@@ -197,7 +236,7 @@ List<PropagationType> getConsumeTypes() {
197236
enum PropagationType {
198237

199238
/**
200-
* <a href="https://www.w3.org/TR/trace-context/">W3C propagation.</a>
239+
* <a href="https://www.w3.org/TR/trace-context/">W3C</a> propagation.
201240
*/
202241
W3C,
203242

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2166,8 +2166,18 @@
21662166
}
21672167
},
21682168
{
2169-
"name": "management.tracing.propagation.type",
2170-
"defaultValue": "W3C"
2169+
"name": "management.tracing.propagation.consume-types",
2170+
"defaultValue": [
2171+
"W3C",
2172+
"B3",
2173+
"B3_MULTI"
2174+
]
2175+
},
2176+
{
2177+
"name": "management.tracing.propagation.produce-types",
2178+
"defaultValue": [
2179+
"W3C"
2180+
]
21712181
}
21722182
],
21732183
"hints": [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2012-2023 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 java.util.List;
20+
21+
import org.junit.jupiter.api.Test;
22+
23+
import static org.assertj.core.api.Assertions.assertThat;
24+
25+
/**
26+
* Tests for {@link TracingProperties}.
27+
*
28+
* @author Moritz Halbritter
29+
*/
30+
class TracingPropertiesTests {
31+
32+
@Test
33+
void propagationTypeShouldOverrideProduceTypes() {
34+
TracingProperties.Propagation propagation = new TracingProperties.Propagation();
35+
propagation.setProduceTypes(List.of(TracingProperties.Propagation.PropagationType.W3C));
36+
propagation.setType(List.of(TracingProperties.Propagation.PropagationType.B3));
37+
assertThat(propagation.getEffectiveProduceTypes())
38+
.containsExactly(TracingProperties.Propagation.PropagationType.B3);
39+
}
40+
41+
@Test
42+
void propagationTypeShouldOverrideConsumeTypes() {
43+
TracingProperties.Propagation propagation = new TracingProperties.Propagation();
44+
propagation.setConsumeTypes(List.of(TracingProperties.Propagation.PropagationType.W3C));
45+
propagation.setType(List.of(TracingProperties.Propagation.PropagationType.B3));
46+
assertThat(propagation.getEffectiveConsumeTypes())
47+
.containsExactly(TracingProperties.Propagation.PropagationType.B3);
48+
}
49+
50+
@Test
51+
void getEffectiveConsumeTypes() {
52+
TracingProperties.Propagation propagation = new TracingProperties.Propagation();
53+
propagation.setConsumeTypes(List.of(TracingProperties.Propagation.PropagationType.W3C));
54+
assertThat(propagation.getEffectiveConsumeTypes())
55+
.containsExactly(TracingProperties.Propagation.PropagationType.W3C);
56+
}
57+
58+
@Test
59+
void getEffectiveProduceTypes() {
60+
TracingProperties.Propagation propagation = new TracingProperties.Propagation();
61+
propagation.setProduceTypes(List.of(TracingProperties.Propagation.PropagationType.W3C));
62+
assertThat(propagation.getEffectiveProduceTypes())
63+
.containsExactly(TracingProperties.Propagation.PropagationType.W3C);
64+
}
65+
66+
}

0 commit comments

Comments
 (0)