parent
ce1c3e52d7
commit
f40e9738b6
|
@ -70,6 +70,7 @@ import org.springframework.core.env.Environment;
|
||||||
* {@link EnableAutoConfiguration Auto-configuration} for OpenTelemetry.
|
* {@link EnableAutoConfiguration Auto-configuration} for OpenTelemetry.
|
||||||
*
|
*
|
||||||
* @author Moritz Halbritter
|
* @author Moritz Halbritter
|
||||||
|
* @author Yanming Zhou
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
@AutoConfiguration(before = MicrometerTracingAutoConfiguration.class)
|
@AutoConfiguration(before = MicrometerTracingAutoConfiguration.class)
|
||||||
|
@ -101,12 +102,13 @@ public class OpenTelemetryAutoConfiguration {
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
SdkTracerProvider otelSdkTracerProvider(Environment environment, ObjectProvider<SpanProcessor> spanProcessors,
|
SdkTracerProvider otelSdkTracerProvider(Environment environment, ObjectProvider<SpanProcessor> spanProcessors,
|
||||||
Sampler sampler) {
|
Sampler sampler, ObjectProvider<SdkTracerProviderCustomizer> customizers) {
|
||||||
String applicationName = environment.getProperty("spring.application.name", DEFAULT_APPLICATION_NAME);
|
String applicationName = environment.getProperty("spring.application.name", DEFAULT_APPLICATION_NAME);
|
||||||
SdkTracerProviderBuilder builder = SdkTracerProvider.builder()
|
SdkTracerProviderBuilder builder = SdkTracerProvider.builder()
|
||||||
.setSampler(sampler)
|
.setSampler(sampler)
|
||||||
.setResource(Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, applicationName)));
|
.setResource(Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, applicationName)));
|
||||||
spanProcessors.orderedStream().forEach(builder::addSpanProcessor);
|
spanProcessors.orderedStream().forEach(builder::addSpanProcessor);
|
||||||
|
customizers.forEach((customizer) -> customizer.customize(builder));
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2012-2023 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.boot.actuate.autoconfigure.tracing;
|
||||||
|
|
||||||
|
import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback interface that can be used to customize auto-configured
|
||||||
|
* {@link SdkTracerProviderBuilder}.
|
||||||
|
*
|
||||||
|
* @author Yanming Zhou
|
||||||
|
* @since 3.1.0
|
||||||
|
*/
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface SdkTracerProviderCustomizer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Customize the given {@code builder}.
|
||||||
|
* @param builder the builder to customize
|
||||||
|
*/
|
||||||
|
void customize(SdkTracerProviderBuilder builder);
|
||||||
|
|
||||||
|
}
|
|
@ -34,6 +34,7 @@ import io.opentelemetry.context.propagation.ContextPropagators;
|
||||||
import io.opentelemetry.context.propagation.TextMapPropagator;
|
import io.opentelemetry.context.propagation.TextMapPropagator;
|
||||||
import io.opentelemetry.extension.trace.propagation.B3Propagator;
|
import io.opentelemetry.extension.trace.propagation.B3Propagator;
|
||||||
import io.opentelemetry.sdk.trace.SdkTracerProvider;
|
import io.opentelemetry.sdk.trace.SdkTracerProvider;
|
||||||
|
import io.opentelemetry.sdk.trace.SpanLimits;
|
||||||
import io.opentelemetry.sdk.trace.SpanProcessor;
|
import io.opentelemetry.sdk.trace.SpanProcessor;
|
||||||
import io.opentelemetry.sdk.trace.samplers.Sampler;
|
import io.opentelemetry.sdk.trace.samplers.Sampler;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -54,6 +55,7 @@ import static org.mockito.Mockito.mock;
|
||||||
*
|
*
|
||||||
* @author Moritz Halbritter
|
* @author Moritz Halbritter
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
|
* @author Yanming Zhou
|
||||||
*/
|
*/
|
||||||
class OpenTelemetryAutoConfigurationTests {
|
class OpenTelemetryAutoConfigurationTests {
|
||||||
|
|
||||||
|
@ -203,6 +205,14 @@ class OpenTelemetryAutoConfigurationTests {
|
||||||
.run((context) -> assertThat(context).hasBean("w3cTextMapPropagatorWithoutBaggage"));
|
.run((context) -> assertThat(context).hasBean("w3cTextMapPropagatorWithoutBaggage"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldCustomizeSdkTracerProvider() {
|
||||||
|
this.contextRunner.withUserConfiguration(SdkTracerProviderCustomizationConfiguration.class).run((context) -> {
|
||||||
|
SdkTracerProvider tracerProvider = context.getBean(SdkTracerProvider.class);
|
||||||
|
assertThat(tracerProvider.getSpanLimits().getMaxNumberOfEvents()).isEqualTo(42);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
private static class CustomConfiguration {
|
private static class CustomConfiguration {
|
||||||
|
|
||||||
|
@ -278,4 +288,17 @@ class OpenTelemetryAutoConfigurationTests {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
private static class SdkTracerProviderCustomizationConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
SdkTracerProviderCustomizer sdkTracerProviderBuilderCustomizer() {
|
||||||
|
return (builder) -> {
|
||||||
|
SpanLimits spanLimits = SpanLimits.builder().setMaxNumberOfEvents(42).build();
|
||||||
|
builder.setSpanLimits(spanLimits);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue