Prefers "plain bean names" for community instrumentation (#885)

Instrumentation around brave is more likely to use a simple bean name
like "tracing" vs "sleuthTracing". This changes the commodity beans to
simple names so that we can avoid having to teach naming prefixes unless
necessary.

This affects the following beans:
* httpTracing
* tracing
* tracer
* spanCustomizer

This came up when integrating dubbo, as their extension loader prefers
stable bean names. For example, loading `brave.Tracing` with their
spring extension silently failed because our bean was named
"sleuthTracing". Even if we can provide instructions to override this,
seems best to dodge.
This commit is contained in:
Adrian Cole
2018-03-06 19:33:23 +08:00
committed by Marcin Grzejszczak
parent 54c00b76ea
commit 2e974e8ce7
2 changed files with 22 additions and 17 deletions

View File

@@ -61,7 +61,8 @@ public class TraceAutoConfiguration {
@Bean
@ConditionalOnMissingBean
Tracing sleuthTracing(@Value("${spring.zipkin.service.name:${spring.application.name:default}}") String serviceName,
// NOTE: stable bean name as might be used outside sleuth
Tracing tracing(@Value("${spring.zipkin.service.name:${spring.application.name:default}}") String serviceName,
Propagation.Factory factory,
CurrentTraceContext currentTraceContext,
Reporter<zipkin2.Span> reporter,
@@ -86,7 +87,8 @@ public class TraceAutoConfiguration {
@Bean
@ConditionalOnMissingBean
Tracer sleuthTracer(Tracing tracing) {
// NOTE: stable bean name as might be used outside sleuth
Tracer tracer(Tracing tracing) {
return tracing.tracer();
}
@@ -144,7 +146,8 @@ public class TraceAutoConfiguration {
@Bean
@ConditionalOnMissingBean
CurrentSpanCustomizer sleuthCurrentSpanCustomizer(Tracing tracing) {
// NOTE: stable bean name as might be used outside sleuth
CurrentSpanCustomizer spanCustomizer(Tracing tracing) {
return CurrentSpanCustomizer.create(tracing);
}
}

View File

@@ -18,6 +18,7 @@ package org.springframework.cloud.sleuth.instrument.web;
import brave.Tracing;
import brave.http.HttpTracing;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@@ -42,23 +43,24 @@ public class TraceHttpAutoConfiguration {
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(name = "spring.sleuth.http.legacy.enabled", havingValue = "false", matchIfMissing = true)
HttpTracing sleuthHttpTracing(Tracing tracing, SkipPatternProvider provider) {
// NOTE: stable bean name as might be used outside sleuth
HttpTracing httpTracing(
@Value("${spring.sleuth.http.legacy.enabled:false}") boolean legacyEnabled,
Tracing tracing,
TraceKeys traceKeys,
ErrorParser errorParser,
SkipPatternProvider provider
) {
if (legacyEnabled) {
return HttpTracing.newBuilder(tracing)
.clientParser(new SleuthHttpClientParser(traceKeys))
.serverParser(new SleuthHttpServerParser(traceKeys, errorParser))
.serverSampler(new SleuthHttpSampler(provider))
.build();
}
return HttpTracing
.newBuilder(tracing)
.serverSampler(new SleuthHttpSampler(provider))
.build();
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(name = "spring.sleuth.http.legacy.enabled", havingValue = "true")
HttpTracing legacySleuthHttpTracing(Tracing tracing, TraceKeys traceKeys,
ErrorParser errorParser, SkipPatternProvider provider) {
return HttpTracing.newBuilder(tracing)
.clientParser(new SleuthHttpClientParser(traceKeys))
.serverParser(new SleuthHttpServerParser(traceKeys, errorParser))
.serverSampler(new SleuthHttpSampler(provider))
.build();
}
}