private String generateSubParentLevelId(Span spanData) { if (spanData.getParentLevel() == null || spanData.getParentLevel().length() == 0) { return spanData.getLevelId() + ""; } return spanData.getParentLevel() + "." + spanData.getLevelId(); }
protected ContextData beforeInvoke(Span spanData, Identification id) { if (Config.BuriedPoint.PRINTF) { easyLogger.debug( "TraceId:" + spanData.getTraceId() + "\tParentLevelId:" + spanData.getParentLevel() + "\tLevelId:" + spanData.getLevelId() + "\tbusinessKey:" + spanData.getBusinessKey()); } // 将新创建的Context存放到ThreadLocal栈中。 CurrentThreadSpanStack.push(spanData); // 根据SpanData生成RequestSpan,并保存 CurrentThreadSpanStack.push(spanData); sendRequestSpan(spanData, id); // 并将当前的Context返回回去 return new ContextData(spanData); }
public ContextData beforeInvoke(Identification id) { try { Span spanData = ContextGenerator.generateSpanFromThreadLocal(id); // 设置SpanType的类型 spanData.setTag(Tag.SPAN_TYPE, SpanType.RPC_CLIENT); if (Config.BuriedPoint.PRINTF) { logger.debug( "TraceId:" + spanData.getTraceId() + "\tParentLevelId:" + spanData.getParentLevel() + "\tLevelId:" + spanData.getLevelId() + "\tbusinessKey:" + spanData.getBusinessKey()); } CurrentThreadSpanStack.push(spanData); sendRequestSpan(spanData, id); return new ContextData( spanData.getTraceId(), generateSubParentLevelId(spanData), spanData.getRouteKey()); } catch (Throwable t) { logger.error(t.getMessage(), t); return new EmptyContextData(); } }
protected void afterInvoke() { try { // 弹出上下文的栈顶中的元素 Span spanData = CurrentThreadSpanStack.pop(); if (Config.BuriedPoint.PRINTF) { easyLogger.debug( "TraceId-ACK:" + spanData.getTraceId() + "\tParentLevelId:" + spanData.getParentLevel() + "\tLevelId:" + spanData.getLevelId() + "\tbusinessKey:" + spanData.getBusinessKey()); } sendAckSpan(spanData); } catch (Throwable t) { easyLogger.error(t.getMessage(), t); } }