Skip to content

Commit 76ab937

Browse files
authored
Spring starter should support otel.propagators (#10408)
1 parent 3d2ca02 commit 76ab937

File tree

6 files changed

+142
-12
lines changed

6 files changed

+142
-12
lines changed

instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/propagators/PropagationAutoConfiguration.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.opentelemetry.context.propagation.ContextPropagators;
99
import io.opentelemetry.context.propagation.TextMapPropagator;
1010
import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration;
11+
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
1112
import java.util.Collections;
1213
import java.util.List;
1314
import org.springframework.beans.factory.BeanFactory;
@@ -24,6 +25,7 @@
2425
@EnableConfigurationProperties(PropagationProperties.class)
2526
@AutoConfigureBefore(OpenTelemetryAutoConfiguration.class)
2627
@ConditionalOnProperty(prefix = "otel.propagation", name = "enabled", matchIfMissing = true)
28+
@SuppressWarnings("deprecation")
2729
public class PropagationAutoConfiguration {
2830

2931
@Bean
@@ -41,9 +43,11 @@ static class PropagatorsConfiguration {
4143

4244
@Bean
4345
TextMapPropagator compositeTextMapPropagator(
44-
BeanFactory beanFactory, PropagationProperties properties) {
46+
BeanFactory beanFactory,
47+
PropagationProperties properties,
48+
ConfigProperties configProperties) {
4549
return CompositeTextMapPropagatorFactory.getCompositeTextMapPropagator(
46-
beanFactory, properties.getType());
50+
beanFactory, configProperties.getList("otel.propagators", properties.getType()));
4751
}
4852
}
4953
}

instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/propagators/PropagationProperties.java

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
/** Configuration for propagators. */
1313
@ConfigurationProperties(prefix = "otel.propagation")
14+
@Deprecated // use otel.propagators instead
1415
public final class PropagationProperties {
1516

1617
private List<String> type = Arrays.asList("tracecontext", "baggage");

instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/SpringConfigProperties.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ public Double getDouble(String name) {
7171
@SuppressWarnings("unchecked")
7272
@Override
7373
public List<String> getList(String name) {
74-
return (List<String>) environment.getProperty(name, List.class);
74+
List<String> value = environment.getProperty(name, List.class);
75+
return value == null ? Collections.emptyList() : value;
7576
}
7677

7778
@Nullable

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

+116-8
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,30 @@
197197
"description": "The Zipkin endpoint to connect to.<br/>Currently only HTTP is supported.",
198198
"defaultValue": "http://localhost:9411/api/v2/spans"
199199
},
200+
{
201+
"name": "otel.instrumentation.annotations.enabled",
202+
"type": "java.lang.Boolean",
203+
"description": "Enable the <code>@WithSpan</code> annotation.",
204+
"defaultValue": true
205+
},
206+
{
207+
"name": "otel.instrumentation.kafka.enabled",
208+
"type": "java.lang.Boolean",
209+
"description": "Enable the Kafka instrumentation.",
210+
"defaultValue": true
211+
},
212+
{
213+
"name": "otel.instrumentation.log4j-appender.enabled",
214+
"type": "java.lang.Boolean",
215+
"description": "Enable the Log4J2 appender instrumentation.",
216+
"defaultValue": true
217+
},
218+
{
219+
"name": "otel.instrumentation.logback-appender.enabled",
220+
"type": "java.lang.Boolean",
221+
"description": "Enable the Logback appender instrumentation.",
222+
"defaultValue": true
223+
},
200224
{
201225
"name": "otel.instrumentation.logback-appender.experimental.capture-code-attributes",
202226
"type": "java.lang.Boolean",
@@ -229,13 +253,37 @@
229253
},
230254
{
231255
"name": "otel.instrumentation.logback-appender.experimental.capture-mdc-attributes",
232-
"type": "java.lang.String",
233-
"description": "Comma separated list of MDC attributes to capture. Use the wildcard character <code>*</code> to capture all attributes."
256+
"type": "java.util.List<java.lang.String>",
257+
"description": "MDC attributes to capture. Use the wildcard character <code>*</code> to capture all attributes."
258+
},
259+
{
260+
"name": "otel.instrumentation.micrometer.enabled",
261+
"type": "java.lang.Boolean",
262+
"description": "Enable the Micrometer instrumentation.",
263+
"defaultValue": false
264+
},
265+
{
266+
"name": "otel.instrumentation.spring-web.enabled",
267+
"type": "java.lang.Boolean",
268+
"description": "Enable the RestTemplate instrumentation.",
269+
"defaultValue": true
270+
},
271+
{
272+
"name": "otel.instrumentation.spring-webflux.enabled",
273+
"type": "java.lang.Boolean",
274+
"description": "Enable the WebClient instrumentation.",
275+
"defaultValue": true
276+
},
277+
{
278+
"name": "otel.instrumentation.spring-webmvc.enabled",
279+
"type": "java.lang.Boolean",
280+
"description": "Enable the Servlet instrumentation.",
281+
"defaultValue": true
234282
},
235283
{
236284
"name": "otel.logs.exporter",
237-
"type": "java.lang.String",
238-
"description": "List of exporters to be used for logs, separated by commas.",
285+
"type": "java.util.List<java.lang.String>",
286+
"description": "List of exporters to be used for logs.",
239287
"defaultValue": "otlp"
240288
},
241289
{
@@ -246,14 +294,37 @@
246294
},
247295
{
248296
"name": "otel.metrics.exporter",
249-
"type": "java.lang.String",
250-
"description": "List of exporters to be used for metrics, separated by commas.",
297+
"type": "java.util.List<java.lang.String>",
298+
"description": "List of exporters to be used for metrics.",
251299
"defaultValue": "otlp"
252300
},
301+
{
302+
"name": "otel.propagators",
303+
"type": "java.util.List<java.lang.String>",
304+
"description": "List of propagators to be used for context propagation.",
305+
"defaultValue": "tracecontext,baggage"
306+
},
307+
{
308+
"name": "otel.resource.attributes",
309+
"type": "java.util.Map<java.lang.String, java.lang.String>",
310+
"description": "Resource attributes to be added to all spans. In addition to these attributes, the resource will also include attributes discovered from the runtime, such as <code>host.name</code> and <code>process.id</code>."
311+
},
312+
{
313+
"name": "otel.sdk.disabled",
314+
"type": "java.lang.Boolean",
315+
"description": "Disable the OpenTelemetry Spring Starter.",
316+
"defaultValue": false
317+
},
318+
{
319+
"name": "otel.springboot.resource.enabled",
320+
"type": "java.lang.Boolean",
321+
"description": "Enable the resource auto-configuration.",
322+
"defaultValue": true
323+
},
253324
{
254325
"name": "otel.traces.exporter",
255-
"type": "java.lang.String",
256-
"description": "List of exporters to be used for tracing, separated by commas.",
326+
"type": "java.util.List<java.lang.String>",
327+
"description": "List of exporters to be used for tracing.",
257328
"defaultValue": "otlp"
258329
},
259330
{
@@ -339,6 +410,10 @@
339410
{
340411
"name": "otel.logs.exporter",
341412
"values": [
413+
{
414+
"value": "logging",
415+
"description": "The logging exporter prints exported logs to stdout. It's mainly used for testing and debugging."
416+
},
342417
{
343418
"value": "none",
344419
"description": "No autoconfigured exporter."
@@ -366,6 +441,39 @@
366441
}
367442
]
368443
},
444+
{
445+
"name": "otel.propagators",
446+
"values": [
447+
{
448+
"value": "baggage",
449+
"description": "The Baggage propagator propagates baggage using the W3C Baggage format. See https://www.w3.org/TR/baggage/."
450+
},
451+
{
452+
"value": "b3",
453+
"description": "The B3 propagator propagates trace context using the B3 single-header format: See https://github.com/openzipkin/b3-propagation#single-header."
454+
},
455+
{
456+
"value": "b3multi",
457+
"description": "The B3 propagator propagates trace context using the B3 multi-header format: See https://github.com/openzipkin/b3-propagation#multiple-headers."
458+
},
459+
{
460+
"value": "jaeger",
461+
"description": "The Jaeger propagator propagates trace context using the Jaeger format. See https://www.jaegertracing.io/docs/1.21/client-libraries/#propagation-format."
462+
},
463+
{
464+
"value": "ottrace",
465+
"description": "The OpenTelemetry Trace Context propagator propagates trace context using the OpenTelemetry format. See https://github.com/opentracing/specification/blob/master/rfc/trace_identifiers.md."
466+
},
467+
{
468+
"value": "tracecontext",
469+
"description": "The Trace Context propagator propagates trace context using the W3C Trace Context format (add `baggage` as well to include W3C baggage). See https://www.w3.org/TR/trace-context/."
470+
},
471+
{
472+
"value": "xray",
473+
"description": "The AWS X-Ray propagator propagates trace context using the AWS X-Ray format. See https://docs.aws.amazon.com/xray/latest/devguide/xray-concepts.html#xray-concepts-tracingheader."
474+
}
475+
]
476+
},
369477
{
370478
"name": "otel.traces.exporter",
371479
"values": [

instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/propagators/PropagationAutoConfigurationTest.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,26 @@ void shouldCreateNoop() {
9191
});
9292
}
9393

94+
@Test
95+
@DisplayName(
96+
"when propagation is set to some values should contain only supported values - deprecated")
97+
void shouldContainOnlySupportedDeprecated() {
98+
this.contextRunner
99+
.withPropertyValues("otel.propagation.type=invalid,b3")
100+
.run(
101+
context -> {
102+
TextMapPropagator compositePropagator =
103+
context.getBean("compositeTextMapPropagator", TextMapPropagator.class);
104+
105+
assertThat(compositePropagator.fields()).containsExactly("b3");
106+
});
107+
}
108+
94109
@Test
95110
@DisplayName("when propagation is set to some values should contain only supported values")
96111
void shouldContainOnlySupported() {
97112
this.contextRunner
98-
.withPropertyValues("otel.propagation.type=invalid,b3")
113+
.withPropertyValues("otel.propagators=invalid,b3")
99114
.run(
100115
context -> {
101116
TextMapPropagator compositePropagator =

instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/propagators/PropagationPropertiesTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.springframework.boot.autoconfigure.AutoConfigurations;
1515
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
1616

17+
@SuppressWarnings("deprecation") // test for deprecated code
1718
public class PropagationPropertiesTest {
1819

1920
private final ApplicationContextRunner contextRunner =

0 commit comments

Comments
 (0)