Wraped debug logs with conditional

This commit is contained in:
Marcin Grzejszczak
2016-08-17 13:54:12 +02:00
parent 9e900569a9
commit fdea5d6bac
8 changed files with 51 additions and 23 deletions

View File

@@ -84,11 +84,13 @@ public class SleuthHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy
private void logCurrentStateOfHysrixPlugins(HystrixEventNotifier eventNotifier,
HystrixMetricsPublisher metricsPublisher,
HystrixPropertiesStrategy propertiesStrategy) {
log.debug("Current Hystrix plugins configuration is [" + "concurrencyStrategy ["
+ this.delegate + "]," + "eventNotifier [" + eventNotifier + "],"
+ "metricPublisher [" + metricsPublisher + "]," + "propertiesStrategy ["
+ propertiesStrategy + "]," + "]");
log.debug("Registering Sleuth Hystrix Concurrency Strategy.");
if (log.isDebugEnabled()) {
log.debug("Current Hystrix plugins configuration is [" + "concurrencyStrategy ["
+ this.delegate + "]," + "eventNotifier [" + eventNotifier + "],"
+ "metricPublisher [" + metricsPublisher + "]," + "propertiesStrategy ["
+ propertiesStrategy + "]," + "]");
log.debug("Registering Sleuth Hystrix Concurrency Strategy.");
}
}
@Override

View File

@@ -16,9 +16,9 @@
package org.springframework.cloud.sleuth.instrument.web;
import javax.servlet.http.HttpServletRequest;
import java.lang.invoke.MethodHandles;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -66,8 +66,10 @@ class HttpServletRequestExtractor implements SpanExtractor<HttpServletRequest> {
private long spanId(HttpServletRequest carrier, long traceId) {
String spanId = carrier.getHeader(Span.SPAN_ID_NAME);
if (spanId == null) {
log.debug("Request is missing a span id but it has a trace id. We'll assume that this is "
+ "a root span with span id equal to trace id");
if (log.isDebugEnabled()) {
log.debug("Request is missing a span id but it has a trace id. We'll assume that this is "
+ "a root span with span id equal to trace id");
}
return traceId;
} else {
return Span.hexToId(spanId);

View File

@@ -315,7 +315,9 @@ public class TraceFilter extends GenericFilterBean {
}
spanFromRequest.logEvent(Span.SERVER_RECV);
request.setAttribute(TRACE_REQUEST_ATTR, spanFromRequest);
log.debug("No parent span present - creating a new span");
if (log.isDebugEnabled()) {
log.debug("No parent span present - creating a new span");
}
}
return spanFromRequest;
}

View File

@@ -62,11 +62,15 @@ public class TraceHandlerInterceptor extends HandlerInterceptorAdapter {
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
Object handler) throws Exception {
if (isErrorControllerRelated(request)) {
log.debug("Skipping creation of a span for error controller processing");
if (log.isDebugEnabled()) {
log.debug("Skipping creation of a span for error controller processing");
}
return true;
}
if (isSpanContinued(request)) {
log.debug("Skipping creation of a span since the span is continued");
if (log.isDebugEnabled()) {
log.debug("Skipping creation of a span since the span is continued");
}
return true;
}
String spanName = spanName(handler);
@@ -131,11 +135,15 @@ public class TraceHandlerInterceptor extends HandlerInterceptorAdapter {
public void afterCompletion(HttpServletRequest request, HttpServletResponse response,
Object handler, Exception ex) throws Exception {
if (isErrorControllerRelated(request)) {
log.debug("Skipping closing of a span for error controller processing");
if (log.isDebugEnabled()) {
log.debug("Skipping closing of a span for error controller processing");
}
return;
}
if (isSpanContinued(request)) {
log.debug("Skipping closing of a span since it's been continued");
if (log.isDebugEnabled()) {
log.debug("Skipping closing of a span since it's been continued");
}
return;
}
Span span = getSpanFromAttribute(request);

View File

@@ -100,8 +100,9 @@ public class TraceWebAspect {
public Object wrapWithCorrelationId(ProceedingJoinPoint pjp) throws Throwable {
Callable<Object> callable = (Callable<Object>) pjp.proceed();
if (this.tracer.isTracing()) {
log.debug("Wrapping callable with span ["
+ this.tracer.getCurrentSpan() + "]");
if (log.isDebugEnabled()) {
log.debug("Wrapping callable with span [" + this.tracer.getCurrentSpan() + "]");
}
return new TraceContinuingCallable<>(this.tracer, this.spanNamer, callable);
}
else {
@@ -114,8 +115,10 @@ public class TraceWebAspect {
final WebAsyncTask<?> webAsyncTask = (WebAsyncTask<?>) pjp.proceed();
if (this.tracer.isTracing()) {
try {
log.debug("Wrapping callable with span ["
+ this.tracer.getCurrentSpan() + "]");
if (log.isDebugEnabled()) {
log.debug("Wrapping callable with span [" + this.tracer.getCurrentSpan()
+ "]");
}
Field callableField = WebAsyncTask.class.getDeclaredField("callable");
callableField.setAccessible(true);
callableField.set(webAsyncTask, new TraceContinuingCallable<>(this.tracer,

View File

@@ -92,7 +92,9 @@ final class TraceFeignClient implements Client {
private void closeSpan() {
Span span = getTracer().getCurrentSpan();
if (span != null) {
log.debug("Closing Feign span " + span);
if (log.isDebugEnabled()) {
log.debug("Closing Feign span " + span);
}
getTracer().close(span);
}
}
@@ -100,7 +102,9 @@ final class TraceFeignClient implements Client {
private void logCr() {
Span span = getTracer().getCurrentSpan();
if (span != null) {
log.debug("Closing Feign span and logging CR" + span);
if (log.isDebugEnabled()) {
log.debug("Closing Feign span and logging CR" + span);
}
span.logEvent(Span.CLIENT_RECV);
}
}
@@ -109,7 +113,9 @@ final class TraceFeignClient implements Client {
Span span = getTracer().getCurrentSpan();
if (span != null) {
String message = e.getMessage() != null ? e.getMessage() : e.toString();
log.debug("Appending exception [" + message + "] to span " + span);
if (log.isDebugEnabled()) {
log.debug("Appending exception [" + message + "] to span " + span);
}
getTracer().addTag("error", message);
}
}

View File

@@ -96,8 +96,11 @@ final class ConvertToZipkinSpanList {
zipkinSpan.traceId(span.getTraceId());
if (span.getParents().size() > 0) {
if (span.getParents().size() > 1) {
log.debug("zipkin doesn't support spans with multiple parents. Omitting "
+ "other parents for " + span);
if (log.isDebugEnabled()) {
log.debug(
"zipkin doesn't support spans with multiple parents. Omitting "
+ "other parents for " + span);
}
}
zipkinSpan.parentId(span.getParents().get(0));
}

View File

@@ -86,7 +86,9 @@ public final class HttpZipkinSpanReporter
byte[] json = Codec.JSON.writeSpans(drained);
// NOTE: https://github.com/openzipkin/zipkin-java/issues/66 will throw instead of return null.
if (json == null) {
log.debug("failed to encode spans, dropping them: " + drained);
if (log.isDebugEnabled()) {
log.debug("failed to encode spans, dropping them: " + drained);
}
this.spanMetricReporter.incrementDroppedSpans(drained.size());
return;
}