Clean up some spring-boot auto-configuration to get rid of deprecations
MODIFY
instrumentation/spring/spring-boot-autoconfigure/README.md
instrumentation/spring/spring-boot-autoconfigure/README.md
@@ -7,7 +7,7 @@ Auto-configures OpenTelemetry instrumentation for [spring-web](../spring-web-3.1
### Add these dependencies to your project.
Replace `OPENTELEMETRY_VERSION` with the latest stable [release](https://search.maven.org/search?q=g:io.opentelemetry).
- - Minimum version: `0.11.0`
+ - Minimum version: `0.14.1`
- Note: You may need to include our bintray maven repository to your build file: `https://dl.bintray.com/open-telemetry/maven/`. As of August 2020 the latest opentelemetry-java-instrumentation artifacts are not published to maven-central. Please check the [releasing](https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/master/RELEASING.md) doc for updates to this process.
@@ -72,17 +72,17 @@ For Maven add to your `pom.xml`:
<!-- opentelemetry exporters-->
<dependency>
<groupId>io.opentelemetry</groupId>
- <artifactId>opentelemetry-exporters-jaeger</artifactId>
+ <artifactId>opentelemetry-exporter-jaeger</artifactId>
<version>OPENTELEMETRY_VERSION</version>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
- <artifactId>opentelemetry-exporters-zipkin</artifactId>
+ <artifactId>opentelemetry-exporter-zipkin</artifactId>
<version>OPENTELEMETRY_VERSION</version>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
- <artifactId>opentelemetry-exporters-otlp</artifactId>
+ <artifactId>opentelemetry-exporter-otlp</artifactId>
<version>OPENTELEMETRY_VERSION</version>
</dependency>

MODIFY
instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/TracerAutoConfiguration.java
instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/TracerAutoConfiguration.java
package io.opentelemetry.instrumentation.spring.autoconfigure;
-import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.trace.Tracer;
+import io.opentelemetry.api.trace.TracerProvider;
import io.opentelemetry.sdk.OpenTelemetrySdk;
-import io.opentelemetry.sdk.trace.SpanProcessor;
+import io.opentelemetry.sdk.trace.SdkTracerProvider;
+import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder;
import io.opentelemetry.sdk.trace.config.TraceConfig;
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
import io.opentelemetry.sdk.trace.export.SpanExporter;
import io.opentelemetry.sdk.trace.samplers.Sampler;
+import java.util.Collections;
import java.util.List;
-import java.util.stream.Collectors;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -34,38 +35,29 @@ public class TracerAutoConfiguration {
@Bean
@ConditionalOnMissingBean
- public Tracer otelTracer(
- TracerProperties tracerProperties, ObjectProvider<List<SpanExporter>> spanExportersProvider)
- throws Exception {
- Tracer tracer = GlobalOpenTelemetry.getTracer(tracerProperties.getName());
-
- List<SpanExporter> spanExporters = spanExportersProvider.getIfAvailable();
- if (spanExporters == null || spanExporters.isEmpty()) {
- return tracer;
- }
-
- addSpanProcessors(spanExporters);
- setSampler(tracerProperties);
-
- return tracer;
- }
-
- private void addSpanProcessors(List<SpanExporter> spanExporters) {
- List<SpanProcessor> spanProcessors =
- spanExporters.stream()
- .map(spanExporter -> SimpleSpanProcessor.builder(spanExporter).build())
- .collect(Collectors.toList());
-
- OpenTelemetrySdk.getGlobalTracerManagement()
- .addSpanProcessor(SpanProcessor.composite(spanProcessors));
+ public Tracer otelTracer(TracerProvider tracerProvider, TracerProperties tracerProperties) {
+ return tracerProvider.get(tracerProperties.getName());
}
- private void setSampler(TracerProperties tracerProperties) {
- TraceConfig updatedTraceConfig =
- OpenTelemetrySdk.getGlobalTracerManagement().getActiveTraceConfig().toBuilder()
+ @Bean
+ @ConditionalOnMissingBean
+ public TracerProvider tracerProvider(
+ TracerProperties tracerProperties, ObjectProvider<List<SpanExporter>> spanExportersProvider) {
+ SdkTracerProviderBuilder tracerProviderBuilder = SdkTracerProvider.builder();
+
+ spanExportersProvider.getIfAvailable(Collections::emptyList).stream()
+ // todo SimpleSpanProcessor...is that really what we want here?
+ .map(SimpleSpanProcessor::create)
+ .forEach(tracerProviderBuilder::addSpanProcessor);
+
+ SdkTracerProvider tracerProvider =
+ tracerProviderBuilder
+ .setTraceConfig(
+ TraceConfig.getDefault().toBuilder()
.setSampler(Sampler.traceIdRatioBased(tracerProperties.getSamplerProbability()))
+ .build())
.build();
-
- OpenTelemetrySdk.getGlobalTracerManagement().updateActiveTraceConfig(updatedTraceConfig);
+ OpenTelemetrySdk.builder().setTracerProvider(tracerProvider).buildAndRegisterGlobal();
+ return tracerProvider;
}
}

MODIFY
instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/jaeger/JaegerSpanExporterAutoConfiguration.java
instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/jaeger/JaegerSpanExporterAutoConfiguration.java
@@ -38,7 +38,7 @@ public class JaegerSpanExporterAutoConfiguration {
return JaegerGrpcSpanExporter.builder()
.setServiceName(jaegerSpanExporterProperties.getServiceName())
- .setDeadlineMs(jaegerSpanExporterProperties.getSpanTimeout().toMillis())
+ .setTimeout(jaegerSpanExporterProperties.getSpanTimeout())
.setEndpoint(jaegerSpanExporterProperties.getEndpoint())
.build();
}

MODIFY
instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpGrpcSpanExporterAutoConfiguration.java
instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpGrpcSpanExporterAutoConfiguration.java
@@ -38,7 +38,7 @@ public class OtlpGrpcSpanExporterAutoConfiguration {
return OtlpGrpcSpanExporter.builder()
.setEndpoint(otlpGrpcSpanExporterProperties.getEndpoint())
- .setDeadlineMs(otlpGrpcSpanExporterProperties.getSpanTimeout().toMillis())
+ .setTimeout(otlpGrpcSpanExporterProperties.getSpanTimeout())
.build();
}
}

Clean up some spring-boot auto-configuration to get rid of deprecations (#2115)