예제 #1
0
  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);
  }
  private String generateSubParentLevelId(Span spanData) {
    if (spanData.getParentLevel() == null || spanData.getParentLevel().length() == 0) {
      return spanData.getLevelId() + "";
    }

    return spanData.getParentLevel() + "." + spanData.getLevelId();
  }
  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();
    }
  }
예제 #4
0
  protected void occurException(Throwable th) {
    try {
      if (exclusiveExceptionSet == null) {
        Set<String> exclusiveExceptions = new HashSet<String>();

        String[] exceptions = Config.BuriedPoint.EXCLUSIVE_EXCEPTIONS.split(EXCEPTION_SPLIT);
        for (String exception : exceptions) {
          exclusiveExceptions.add(exception);
        }
        exclusiveExceptionSet = exclusiveExceptions;
      }

      Span span = CurrentThreadSpanStack.peek();
      span.handleException(
          th, exclusiveExceptionSet, Config.BuriedPoint.MAX_EXCEPTION_STACK_LENGTH);
    } catch (Throwable t) {
      easyLogger.error(t.getMessage(), t);
    }
  }
예제 #5
0
  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);
    }
  }
예제 #6
0
  protected void sendRequestSpan(Span span, Identification id) {
    RequestSpan.Builder requestSpanBuilder = span.buildRequestSpan(RequestSpan.newBuilder());
    if (id.getBusinessKey() != null && id.getBusinessKey().length() > 0) {
      requestSpanBuilder = requestSpanBuilder.setBusinessKey(id.getBusinessKey());
    }
    RequestSpan requestSpan =
        requestSpanBuilder
            .setViewPointId(id.getViewPoint())
            .setSpanTypeDesc(id.getSpanTypeDesc())
            .setCallType(id.getCallType())
            .setProcessNo(BuriedPointMachineUtil.getProcessNo())
            .setAddress(BuriedPointMachineUtil.getHostDesc())
            .build();

    RequestSpanDisruptor.INSTANCE.ready2Send(requestSpan);
  }
예제 #7
0
  protected void sendAckSpan(Span span) {
    AckSpan ackSpan = span.buildAckSpan(AckSpan.newBuilder()).build();

    AckSpanDisruptor.INSTANCE.ready2Send(ackSpan);
  }