Unified tag names

with this change the tags related to method and class name will not be hyphen delimited.

fixes #359
This commit is contained in:
Marcin Grzejszczak
2016-07-29 12:43:15 +02:00
parent 46d18e83a7
commit ea57bb3088
2 changed files with 11 additions and 13 deletions

View File

@@ -16,9 +16,9 @@
package org.springframework.cloud.sleuth.instrument.web;
import java.lang.invoke.MethodHandles;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.invoke.MethodHandles;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -87,8 +87,7 @@ public class TraceHandlerInterceptor extends HandlerInterceptorAdapter {
private void addClassMethodTag(Object handler, Span span) {
if (handler instanceof HandlerMethod) {
String methodName = SpanNameUtil.toLowerHyphen(
((HandlerMethod) handler).getMethod().getName());
String methodName = ((HandlerMethod) handler).getMethod().getName();
getTracer().addTag(getTraceKeys().getMvc().getControllerMethod(), methodName);
if (log.isDebugEnabled()) {
log.debug("Adding a method tag with value [" + methodName + "] to a span " + span);
@@ -99,10 +98,9 @@ public class TraceHandlerInterceptor extends HandlerInterceptorAdapter {
private void addClassNameTag(Object handler, Span span) {
String className;
if (handler instanceof HandlerMethod) {
className = SpanNameUtil.toLowerHyphen(
((HandlerMethod) handler).getBeanType().getSimpleName());
className = ((HandlerMethod) handler).getBeanType().getSimpleName();
} else {
className = SpanNameUtil.toLowerHyphen(handler.getClass().getSimpleName());
className = handler.getClass().getSimpleName();
}
if (log.isDebugEnabled()) {
log.debug("Adding a class tag with value [" + className + "] to a span " + span);

View File

@@ -85,7 +85,7 @@ public class TraceFilterIntegrationTests extends AbstractMvcIntegrationTest {
throws Exception {
Long expectedTraceId = new Random().nextLong();
MvcResult mvcResult = whenSentPingWithTraceId(expectedTraceId);
whenSentPingWithTraceId(expectedTraceId);
then(ExceptionUtils.getLastException()).isNull();
}
@@ -105,7 +105,7 @@ public class TraceFilterIntegrationTests extends AbstractMvcIntegrationTest {
Long expectedTraceId = new Random().nextLong();
MvcResult mvcResult = whenSentFutureWithTraceId(expectedTraceId);
mvcResult = this.mockMvc.perform(asyncDispatch(mvcResult))
this.mockMvc.perform(asyncDispatch(mvcResult))
.andExpect(status().isOk()).andReturn();
then(this.tracer.getCurrentSpan()).isNull();
@@ -117,15 +117,15 @@ public class TraceFilterIntegrationTests extends AbstractMvcIntegrationTest {
Long expectedTraceId = new Random().nextLong();
MvcResult mvcResult = whenSentDeferredWithTraceId(expectedTraceId);
mvcResult = this.mockMvc.perform(asyncDispatch(mvcResult))
this.mockMvc.perform(asyncDispatch(mvcResult))
.andExpect(status().isOk()).andReturn();
Optional<Span> taggedSpan = this.spanAccumulator.getSpans().stream()
.filter(span -> span.tags().containsKey("tag")).findFirst();
then(taggedSpan.isPresent()).isTrue();
then(taggedSpan.get()).hasATag("tag", "value");
then(taggedSpan.get()).hasATag("mvc.controller.method", "deferred");
then(taggedSpan.get()).hasATag("mvc.controller.class", "test-controller");
then(taggedSpan.get()).hasATag("mvc.controller.method", "deferredMethod");
then(taggedSpan.get()).hasATag("mvc.controller.class", "TestController");
then(ExceptionUtils.getLastException()).isNull();
}
@@ -133,7 +133,7 @@ public class TraceFilterIntegrationTests extends AbstractMvcIntegrationTest {
public void should_log_tracing_information_when_exception_was_thrown() throws Exception {
Long expectedTraceId = new Random().nextLong();
MvcResult mvcResult = whenSentToNonExistentEndpointWithTraceId(expectedTraceId);
whenSentToNonExistentEndpointWithTraceId(expectedTraceId);
then(this.tracer.getCurrentSpan()).isNull();
then(ExceptionUtils.getLastException()).isNull();
@@ -248,7 +248,7 @@ public class TraceFilterIntegrationTests extends AbstractMvcIntegrationTest {
}
@RequestMapping("/deferred")
public DeferredResult<String> deferred() {
public DeferredResult<String> deferredMethod() {
logger.info("deferred");
this.tracer.addTag("tag", "value");
span = this.tracer.getCurrentSpan();