Deprecates SpanAdjuster for Brave's FirehoseHandler
Brave's `FirehoseHandler` has the features adjuster has, more efficiently and also including the ability to prune spans. See https://github.com/openzipkin/brave/pull/794
This commit is contained in:
@@ -19,16 +19,9 @@ package org.springframework.cloud.sleuth;
|
||||
import zipkin2.Span;
|
||||
|
||||
/**
|
||||
* Adds ability to adjust a span before reporting it.
|
||||
*
|
||||
* <b>IMPORTANT</b> - if you override the default {@link brave.Tracing} implementation,
|
||||
* remember to ensure that you pass to it an adjusted version of the {@link zipkin2.reporter.Reporter<zipkin2.Span>}
|
||||
* bean. In other words you must reuse the list of available {@link SpanAdjuster}s and
|
||||
* wrap the provided {@link zipkin2.reporter.Reporter} interface with it.
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
* @since 1.1.4
|
||||
* @deprecated use {@link brave.handler.FinishedSpanHandler}
|
||||
*/
|
||||
@Deprecated
|
||||
public interface SpanAdjuster {
|
||||
/**
|
||||
* You can adjust the {@link zipkin2.Span} by creating a new one using the {@link Span#toBuilder()}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.sleuth.autoconfig;
|
||||
|
||||
import brave.handler.FinishedSpanHandler;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -58,6 +59,7 @@ public class TraceAutoConfiguration {
|
||||
public static final String TRACER_BEAN_NAME = "tracer";
|
||||
|
||||
@Autowired(required = false) List<SpanAdjuster> spanAdjusters = new ArrayList<>();
|
||||
@Autowired(required = false) List<FinishedSpanHandler> finishedSpanHandlers = new ArrayList<>();
|
||||
@Autowired(required = false) List<CurrentTraceContext.ScopeDecorator> scopeDecorators = new ArrayList<>();
|
||||
|
||||
@Bean
|
||||
@@ -71,7 +73,7 @@ public class TraceAutoConfiguration {
|
||||
ErrorParser errorParser,
|
||||
SleuthProperties sleuthProperties
|
||||
) {
|
||||
return Tracing.newBuilder()
|
||||
Tracing.Builder builder = Tracing.newBuilder()
|
||||
.sampler(sampler)
|
||||
.errorParser(errorParser)
|
||||
.localServiceName(serviceName)
|
||||
@@ -79,8 +81,11 @@ public class TraceAutoConfiguration {
|
||||
.currentTraceContext(currentTraceContext)
|
||||
.spanReporter(adjustedReporter(reporter))
|
||||
.traceId128Bit(sleuthProperties.isTraceId128())
|
||||
.supportsJoin(sleuthProperties.isSupportsJoin())
|
||||
.build();
|
||||
.supportsJoin(sleuthProperties.isSupportsJoin());
|
||||
for (FinishedSpanHandler finishedSpanHandlerFactory : this.finishedSpanHandlers) {
|
||||
builder.addFinishedSpanHandler(finishedSpanHandlerFactory);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private Reporter<zipkin2.Span> adjustedReporter(Reporter<zipkin2.Span> delegate) {
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright 2013-2018 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
|
||||
*
|
||||
* http://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.cloud.sleuth;
|
||||
|
||||
import brave.Span;
|
||||
import brave.Tracer;
|
||||
import brave.handler.FinishedSpanHandler;
|
||||
import brave.handler.MutableSpan;
|
||||
import brave.propagation.TraceContext;
|
||||
import brave.sampler.Sampler;
|
||||
import org.assertj.core.api.BDDAssertions;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.sleuth.util.ArrayListSpanReporter;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import zipkin2.reporter.Reporter;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = FinishedSpanHandlerTests.FinishedSpanHandlerAspectTestsConfig.class,
|
||||
webEnvironment = SpringBootTest.WebEnvironment.NONE)
|
||||
public class FinishedSpanHandlerTests {
|
||||
|
||||
@Autowired ArrayListSpanReporter reporter;
|
||||
@Autowired Tracer tracer;
|
||||
|
||||
@Test
|
||||
public void should_adjust_span_twice_before_reporting() {
|
||||
Span hello = this.tracer.nextSpan().name("hello").start();
|
||||
|
||||
hello.finish();
|
||||
|
||||
BDDAssertions.then(this.reporter.getSpans()).hasSize(1);
|
||||
BDDAssertions.then(this.reporter.getSpans().get(0).name()).isEqualTo("foo bar");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration(exclude = IntegrationAutoConfiguration.class)
|
||||
static class FinishedSpanHandlerAspectTestsConfig {
|
||||
@Bean Sampler sampler() {
|
||||
return Sampler.ALWAYS_SAMPLE;
|
||||
}
|
||||
|
||||
@Bean Reporter<zipkin2.Span> reporter() {
|
||||
return new ArrayListSpanReporter();
|
||||
}
|
||||
|
||||
// tag::finishedSpanHandler[]
|
||||
@Bean FinishedSpanHandler handlerOne() {
|
||||
return new FinishedSpanHandler() {
|
||||
@Override public boolean handle(TraceContext traceContext, MutableSpan span) {
|
||||
span.name("foo");
|
||||
return true; // keep this span
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Bean FinishedSpanHandler handlerTwo() {
|
||||
return new FinishedSpanHandler() {
|
||||
@Override public boolean handle(TraceContext traceContext, MutableSpan span) {
|
||||
span.name(span.name() + " bar");
|
||||
return true; // keep this span
|
||||
}
|
||||
};
|
||||
}
|
||||
// end::finishedSpanHandler[]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user