Skip to content

Commit

Permalink
Merge pull request #7 from spring-cloud-incubator/otel-upgrade-0.14
Browse files Browse the repository at this point in the history
Otel upgrade to 0.14
  • Loading branch information
jonatan-ivanov authored Jan 27, 2021
2 parents 9b79cb8 + 74db4ab commit eac5377
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 178 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@
<spring-cloud-netflix.version>3.0.0</spring-cloud-netflix.version>
<spring-cloud-openfeign.version>3.0.0</spring-cloud-openfeign.version>
<opentracing.version>0.32.0</opentracing.version>
<opentelemetry.version>0.13.1</opentelemetry.version>
<opentelemetry.version>0.14.1</opentelemetry.version>
<!-- From maven local -->
<opentelemetry-instrumentation.version>0.13.0</opentelemetry-instrumentation.version>
<opentelemetry-instrumentation.version>0.14.0</opentelemetry-instrumentation.version>
<spring-security-boot-autoconfigure.version>2.3.4.RELEASE</spring-security-boot-autoconfigure.version>
<disable.nohttp.checks>false</disable.nohttp.checks>
<okhttp.version>4.9.0</okhttp.version>
Expand Down
4 changes: 4 additions & 0 deletions spring-cloud-sleuth-otel-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-api</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-semconv</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk-common</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
import java.util.List;
import java.util.stream.Collectors;

import io.opentelemetry.api.DefaultOpenTelemetry;
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.metrics.MeterProvider;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.api.trace.TracerProvider;
import io.opentelemetry.context.propagation.ContextPropagators;
Expand All @@ -31,8 +32,7 @@
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
import io.opentelemetry.sdk.trace.export.SpanExporter;
import io.opentelemetry.sdk.trace.samplers.Sampler;
import io.opentelemetry.sdk.trace.spi.TracerProviderFactorySdk;
import io.opentelemetry.spi.metrics.MeterProviderFactory;
import io.opentelemetry.sdk.trace.spi.SdkTracerProviderFactory;
import io.opentelemetry.spi.trace.TracerProviderFactory;

