fix otel.properties in spring boot starter (#10559)
This commit is contained in:
parent
d73962834a
commit
66dd60015c
|
@ -13,6 +13,7 @@ import io.opentelemetry.instrumentation.spring.autoconfigure.exporters.otlp.Otlp
|
|||
import io.opentelemetry.instrumentation.spring.autoconfigure.exporters.otlp.OtlpMetricExporterAutoConfiguration;
|
||||
import io.opentelemetry.instrumentation.spring.autoconfigure.exporters.otlp.OtlpSpanExporterAutoConfiguration;
|
||||
import io.opentelemetry.instrumentation.spring.autoconfigure.internal.MapConverter;
|
||||
import io.opentelemetry.instrumentation.spring.autoconfigure.propagators.PropagationProperties;
|
||||
import io.opentelemetry.instrumentation.spring.autoconfigure.resources.OtelResourceAutoConfiguration;
|
||||
import io.opentelemetry.instrumentation.spring.autoconfigure.resources.SpringConfigProperties;
|
||||
import io.opentelemetry.sdk.OpenTelemetrySdk;
|
||||
|
@ -57,7 +58,11 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
|
|||
* <p>Updates the sampler probability for the configured {@link TracerProvider}.
|
||||
*/
|
||||
@Configuration
|
||||
@EnableConfigurationProperties({SamplerProperties.class, OtlpExporterProperties.class})
|
||||
@EnableConfigurationProperties({
|
||||
SamplerProperties.class,
|
||||
OtlpExporterProperties.class,
|
||||
PropagationProperties.class
|
||||
})
|
||||
public class OpenTelemetryAutoConfiguration {
|
||||
|
||||
public OpenTelemetryAutoConfiguration() {}
|
||||
|
@ -96,8 +101,11 @@ public class OpenTelemetryAutoConfiguration {
|
|||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
ConfigProperties configProperties(
|
||||
Environment env, OtlpExporterProperties otlpExporterProperties) {
|
||||
return new SpringConfigProperties(env, new SpelExpressionParser(), otlpExporterProperties);
|
||||
Environment env,
|
||||
OtlpExporterProperties otlpExporterProperties,
|
||||
PropagationProperties propagationProperties) {
|
||||
return new SpringConfigProperties(
|
||||
env, new SpelExpressionParser(), otlpExporterProperties, propagationProperties);
|
||||
}
|
||||
|
||||
@Bean(destroyMethod = "") // SDK components are shutdown from the OpenTelemetry instance
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.instrumentation.spring.autoconfigure.propagators;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/** Configuration for propagators. */
|
||||
@ConfigurationProperties(prefix = "otel.propagation")
|
||||
@Deprecated // use otel.propagators instead
|
||||
public final class DeprecatedPropagationProperties {
|
||||
|
||||
private List<String> type = Arrays.asList("tracecontext", "baggage");
|
||||
|
||||
public List<String> getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(List<String> type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
|
@ -22,7 +22,7 @@ import org.springframework.context.annotation.Configuration;
|
|||
|
||||
/** Configures {@link ContextPropagators} bean for propagation. */
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(PropagationProperties.class)
|
||||
@EnableConfigurationProperties(DeprecatedPropagationProperties.class)
|
||||
@AutoConfigureBefore(OpenTelemetryAutoConfiguration.class)
|
||||
@ConditionalOnProperty(prefix = "otel.propagation", name = "enabled", matchIfMissing = true)
|
||||
@SuppressWarnings("deprecation")
|
||||
|
@ -44,7 +44,7 @@ public class PropagationAutoConfiguration {
|
|||
@Bean
|
||||
TextMapPropagator compositeTextMapPropagator(
|
||||
BeanFactory beanFactory,
|
||||
PropagationProperties properties,
|
||||
DeprecatedPropagationProperties properties,
|
||||
ConfigProperties configProperties) {
|
||||
return CompositeTextMapPropagatorFactory.getCompositeTextMapPropagator(
|
||||
beanFactory, configProperties.getList("otel.propagators", properties.getType()));
|
||||
|
|
|
@ -5,22 +5,21 @@
|
|||
|
||||
package io.opentelemetry.instrumentation.spring.autoconfigure.propagators;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/** Configuration for propagators. */
|
||||
@ConfigurationProperties(prefix = "otel.propagation")
|
||||
@Deprecated // use otel.propagators instead
|
||||
@ConfigurationProperties(prefix = "otel")
|
||||
public final class PropagationProperties {
|
||||
|
||||
private List<String> type = Arrays.asList("tracecontext", "baggage");
|
||||
private List<String> propagators = Collections.emptyList();
|
||||
|
||||
public List<String> getType() {
|
||||
return type;
|
||||
public List<String> getPropagators() {
|
||||
return propagators;
|
||||
}
|
||||
|
||||
public void setType(List<String> type) {
|
||||
this.type = type;
|
||||
public void setPropagators(List<String> propagators) {
|
||||
this.propagators = propagators;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ package io.opentelemetry.instrumentation.spring.autoconfigure.resources;
|
|||
|
||||
import io.opentelemetry.exporter.otlp.internal.OtlpConfigUtil;
|
||||
import io.opentelemetry.instrumentation.spring.autoconfigure.exporters.otlp.OtlpExporterProperties;
|
||||
import io.opentelemetry.instrumentation.spring.autoconfigure.propagators.PropagationProperties;
|
||||
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
|
||||
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
|
||||
import java.time.Duration;
|
||||
|
@ -22,14 +23,17 @@ public class SpringConfigProperties implements ConfigProperties {
|
|||
|
||||
private final ExpressionParser parser;
|
||||
private final OtlpExporterProperties otlpExporterProperties;
|
||||
private final PropagationProperties propagationProperties;
|
||||
|
||||
public SpringConfigProperties(
|
||||
Environment environment,
|
||||
ExpressionParser parser,
|
||||
OtlpExporterProperties otlpExporterProperties) {
|
||||
OtlpExporterProperties otlpExporterProperties,
|
||||
PropagationProperties propagationProperties) {
|
||||
this.environment = environment;
|
||||
this.parser = parser;
|
||||
this.otlpExporterProperties = otlpExporterProperties;
|
||||
this.propagationProperties = propagationProperties;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -71,6 +75,9 @@ public class SpringConfigProperties implements ConfigProperties {
|
|||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<String> getList(String name) {
|
||||
if (name.equals("otel.propagators")) {
|
||||
return propagationProperties.getPropagators();
|
||||
}
|
||||
List<String> value = environment.getProperty(name, List.class);
|
||||
return value == null ? Collections.emptyList() : value;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
import static org.assertj.core.api.Assertions.entry;
|
||||
|
||||
import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration;
|
||||
import io.opentelemetry.instrumentation.spring.autoconfigure.propagators.PropagationProperties;
|
||||
import io.opentelemetry.instrumentation.spring.autoconfigure.resources.OtelResourceAutoConfiguration;
|
||||
import io.opentelemetry.instrumentation.spring.autoconfigure.resources.SpringConfigProperties;
|
||||
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
|
||||
|
@ -90,6 +91,7 @@ class OtlpExporterPropertiesTest {
|
|||
return new SpringConfigProperties(
|
||||
context.getBean("environment", Environment.class),
|
||||
new SpelExpressionParser(),
|
||||
context.getBean(OtlpExporterProperties.class));
|
||||
context.getBean(OtlpExporterProperties.class),
|
||||
new PropagationProperties());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,8 @@ public class PropagationPropertiesTest {
|
|||
.withPropertyValues("otel.propagation.type=xray,b3")
|
||||
.run(
|
||||
context -> {
|
||||
PropagationProperties propertiesBean = context.getBean(PropagationProperties.class);
|
||||
DeprecatedPropagationProperties propertiesBean =
|
||||
context.getBean(DeprecatedPropagationProperties.class);
|
||||
|
||||
assertThat(propertiesBean.getType()).isEqualTo(Arrays.asList("xray", "b3"));
|
||||
});
|
||||
|
@ -43,7 +44,7 @@ public class PropagationPropertiesTest {
|
|||
|
||||
this.contextRunner.run(
|
||||
context ->
|
||||
assertThat(context.getBean(PropagationProperties.class).getType())
|
||||
assertThat(context.getBean(DeprecatedPropagationProperties.class).getType())
|
||||
.containsExactly("tracecontext", "baggage"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
import static org.assertj.core.api.Assertions.entry;
|
||||
|
||||
import io.opentelemetry.instrumentation.spring.autoconfigure.exporters.otlp.OtlpExporterProperties;
|
||||
import io.opentelemetry.instrumentation.spring.autoconfigure.propagators.PropagationProperties;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
|
@ -29,7 +30,10 @@ class SpringConfigPropertiesTest {
|
|||
Environment env = context.getBean("environment", Environment.class);
|
||||
SpringConfigProperties config =
|
||||
new SpringConfigProperties(
|
||||
env, new SpelExpressionParser(), new OtlpExporterProperties());
|
||||
env,
|
||||
new SpelExpressionParser(),
|
||||
new OtlpExporterProperties(),
|
||||
new PropagationProperties());
|
||||
|
||||
assertThat(config.getMap("otel.springboot.test.map"))
|
||||
.contains(
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
otel.instrumentation.logback-appender.experimental.capture-code-attributes=true
|
|
@ -0,0 +1,7 @@
|
|||
otel:
|
||||
instrumentation:
|
||||
logback-appender:
|
||||
experimental:
|
||||
capture-code-attributes: true
|
||||
propagators:
|
||||
- b3
|
|
@ -8,6 +8,7 @@ package io.opentelemetry.smoketest;
|
|||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import io.opentelemetry.api.trace.SpanKind;
|
||||
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
|
||||
import io.opentelemetry.sdk.logs.data.LogRecordData;
|
||||
import io.opentelemetry.sdk.logs.export.LogRecordExporter;
|
||||
import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
|
||||
|
@ -54,6 +55,8 @@ class OtelSpringStarterSmokeTest {
|
|||
|
||||
@Autowired private TestRestTemplate testRestTemplate;
|
||||
|
||||
@Autowired private ConfigProperties configProperties;
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class TestConfiguration {
|
||||
@Bean
|
||||
|
@ -72,6 +75,14 @@ class OtelSpringStarterSmokeTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void propertyConversion() {
|
||||
assertThat(configProperties.getMap("otel.exporter.otlp.headers"))
|
||||
.containsEntry("a", "1")
|
||||
.containsEntry("b", "2");
|
||||
assertThat(configProperties.getList("otel.propagators")).containsExactly("b3");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSendTelemetry() throws InterruptedException {
|
||||
|
||||
|
|
Loading…
Reference in New Issue