From ea57bb30888f66b75c90e4b3732d128868179141 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Fri, 29 Jul 2016 12:43:15 +0200 Subject: [PATCH] Unified tag names with this change the tags related to method and class name will not be hyphen delimited. fixes #359 --- .../instrument/web/TraceHandlerInterceptor.java | 10 ++++------ .../web/TraceFilterIntegrationTests.java | 14 +++++++------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceHandlerInterceptor.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceHandlerInterceptor.java index c9d87e7bc..f23cbd952 100644 --- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceHandlerInterceptor.java +++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceHandlerInterceptor.java @@ -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); diff --git a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/TraceFilterIntegrationTests.java b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/TraceFilterIntegrationTests.java index c92ce253c..a47d290d5 100644 --- a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/TraceFilterIntegrationTests.java +++ b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/TraceFilterIntegrationTests.java @@ -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 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 deferred() { + public DeferredResult deferredMethod() { logger.info("deferred"); this.tracer.addTag("tag", "value"); span = this.tracer.getCurrentSpan();