Migrated to OTel 0.10.0
This commit is contained in:
@@ -74,8 +74,6 @@ import org.springframework.web.client.RestTemplate;
|
||||
@Import(ZipkinSenderConfigurationImportSelector.class)
|
||||
public class ZipkinAutoConfiguration {
|
||||
|
||||
private static final Log log = LogFactory.getLog(ZipkinAutoConfiguration.class);
|
||||
|
||||
/**
|
||||
* Zipkin reporter bean name. Name of the bean matters for supporting multiple tracing
|
||||
* systems.
|
||||
@@ -88,29 +86,7 @@ public class ZipkinAutoConfiguration {
|
||||
*/
|
||||
public static final String SENDER_BEAN_NAME = "zipkinSender";
|
||||
|
||||
@Bean(REPORTER_BEAN_NAME)
|
||||
@ConditionalOnMissingBean(name = REPORTER_BEAN_NAME)
|
||||
public Reporter<Span> reporter(ReporterMetrics reporterMetrics, ZipkinProperties zipkin,
|
||||
@Qualifier(SENDER_BEAN_NAME) Sender sender) {
|
||||
CheckResult checkResult = checkResult(sender, 1_000L);
|
||||
logCheckResult(sender, checkResult);
|
||||
|
||||
// historical constraint. Note: AsyncReporter supports memory bounds
|
||||
AsyncReporter<Span> asyncReporter = AsyncReporter.builder(sender).queuedMaxSpans(1000)
|
||||
.messageTimeout(zipkin.getMessageTimeout(), TimeUnit.SECONDS).metrics(reporterMetrics)
|
||||
.build(zipkin.getEncoder());
|
||||
|
||||
return asyncReporter;
|
||||
}
|
||||
|
||||
private void logCheckResult(Sender sender, CheckResult checkResult) {
|
||||
if (log.isDebugEnabled() && checkResult != null && checkResult.ok()) {
|
||||
log.debug("Check result of the [" + sender.toString() + "] is [" + checkResult + "]");
|
||||
}
|
||||
else if (checkResult != null && !checkResult.ok()) {
|
||||
log.warn("Check result of the [" + sender.toString() + "] contains an error [" + checkResult + "]");
|
||||
}
|
||||
}
|
||||
private static final Log log = LogFactory.getLog(ZipkinAutoConfiguration.class);
|
||||
|
||||
/** Limits {@link Sender#check()} to {@code deadlineMillis}. */
|
||||
static CheckResult checkResult(Sender sender, long deadlineMillis) {
|
||||
@@ -142,6 +118,30 @@ public class ZipkinAutoConfiguration {
|
||||
}
|
||||
}
|
||||
|
||||
@Bean(REPORTER_BEAN_NAME)
|
||||
@ConditionalOnMissingBean(name = REPORTER_BEAN_NAME)
|
||||
public Reporter<Span> reporter(ReporterMetrics reporterMetrics, ZipkinProperties zipkin,
|
||||
@Qualifier(SENDER_BEAN_NAME) Sender sender) {
|
||||
CheckResult checkResult = checkResult(sender, 1_000L);
|
||||
logCheckResult(sender, checkResult);
|
||||
|
||||
// historical constraint. Note: AsyncReporter supports memory bounds
|
||||
AsyncReporter<Span> asyncReporter = AsyncReporter.builder(sender).queuedMaxSpans(1000)
|
||||
.messageTimeout(zipkin.getMessageTimeout(), TimeUnit.SECONDS).metrics(reporterMetrics)
|
||||
.build(zipkin.getEncoder());
|
||||
|
||||
return asyncReporter;
|
||||
}
|
||||
|
||||
private void logCheckResult(Sender sender, CheckResult checkResult) {
|
||||
if (log.isDebugEnabled() && checkResult != null && checkResult.ok()) {
|
||||
log.debug("Check result of the [" + sender.toString() + "] is [" + checkResult + "]");
|
||||
}
|
||||
else if (checkResult != null && !checkResult.ok()) {
|
||||
log.warn("Check result of the [" + sender.toString() + "] contains an error [" + checkResult + "]");
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ZipkinRestTemplateCustomizer zipkinRestTemplateCustomizer(ZipkinProperties zipkinProperties) {
|
||||
|
||||
@@ -63,8 +63,6 @@ import org.springframework.web.client.RestTemplate;
|
||||
@AutoConfigureAfter(ZipkinAutoConfiguration.class)
|
||||
public class ZipkinBraveAutoConfiguration {
|
||||
|
||||
private static final Log log = LogFactory.getLog(ZipkinBraveAutoConfiguration.class);
|
||||
|
||||
/**
|
||||
*
|
||||
* Sort Zipkin Handlers last, so that redactions etc happen prior.
|
||||
@@ -82,6 +80,8 @@ public class ZipkinBraveAutoConfiguration {
|
||||
return 0;
|
||||
};
|
||||
|
||||
private static final Log log = LogFactory.getLog(ZipkinBraveAutoConfiguration.class);
|
||||
|
||||
/** Returns one handler for as many reporters as exist. */
|
||||
@Bean
|
||||
SpanHandler zipkinSpanHandler(@Nullable List<Reporter<Span>> spanReporters, @Nullable Tag<Throwable> errorTag) {
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.sleuth.zipkin2;
|
||||
|
||||
import io.opentelemetry.exporters.zipkin.ZipkinSpanExporter;
|
||||
import io.opentelemetry.trace.Tracer;
|
||||
import io.opentelemetry.api.trace.Tracer;
|
||||
import io.opentelemetry.exporter.zipkin.ZipkinSpanExporter;
|
||||
import zipkin2.reporter.Sender;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
@@ -62,7 +62,7 @@ public class ZipkinOtelAutoConfiguration {
|
||||
@ConditionalOnMissingBean
|
||||
ZipkinSpanExporter otelZipkinSpanExporter(ZipkinProperties zipkinProperties,
|
||||
@Qualifier(ZipkinAutoConfiguration.SENDER_BEAN_NAME) Sender sender, Environment env) {
|
||||
return ZipkinSpanExporter.newBuilder().setEndpoint(zipkinProperties.getBaseUrl() + "api/v2/spans")
|
||||
return ZipkinSpanExporter.builder().setEndpoint(zipkinProperties.getBaseUrl() + "api/v2/spans")
|
||||
.setSender(sender).setEncoder(zipkinProperties.getEncoder())
|
||||
.setServiceName(
|
||||
StringUtils.hasText(zipkinProperties.getService().getName())
|
||||
|
||||
@@ -174,17 +174,6 @@ class ZipkinRestTemplateSenderConfiguration {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal interface to provide a way to retrieve Zipkin URI. If there's no discovery
|
||||
* client then this value will be taken from the properties. Otherwise host will be
|
||||
* assumed to be a service id.
|
||||
*/
|
||||
interface ZipkinUrlExtractor {
|
||||
|
||||
URI zipkinUrl(ZipkinProperties zipkinProperties);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves at runtime where the Zipkin server is. If there's no discovery client then
|
||||
* {@link URI} from the properties is taken. Otherwise service discovery is pinged for
|
||||
@@ -238,6 +227,17 @@ class ZipkinRestTemplateWrapper extends RestTemplate {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal interface to provide a way to retrieve Zipkin URI. If there's no discovery
|
||||
* client then this value will be taken from the properties. Otherwise host will be
|
||||
* assumed to be a service id.
|
||||
*/
|
||||
interface ZipkinUrlExtractor {
|
||||
|
||||
URI zipkinUrl(ZipkinProperties zipkinProperties);
|
||||
|
||||
}
|
||||
|
||||
class NoOpZipkinLoadBalancer implements ZipkinLoadBalancer {
|
||||
|
||||
private final ZipkinProperties zipkinProperties;
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.sleuth.zipkin2;
|
||||
|
||||
import io.opentelemetry.sdk.trace.Sampler;
|
||||
import io.opentelemetry.sdk.trace.Samplers;
|
||||
import io.opentelemetry.sdk.trace.samplers.Sampler;
|
||||
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@@ -34,7 +33,7 @@ public class OtelZipkinDiscoveryClientTests extends ZipkinDiscoveryClientTests {
|
||||
|
||||
@Bean
|
||||
Sampler alwaysSampler() {
|
||||
return Samplers.alwaysOn();
|
||||
return Sampler.alwaysOn();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -85,6 +85,10 @@ public class ZipkinAutoConfigurationTests {
|
||||
|
||||
public MockWebServer server = new MockWebServer();
|
||||
|
||||
MockEnvironment environment = new MockEnvironment();
|
||||
|
||||
AnnotationConfigApplicationContext context;
|
||||
|
||||
@BeforeEach
|
||||
void setup() throws IOException {
|
||||
server.start();
|
||||
@@ -95,10 +99,6 @@ public class ZipkinAutoConfigurationTests {
|
||||
server.close();
|
||||
}
|
||||
|
||||
MockEnvironment environment = new MockEnvironment();
|
||||
|
||||
AnnotationConfigApplicationContext context;
|
||||
|
||||
@AfterEach
|
||||
public void close() {
|
||||
if (this.context != null) {
|
||||
@@ -167,7 +167,7 @@ public class ZipkinAutoConfigurationTests {
|
||||
Awaitility.await().atMost(250, TimeUnit.MILLISECONDS)
|
||||
.untilAsserted(() -> then(this.server.getRequestCount()).isGreaterThan(1));
|
||||
|
||||
Awaitility.await().atMost(1, TimeUnit.SECONDS).untilAsserted(() -> {
|
||||
Awaitility.await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> {
|
||||
RecordedRequest request = this.server.takeRequest(1, TimeUnit.SECONDS);
|
||||
then(request.getPath()).isEqualTo("/api/v2/spans");
|
||||
then(request.getBody().readUtf8()).contains("localEndpoint");
|
||||
@@ -195,7 +195,7 @@ public class ZipkinAutoConfigurationTests {
|
||||
Awaitility.await().atMost(250, TimeUnit.MILLISECONDS)
|
||||
.untilAsserted(() -> then(this.server.getRequestCount()).isGreaterThan(0));
|
||||
|
||||
Awaitility.await().atMost(1, TimeUnit.SECONDS).untilAsserted(() -> {
|
||||
Awaitility.await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> {
|
||||
RecordedRequest request = this.server.takeRequest(1, TimeUnit.SECONDS);
|
||||
then(request.getPath()).isEqualTo("/api/v1/spans");
|
||||
then(request.getBody().readUtf8()).contains("binaryAnnotations");
|
||||
@@ -310,7 +310,7 @@ public class ZipkinAutoConfigurationTests {
|
||||
Awaitility.await().atMost(250, TimeUnit.MILLISECONDS)
|
||||
.untilAsserted(() -> then(this.server.getRequestCount()).isGreaterThan(1));
|
||||
|
||||
Awaitility.await().atMost(1, TimeUnit.SECONDS).untilAsserted(() -> {
|
||||
Awaitility.await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> {
|
||||
RecordedRequest request = this.server.takeRequest(1, TimeUnit.SECONDS);
|
||||
then(request.getPath()).isEqualTo("/api/v2/spans");
|
||||
then(request.getBody().readUtf8()).contains("localEndpoint");
|
||||
|
||||
@@ -48,15 +48,15 @@ public class RestTemplateSenderTest {
|
||||
|
||||
public MockWebServer server = new MockWebServer();
|
||||
|
||||
String endpoint = this.server.url("/api/v2/spans").toString();
|
||||
|
||||
RestTemplateSender sender = new RestTemplateSender(new RestTemplate(), this.endpoint, JSON_V2);
|
||||
|
||||
@AfterEach
|
||||
void clean() throws IOException {
|
||||
server.close();
|
||||
}
|
||||
|
||||
String endpoint = this.server.url("/api/v2/spans").toString();
|
||||
|
||||
RestTemplateSender sender = new RestTemplateSender(new RestTemplate(), this.endpoint, JSON_V2);
|
||||
|
||||
/**
|
||||
* Tests that json is not manipulated as a side-effect of using rest template.
|
||||
* @throws Exception when span sending or receiving fails
|
||||
|
||||
Reference in New Issue
Block a user