import org.springframework.beans.factory.ObjectProvider;
Expand All @@ -48,7 +48,6 @@
import org.springframework.cloud.sleuth.autoconfig.TraceConfiguration;
import org.springframework.cloud.sleuth.autoconfig.brave.BraveAutoConfiguration;
import org.springframework.cloud.sleuth.internal.SleuthContextListener;
import org.springframework.cloud.sleuth.otel.bridge.OtelOpenTelemetry;
import org.springframework.cloud.sleuth.otel.bridge.SpanExporterCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -77,19 +76,17 @@ public class OtelAutoConfiguration {

@Bean
@ConditionalOnMissingBean
OpenTelemetry otel(TracerProviderFactory tracerProviderFactory, MeterProviderFactory meterProviderFactory,
TracerProvider tracerProvider, MeterProvider meterProvider, ContextPropagators contextPropagators) {
OtelOpenTelemetry otelOpenTelemetry = new OtelOpenTelemetry(tracerProviderFactory, meterProviderFactory,
tracerProvider, meterProvider, contextPropagators);
OpenTelemetry.set(otelOpenTelemetry);
OpenTelemetry.setGlobalPropagators(contextPropagators);
return otelOpenTelemetry;
OpenTelemetry otel(TracerProvider tracerProvider, ContextPropagators contextPropagators) {
OpenTelemetry openTelemetry = DefaultOpenTelemetry.builder().setTracerProvider(tracerProvider)
.setPropagators(contextPropagators).build();
GlobalOpenTelemetry.set(openTelemetry);
return openTelemetry;
}

@Bean
@ConditionalOnMissingBean
TracerProviderFactory otelTracerProviderFactory() {
return new TracerProviderFactorySdk();
return new SdkTracerProviderFactory();
}

@Bean
Expand All @@ -98,18 +95,6 @@ TracerProvider otelTracerProvider(TracerProviderFactory tracerProviderFactory) {
return tracerProviderFactory.create();
}

@Bean
@ConditionalOnMissingBean
MeterProviderFactory otelMeterProviderFactory() {
return OpenTelemetry::getGlobalMeterProvider;
}

@Bean
@ConditionalOnMissingBean
MeterProvider otelMeterProvider(MeterProviderFactory meterProviderFactory) {
return meterProviderFactory.create();
}

@Bean
@ConditionalOnMissingBean
TraceConfig otelTracerConfig(OtelProperties otelProperties, Sampler sampler) {
Expand Down
2 changes: 1 addition & 1 deletion spring-cloud-sleuth-otel-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<name>spring-cloud-sleuth-otel-dependencies</name>
<description>Spring Cloud Sleuth OTel Dependencies</description>
<properties>
<opentelemetry.version>0.13.1</opentelemetry.version>
<opentelemetry.version>0.14.1</opentelemetry.version>
</properties>
<dependencyManagement>
<dependencies>
Expand Down
4 changes: 4 additions & 0 deletions spring-cloud-sleuth-otel/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-api</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-semconv</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk-common</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.sdk.trace.export.SpanExporter;

import static java.util.concurrent.TimeUnit.SECONDS;

/**
* Stores spans in a queue.
*
Expand Down Expand Up @@ -78,6 +80,11 @@ public CompletableResultCode forceFlush() {
return CompletableResultCode.ofSuccess();
}

@Override
public void close() {
shutdown().join(10, SECONDS);
}

public SpanData takeLocalSpan() {
return this.spans.poll();
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.propagation.TextMapPropagator;
import io.opentelemetry.extension.trace.propagation.AwsXRayPropagator;
import io.opentelemetry.extension.trace.propagation.AwsXrayPropagator;
import io.opentelemetry.extension.trace.propagation.B3Propagator;
import io.opentelemetry.extension.trace.propagation.JaegerPropagator;
import io.opentelemetry.extension.trace.propagation.OtTracerPropagator;
Expand Down Expand Up @@ -60,8 +60,8 @@ public class CompositeTextMapPropagator implements TextMapPropagator {
public CompositeTextMapPropagator(BeanFactory beanFactory, List<PropagationType> types) {
this.types = types;
if (isOnClasspath("io.opentelemetry.extension.trace.propagation.AwsXRayPropagator")) {
this.mapping.put(PropagationType.AWS, beanFactory.getBeanProvider(AwsXRayPropagator.class)
.getIfAvailable(AwsXRayPropagator::getInstance));
this.mapping.put(PropagationType.AWS, beanFactory.getBeanProvider(AwsXrayPropagator.class)
.getIfAvailable(AwsXrayPropagator::getInstance));
}
if (isOnClasspath("io.opentelemetry.extension.trace.propagation.B3Propagator")) {
this.mapping.put(PropagationType.B3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import io.opentelemetry.context.Context;
Expand Down Expand Up @@ -121,6 +122,11 @@ public CompletableResultCode forceFlush() {
return spanProcessor.forceFlush();
}

@Override
public void close() {
shutdown().join(10, TimeUnit.SECONDS);
}

@Override
public String toString() {
return "OtelTestSpanHandler{" + "spanProcessor=" + this.spanProcessor + '}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
import java.io.Closeable;
import java.util.regex.Pattern;

import io.opentelemetry.api.DefaultOpenTelemetry;
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.metrics.MeterProvider;
import io.opentelemetry.api.trace.TracerProvider;
import io.opentelemetry.context.propagation.ContextPropagators;
import io.opentelemetry.extension.trace.propagation.B3Propagator;
import io.opentelemetry.sdk.trace.SdkTracerProvider;
import io.opentelemetry.sdk.trace.config.TraceConfig;
import io.opentelemetry.sdk.trace.samplers.Sampler;
import io.opentelemetry.sdk.trace.spi.TracerProviderFactorySdk;
import io.opentelemetry.spi.metrics.MeterProviderFactory;
import io.opentelemetry.sdk.trace.spi.SdkTracerProviderFactory;
import io.opentelemetry.spi.trace.TracerProviderFactory;

import org.springframework.cloud.sleuth.CurrentTraceContext;
Expand All @@ -40,7 +40,6 @@
import org.springframework.cloud.sleuth.http.HttpServerHandler;
import org.springframework.cloud.sleuth.otel.bridge.ArrayListSpanProcessor;
import org.springframework.cloud.sleuth.otel.bridge.OtelAccessor;
import org.springframework.cloud.sleuth.otel.bridge.OtelOpenTelemetry;
import org.springframework.cloud.sleuth.propagation.Propagator;
import org.springframework.cloud.sleuth.test.TestSpanHandler;
import org.springframework.cloud.sleuth.test.TestTracingAssertions;
Expand All @@ -57,7 +56,7 @@ public class OtelTestTracing implements TracerAware, TestTracingAware, TestTraci

OpenTelemetry openTelemetry = otel();

ContextPropagators defaultContextPropagators = OpenTelemetry.getGlobalPropagators();
ContextPropagators defaultContextPropagators = openTelemetry.getPropagators();

Sampler sampler = Sampler.alwaysOn();

Expand All @@ -80,30 +79,20 @@ protected ContextPropagators contextPropagators() {

OpenTelemetry otel() {
TracerProviderFactory providerFactory = otelTracerProviderFactory();
MeterProviderFactory meterProviderFactory = otelMeterProviderFactory();
OtelOpenTelemetry otelOpenTelemetry = new OtelOpenTelemetry(providerFactory, meterProviderFactory,
otelTracerProvider(providerFactory), otelMeterProvider(meterProviderFactory), this.contextPropagators);
OpenTelemetry.set(otelOpenTelemetry);
OpenTelemetry.setGlobalPropagators(contextPropagators);
return otelOpenTelemetry;
OpenTelemetry openTelemetry = DefaultOpenTelemetry.builder()
.setTracerProvider(otelTracerProvider(providerFactory)).setPropagators(this.contextPropagators).build();
GlobalOpenTelemetry.set(openTelemetry);
return openTelemetry;
}

TracerProviderFactory otelTracerProviderFactory() {
return new TracerProviderFactorySdk();
return new SdkTracerProviderFactory();
}

TracerProvider otelTracerProvider(TracerProviderFactory tracerProviderFactory) {
return tracerProviderFactory.create();
}

MeterProviderFactory otelMeterProviderFactory() {
return OpenTelemetry::getGlobalMeterProvider;
}

MeterProvider otelMeterProvider(MeterProviderFactory meterProviderFactory) {
return meterProviderFactory.create();
}

private void reset() {
this.contextPropagators = contextPropagators();
this.tracer = otelTracer();
Expand Down Expand Up @@ -134,7 +123,6 @@ public TestTracingAssertions assertions() {
@Override
public void close() {
this.spanProcessor.clear();
OpenTelemetry.setGlobalPropagators(this.defaultContextPropagators);
this.sampler = Sampler.alwaysOn();
}

Expand Down

0 comments on commit eac5377

Please sign in to comment.