/** * Trace provided {@link Throwable} and increment exception count to entry in current context. * * @param e exception to record */ public static void trace(Throwable e) { trace(e, 1); }
/** * Trace provided {@link Throwable} and increment exception count to provided entry. * * @param e exception to record * @since 1.4.2 */ public static void traceEntry(Throwable e, Entry entry) { traceEntry(e, 1, entry); }
/** * Trace provided {@link Throwable} and add exception count to current entry in provided context. * * @param e exception to record * @param count exception count to add * @since 1.4.2 */ public static void traceContext(Throwable e, int count, Context context) { if (e == null || e instanceof BlockException) { return; } if (context == null) { return; } DefaultNode curNode = (DefaultNode)context.getCurNode(); traceExceptionToNode(e, count, curNode); }
private void recordException(Throwable t) { Tracer.trace(t); } }
/** * Trace provided {@link Throwable} and add exception count to provided entry. * * @param e exception to record * @param count exception count to add * @since 1.4.2 */ public static void traceEntry(Throwable e, int count, Entry entry) { if (e == null || e instanceof BlockException) { return; } if (entry == null || entry.getCurNode() == null) { return; } DefaultNode curNode = (DefaultNode)entry.getCurNode(); traceExceptionToNode(e, count, curNode); }
private void recordException(Throwable t) { Tracer.trace(t); } }
/** * Trace provided {@link Throwable} and add exception count to entry in current context. * * @param e exception to record * @param count exception count to add */ public static void trace(Throwable e, int count) { if (e == null || e instanceof BlockException) { return; } Context context = ContextUtil.getContext(); if (context == null) { return; } DefaultNode curNode = (DefaultNode)context.getCurNode(); traceExceptionToNode(e, count, curNode); }
@Override public void run() { int count = 0; while (true) { count++; Entry entry = null; try { Thread.sleep(20); entry = SphU.entry(KEY); // token acquired, means pass pass.addAndGet(1); if (count % 2 == 0) { // biz code raise an exception. throw new RuntimeException("throw runtime "); } } catch (BlockException e) { block.addAndGet(1); } catch (Throwable t) { bizException.incrementAndGet(); Tracer.trace(t); } finally { total.addAndGet(1); if (entry != null) { entry.exit(); } } } }
@Override public void run() { int count = 0; while (true) { count++; Entry entry = null; try { Thread.sleep(20); entry = SphU.entry(KEY); // token acquired, means pass pass.addAndGet(1); if (count % 2 == 0) { // biz code raise an exception. throw new RuntimeException("throw runtime "); } } catch (BlockException e) { block.addAndGet(1); } catch (Throwable t) { bizException.incrementAndGet(); Tracer.trace(t); } finally { total.addAndGet(1); if (entry != null) { entry.exit(); } } } }
@Around("sentinelResourceAnnotationPointcut()") public Object invokeResourceWithSentinel(ProceedingJoinPoint pjp) throws Throwable { Method originMethod = resolveMethod(pjp); SentinelResource annotation = originMethod.getAnnotation(SentinelResource.class); if (annotation == null) { // Should not go through here. throw new IllegalStateException("Wrong state for SentinelResource annotation"); } String resourceName = getResourceName(annotation.value(), originMethod); EntryType entryType = annotation.entryType(); Entry entry = null; try { entry = SphU.entry(resourceName, entryType, 1, pjp.getArgs()); Object result = pjp.proceed(); return result; } catch (BlockException ex) { return handleBlockException(pjp, annotation, ex); } catch (Throwable ex) { Tracer.trace(ex); throw ex; } finally { if (entry != null) { entry.exit(); } } } }
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest sRequest = (HttpServletRequest)request; String target = FilterUtil.filterTarget(sRequest); target = WebCallbackManager.getUrlCleaner().clean(target); Entry entry = null; try { ContextUtil.enter(target); entry = SphU.entry(TOTAL_URL_REQUEST); chain.doFilter(request, response); } catch (BlockException e) { HttpServletResponse sResponse = (HttpServletResponse)response; WebCallbackManager.getUrlBlockHandler().blocked(sRequest, sResponse, e); } catch (IOException e2) { Tracer.trace(e2); throw e2; } catch (ServletException e3) { Tracer.trace(e3); throw e3; } catch (RuntimeException e4) { Tracer.trace(e4); throw e4; } finally { if (entry != null) { entry.exit(); } ContextUtil.exit(); } }
Tracer.trace(e); throw new IllegalStateException(e);
@Override public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { Entry interfaceEntry = null; Entry methodEntry = null; try { String resourceName = getResourceName(invoker, invocation); interfaceEntry = SphU.entry(invoker.getInterface().getName(), EntryType.OUT); methodEntry = SphU.entry(resourceName, EntryType.OUT); Result result = invoker.invoke(invocation); if (result.hasException()) { // Record common exception. Tracer.trace(result.getException()); } return result; } catch (BlockException e) { return DubboFallbackRegistry.getConsumerFallback().handle(invoker, invocation, e); } catch (RpcException e) { Tracer.trace(e); throw e; } finally { if (methodEntry != null) { methodEntry.exit(); } if (interfaceEntry != null) { interfaceEntry.exit(); } } } }
/** * Trace not {@link BlockException} ex. * While loop will exit all entries, * Case serviceId and URL entry twice in {@link SentinelPreFilter}. * The ContextUtil.getContext().getCurEntry() will exit from inner to outer. */ @Override public Object run() throws ZuulException { try { RequestContext ctx = RequestContext.getCurrentContext(); Throwable throwable = ctx.getThrowable(); if (throwable != null) { if (!BlockException.isBlockException(throwable)) { Tracer.trace(throwable.getCause()); RecordLog.info("[Sentinel Error Filter] Trace cause", throwable.getCause()); } } } finally { while (ContextUtil.getContext() != null && ContextUtil.getContext().getCurEntry() != null) { ContextUtil.getContext().getCurEntry().exit(); } ContextUtil.exit(); } return null; } }
public static void trace(Throwable e) { trace(e, 1); }
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest sRequest = (HttpServletRequest)request; String target = FilterUtil.filterTarget(sRequest); target = WebCallbackManager.getUrlCleaner().clean(target); Entry entry = null; try { ContextUtil.enter(target); entry = SphU.entry(TOTAL_URL_REQUEST); chain.doFilter(request, response); } catch (BlockException e) { HttpServletResponse sResponse = (HttpServletResponse)response; WebCallbackManager.getUrlBlockHandler().blocked(sRequest, sResponse, e); } catch (IOException e2) { Tracer.trace(e2); throw e2; } catch (ServletException e3) { Tracer.trace(e3); throw e3; } catch (RuntimeException e4) { Tracer.trace(e4); throw e4; } finally { if (entry != null) { entry.exit(); } ContextUtil.exit(); } }
Tracer.trace(e); throw new IllegalStateException(e);