|
|
@@ -18,11 +18,7 @@ package com.alibaba.csp.sentinel; |
|
|
|
import com.alibaba.csp.sentinel.context.Context; |
|
|
|
import com.alibaba.csp.sentinel.context.ContextUtil; |
|
|
|
import com.alibaba.csp.sentinel.context.NullContext; |
|
|
|
import com.alibaba.csp.sentinel.metric.extension.MetricExtensionProvider; |
|
|
|
import com.alibaba.csp.sentinel.node.ClusterNode; |
|
|
|
import com.alibaba.csp.sentinel.node.DefaultNode; |
|
|
|
import com.alibaba.csp.sentinel.slots.block.BlockException; |
|
|
|
import com.alibaba.csp.sentinel.metric.extension.MetricExtension; |
|
|
|
import com.alibaba.csp.sentinel.util.AssertUtil; |
|
|
|
|
|
|
|
/** |
|
|
@@ -39,32 +35,33 @@ public class Tracer { |
|
|
|
protected Tracer() {} |
|
|
|
|
|
|
|
/** |
|
|
|
* Trace provided {@link Throwable} and increment exception count to entry in current context. |
|
|
|
* Trace provided {@link Throwable} to the resource entry in current context. |
|
|
|
* |
|
|
|
* @param e exception to record |
|
|
|
*/ |
|
|
|
public static void trace(Throwable e) { |
|
|
|
trace(e, 1); |
|
|
|
traceContext(e, ContextUtil.getContext()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Trace provided {@link Throwable} and add exception count to entry in current context. |
|
|
|
* Trace provided {@link Throwable} to current entry in current context. |
|
|
|
* |
|
|
|
* @param e exception to record |
|
|
|
* @param count exception count to add |
|
|
|
*/ |
|
|
|
@Deprecated |
|
|
|
public static void trace(Throwable e, int count) { |
|
|
|
traceContext(e, count, ContextUtil.getContext()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Trace provided {@link Throwable} and add exception count to current entry in provided context. |
|
|
|
* Trace provided {@link Throwable} to current entry of given entrance context. |
|
|
|
* |
|
|
|
* @param e exception to record |
|
|
|
* @param count exception count to add |
|
|
|
* @since 1.4.2 |
|
|
|
* @param context target entrance context |
|
|
|
* @since 1.8.0 |
|
|
|
*/ |
|
|
|
public static void traceContext(Throwable e, int count, Context context) { |
|
|
|
public static void traceContext(Throwable e, Context context) { |
|
|
|
if (!shouldTrace(e)) { |
|
|
|
return; |
|
|
|
} |
|
|
@@ -72,49 +69,47 @@ public class Tracer { |
|
|
|
if (context == null || context instanceof NullContext) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
DefaultNode curNode = (DefaultNode)context.getCurNode(); |
|
|
|
traceExceptionToNode(e, count, context.getCurEntry(), curNode); |
|
|
|
traceEntryInternal(e, context.getCurEntry()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Trace provided {@link Throwable} and increment exception count to provided entry. |
|
|
|
* Trace provided {@link Throwable} and add exception count to current entry in provided context. |
|
|
|
* |
|
|
|
* @param e exception to record |
|
|
|
* @param e exception to record |
|
|
|
* @param count exception count to add |
|
|
|
* @since 1.4.2 |
|
|
|
*/ |
|
|
|
public static void traceEntry(Throwable e, Entry entry) { |
|
|
|
traceEntry(e, 1, entry); |
|
|
|
@Deprecated |
|
|
|
public static void traceContext(Throwable e, int count, Context context) { |
|
|
|
if (!shouldTrace(e)) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (context == null || context instanceof NullContext) { |
|
|
|
return; |
|
|
|
} |
|
|
|
traceEntryInternal(e, context.getCurEntry()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Trace provided {@link Throwable} and add exception count to provided entry. |
|
|
|
* Trace provided {@link Throwable} to the given resource entry. |
|
|
|
* |
|
|
|
* @param e exception to record |
|
|
|
* @param count exception count to add |
|
|
|
* @param e exception to record |
|
|
|
* @since 1.4.2 |
|
|
|
*/ |
|
|
|
public static void traceEntry(Throwable e, int count, Entry entry) { |
|
|
|
public static void traceEntry(Throwable e, Entry entry) { |
|
|
|
if (!shouldTrace(e)) { |
|
|
|
return; |
|
|
|
} |
|
|
|
if (entry == null || entry.getCurNode() == null) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
DefaultNode curNode = (DefaultNode)entry.getCurNode(); |
|
|
|
traceExceptionToNode(e, count, entry, curNode); |
|
|
|
traceEntryInternal(e, entry); |
|
|
|
} |
|
|
|
|
|
|
|
private static void traceExceptionToNode(Throwable t, int count, Entry entry, DefaultNode curNode) { |
|
|
|
if (curNode == null) { |
|
|
|
private static void traceEntryInternal(/*@NeedToTrace*/ Throwable e, Entry entry) { |
|
|
|
if (entry == null) { |
|
|
|
return; |
|
|
|
} |
|
|
|
for (MetricExtension m : MetricExtensionProvider.getMetricExtensions()) { |
|
|
|
m.addException(entry.getResourceWrapper().getName(), count, t); |
|
|
|
} |
|
|
|
|
|
|
|
curNode.trace(t, count); |
|
|
|
entry.setError(e); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@@ -203,4 +198,4 @@ public class Tracer { |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |