Service name for the remote redis endpoint. (#1475)

fixes #1406
This commit is contained in:
worldtiki
2019-10-29 07:49:33 +00:00
committed by Marcin Grzejszczak
parent b4b597872f
commit bff52872e3
6 changed files with 85 additions and 54 deletions

View File

@@ -36,6 +36,7 @@
|spring.sleuth.propagation.tag.whitelisted-keys | | A list of keys to be put from extra propagation fields to span tags.
|spring.sleuth.reactor.enabled.enabled | true | When true enables instrumentation for reactor.
|spring.sleuth.redis.enabled | true | Enable span information propagation when using Redis.
|spring.sleuth.redis.remote-service-name | redis | Service name used for the remote Redis endpoint.
|spring.sleuth.rxjava.schedulers.hook.enabled | true | Enable support for RxJava via RxJavaSchedulersHook.
|spring.sleuth.rxjava.schedulers.ignoredthreads | [HystrixMetricPoller, ^RxComputation.*$] | Thread names for which spans will not be sampled.
|spring.sleuth.sampler.probability | | Probability of requests that should be sampled. E.g. 1.0 - 100% requests should be sampled. The precision is whole-numbers only (i.e. there's no support for 0.1% of the traces).

View File

@@ -1,39 +0,0 @@
/*
* Copyright 2013-2019 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
*
* https://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.instrument.redis;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
/**
* Verifies if Redis property was enabled.
*
* @author Chao Chang
* @since 2.2.0
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.METHOD })
@Documented
@ConditionalOnProperty(value = "spring.sleuth.redis.enabled", matchIfMissing = true)
@interface OnRedisEnabled {
}

View File

@@ -26,6 +26,8 @@ import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.sleuth.autoconfig.TraceAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -38,9 +40,10 @@ import org.springframework.context.annotation.Configuration;
* @since 2.2.0
*/
@Configuration(proxyBeanMethods = false)
@OnRedisEnabled
@ConditionalOnProperty(value = "spring.sleuth.redis.enabled", matchIfMissing = true)
@ConditionalOnBean({ Tracing.class, ClientResources.class })
@AutoConfigureAfter({ TraceAutoConfiguration.class })
@EnableConfigurationProperties(TraceRedisProperties.class)
public class TraceRedisAutoConfiguration {
@Configuration(proxyBeanMethods = false)
@@ -48,8 +51,9 @@ public class TraceRedisAutoConfiguration {
@Bean
static TraceLettuceClientResourcesBeanPostProcessor traceLettuceClientResourcesBeanPostProcessor(
Tracing tracing) {
return new TraceLettuceClientResourcesBeanPostProcessor(tracing);
Tracing tracing, TraceRedisProperties traceRedisProperties) {
return new TraceLettuceClientResourcesBeanPostProcessor(tracing,
traceRedisProperties);
}
}
@@ -63,8 +67,12 @@ class TraceLettuceClientResourcesBeanPostProcessor implements BeanPostProcessor
private final Tracing tracing;
TraceLettuceClientResourcesBeanPostProcessor(Tracing tracing) {
private final TraceRedisProperties traceRedisProperties;
TraceLettuceClientResourcesBeanPostProcessor(Tracing tracing,
TraceRedisProperties traceRedisProperties) {
this.tracing = tracing;
this.traceRedisProperties = traceRedisProperties;
}
@Override
@@ -83,7 +91,9 @@ class TraceLettuceClientResourcesBeanPostProcessor implements BeanPostProcessor
log.debug(
"Lettuce ClientResources bean is auto-configured to enable tracing.");
}
return cr.mutate().tracing(BraveTracing.create(this.tracing)).build();
BraveTracing lettuceTracing = BraveTracing.builder().tracing(this.tracing)
.serviceName(traceRedisProperties.getRemoteServiceName()).build();
return cr.mutate().tracing(lettuceTracing).build();
}
if (log.isDebugEnabled()) {
log.debug(

View File

@@ -0,0 +1,55 @@
/*
* Copyright 2013-2019 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
*
* https://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.instrument.redis;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* Sleuth Redis properties.
*
* @author Daniel Albuquerque
*/
@ConfigurationProperties("spring.sleuth.redis")
public class TraceRedisProperties {
/**
* Enable span information propagation when using Redis.
*/
private boolean enabled = true;
/**
* Service name for the remote Redis endpoint.
*/
private String remoteServiceName = "redis";
public boolean isEnabled() {
return this.enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public String getRemoteServiceName() {
return remoteServiceName;
}
public void setRemoteServiceName(String remoteServiceName) {
this.remoteServiceName = remoteServiceName;
}
}

View File

@@ -48,12 +48,6 @@
"description": "Enable span information propagation when using GRPC.",
"defaultValue": true
},
{
"name": "spring.sleuth.redis.enabled",
"type": "java.lang.Boolean",
"description": "Enable span information propagation when using Redis.",
"defaultValue": true
},
{
"name": "spring.sleuth.messaging.jms.enabled",
"type": "java.lang.Boolean",

View File

@@ -62,10 +62,19 @@ public class TraceRedisAutoConfigurationTests {
return clientResources;
}
@Bean
TraceRedisProperties traceRedisProperties() {
TraceRedisProperties traceRedisProperties = new TraceRedisProperties();
traceRedisProperties.setEnabled(true);
traceRedisProperties.setRemoteServiceName("redis-foo");
return traceRedisProperties;
}
@Bean
TestTraceLettuceClientResourcesBeanPostProcessor testTraceLettuceClientResourcesBeanPostProcessor(
Tracing tracing) {
return new TestTraceLettuceClientResourcesBeanPostProcessor(tracing);
Tracing tracing, TraceRedisProperties traceRedisProperties) {
return new TestTraceLettuceClientResourcesBeanPostProcessor(tracing,
traceRedisProperties);
}
}
@@ -77,8 +86,9 @@ class TestTraceLettuceClientResourcesBeanPostProcessor
boolean tracingCalled = false;
TestTraceLettuceClientResourcesBeanPostProcessor(Tracing tracing) {
super(tracing);
TestTraceLettuceClientResourcesBeanPostProcessor(Tracing tracing,
TraceRedisProperties traceRedisProperties) {
super(tracing, traceRedisProperties);
}
@Override