Skip to content

Commit

Permalink
feat: add an encoder bean in Trace auto-configuration (#1568)
Browse files Browse the repository at this point in the history
* feat: add an encoder bean

* fix typo in comment
  • Loading branch information
JoeWang1127 authored Feb 3, 2023
1 parent 1dabdc9 commit deb4239
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import zipkin2.CheckResult;
import zipkin2.Span;
import zipkin2.codec.BytesEncoder;
import zipkin2.codec.SpanBytesEncoder;
import zipkin2.reporter.AsyncReporter;
import zipkin2.reporter.Reporter;
import zipkin2.reporter.ReporterMetrics;
Expand Down Expand Up @@ -250,6 +252,13 @@ public BaggagePropagation.FactoryBuilder baggagePropagationFactoryBuilder() {
return BaggagePropagation.newFactoryBuilder(StackdriverTracePropagation.newFactory(primary));
}

// Add this bean to suppress other encoding schema, e.g., JSON.
@Bean
@ConditionalOnMissingBean
public BytesEncoder<Span> spanBytesEncoder() {
return SpanBytesEncoder.PROTO3;
}

@PreDestroy
public void closeScheduler() {
if (this.defaultTraceSenderThreadPool != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import zipkin2.Call;
import zipkin2.CheckResult;
import zipkin2.codec.BytesEncoder;
import zipkin2.codec.Encoding;
import zipkin2.codec.SpanBytesEncoder;
import zipkin2.reporter.AsyncReporter;
Expand Down Expand Up @@ -102,6 +103,15 @@ void test() {
});
}

@Test
void testEncodingSchema() {
this.contextRunner
.run(
context -> assertThat(
context.getBean(BytesEncoder.class))
.isEqualTo(SpanBytesEncoder.PROTO3));
}

@Test
void testDefaultConfig() {
this.contextRunner
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2022 the original author or authors.
* Copyright 2017-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.
Expand Down Expand Up @@ -30,7 +30,6 @@
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.tracing.zipkin.ZipkinAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
Expand All @@ -48,7 +47,7 @@

/** Sample spring boot application. */
@AutoConfiguration
@SpringBootApplication(exclude = ZipkinAutoConfiguration.class)
@SpringBootApplication
public class Application implements WebMvcConfigurer {
private static final Logger LOGGER = LoggerFactory.getLogger(Application.class);

Expand Down

0 comments on commit deb4239

Please sign in to comment.