@Override
  public void after(Object target, Object result, Throwable throwable, Object[] args) {
    if (isDebug) {
      logger.afterInterceptor(target, args);
    }

    final Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
      return;
    }

    try {
      SpanEventRecorder recorder = trace.currentSpanEventRecorder();
      recorder.recordApi(methodDescriptor);
      recorder.recordServiceType(HttpClientConstants.HTTP_CLIENT_INTERNAL);
      recorder.recordException(throwable);

      // remove async id.
      InterceptorGroupInvocation transaction = interceptorGroup.getCurrentInvocation();
      if (transaction != null) {
        // clear
        transaction.removeAttachment();
      }
    } finally {
      trace.traceBlockEnd();
    }
  }
  @Override
  public void after(Object target, Object result, Throwable throwable, Object[] args) {
    if (isDebug) {
      logger.afterInterceptor(
          target,
          methodDescriptor.getClassName(),
          methodDescriptor.getMethodName(),
          "",
          args,
          result,
          throwable);
    }

    final Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
      return;
    }

    InterceptorGroupInvocation invocation = interceptorGroup.getCurrentInvocation();
    if (invocation != null && invocation.getAttachment() != null) {
      HttpCallContext callContext = (HttpCallContext) invocation.getAttachment();
      if (methodDescriptor.getMethodName().equals("doSendRequest")) {
        callContext.setWriteEndTime(System.currentTimeMillis());
        callContext.setWriteFail(throwable != null);
      } else {
        callContext.setReadEndTime(System.currentTimeMillis());
        callContext.setReadFail(throwable != null);
      }
      logger.debug("Set call context {}", callContext);
    }
  }
 @Override
 public void after(Object target, Object[] args, Object result, Throwable throwable) {
   if (isDebug) {
     logger.afterInterceptor(target, args, result, throwable);
   }
   // Unset server markers
   if (args[0] instanceof AsyncFrameBuffer) {
     AsyncFrameBuffer frameBuffer = (AsyncFrameBuffer) args[0];
     attachMarkersToInputProtocol(frameBuffer.getInputProtocol(), false);
   }
   final Trace trace = this.traceContext.currentRawTraceObject();
   if (trace == null) {
     return;
   }
   this.traceContext.removeTraceObject();
   if (trace.canSampled()) {
     try {
       processTraceObject(trace, target, args, throwable);
     } catch (Throwable t) {
       logger.warn("Error processing trace object. Cause:{}", t.getMessage(), t);
     } finally {
       trace.close();
     }
   }
 }
  @Override
  public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
      logger.afterInterceptor(target, args);
    }

    final Trace trace = traceContext.currentRawTraceObject();
    if (trace == null) {
      return;
    }

    // check user include trace.
    if (!isUserIncludeTrace(trace)) {
      return;
    }

    // leave scope(default & disable trace).
    if (!leaveUserIncludeTraceScope(trace)) {
      logger.warn(
          "Failed to leave scope of user include trace. trace={}, sampled={}",
          trace,
          trace.canSampled());
      // delete unstable trace.
      deleteUserIncludeTrace(trace);
      return;
    }

    // check sampled.
    if (!trace.canSampled()) {
      if (isUserIncludeTraceDestination(trace)) {
        deleteUserIncludeTrace(trace);
      }
      return;
    }

    try {
      final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
      recorder.recordApi(descriptor);
      recorder.recordServiceType(ServiceType.INTERNAL_METHOD);
      recorder.recordException(throwable);
    } finally {
      trace.traceBlockEnd();
      if (isUserIncludeTraceDestination(trace)) {
        deleteUserIncludeTrace(trace);
      }
    }
  }
  @Override
  public void after(Object target, Object result, Throwable throwable, Object[] args) {
    if (isDebug) {
      logger.afterInterceptor(target, args, result, throwable);
    }

    try {
      ((CacheNameAccessor) target)._$PINPOINT$_setCacheName(DEFAULT_FRONTCACHE_NAME);

      if (args[0] instanceof Element) {
        Element element = (Element) args[0];
        ((CacheKeyAccessor) target)._$PINPOINT$_setCacheKey(element.getObjectKey());
      }
    } catch (Exception e) {
      logger.error("failed to add metadata: {}", e);
    }
  }
 @Override
 public void after(Object target, Object[] args, Object result, Throwable throwable) {
   if (isDebug) {
     logger.afterInterceptor(target, args, result, throwable);
   }
   if (!validate(target)) {
     return;
   }
   final boolean shouldTrace =
       ((AsyncMarkerFlagFieldAccessor) target)._$PINPOINT$_getAsyncMarkerFlag();
   if (shouldTrace) {
     String methodName = ThriftConstants.UNKNOWN_METHOD_NAME;
     if (result instanceof TMessage) {
       TMessage message = (TMessage) result;
       methodName = message.name;
     }
     ThriftClientCallContext clientCallContext = new ThriftClientCallContext(methodName);
     InterceptorScopeInvocation currentTransaction = this.scope.getCurrentInvocation();
     currentTransaction.setAttachment(clientCallContext);
   }
 }
  @Override
  public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
      logger.afterInterceptor(target, args, result, throwable);
    }

    final Trace trace = this.traceContext.currentTraceObject();
    if (trace == null) {
      return;
    }

    try {
      SpanEventRecorder recorder = trace.currentSpanEventRecorder();
      recorder.recordApi(this.descriptor);
      recorder.recordException(throwable);
    } catch (Throwable t) {
      logger.warn("after error. Caused:{}", t.getMessage(), t);
    } finally {
      trace.traceBlockEnd();
    }
  }
 @Override
 public void after(Object target, Object[] args, Object result, Throwable throwable) {
   final Trace trace = this.traceContext.currentRawTraceObject();
   if (trace == null) {
     return;
   }
   // logging here as some Thrift servers depend on TTransportException being thrown for normal
   // operations.
   // log only when current transaction is being traced.
   if (isDebug) {
     logger.afterInterceptor(target, args, result, throwable);
   }
   this.traceContext.removeTraceObject();
   if (trace.canSampled()) {
     try {
       processTraceObject(trace, target, args, throwable);
     } catch (Throwable t) {
       logger.warn("Error processing trace object. Cause:{}", t.getMessage(), t);
     } finally {
       trace.close();
     }
   }
 }
  @Override
  public void after(Object target, Object result, Throwable throwable, Object[] args) {
    if (isDebug) {
      logger.afterInterceptor(target, args);
    }
    Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
      return;
    }

    try {
      SpanEventRecorder recorder = trace.currentSpanEventRecorder();
      recorder.recordApi(descriptor);
      recorder.recordException(throwable);

      if (result != null) {
        recorder.recordAttribute(
            JacksonConstants.ANNOTATION_KEY_LENGTH_VALUE, ((String) result).length());
      }
    } finally {
      trace.traceBlockEnd();
    }
  }
  @Override
  public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
      logger.afterInterceptor(target, args);
    }

    final Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
      return;
    }

    if (!validate(target)) {
      return;
    }

    try {
      SpanEventRecorder recorder = trace.currentSpanEventRecorder();
      recorder.recordApi(methodDescriptor);
      recorder.recordException(throwable);

      Request request = ((UserRequestGetter) target)._$PINPOINT$_getUserRequest();
      if (request != null) {
        recorder.recordAttribute(AnnotationKey.HTTP_URL, request.httpUrl().toString());
        recorder.recordDestinationId(request.httpUrl().host() + ":" + request.httpUrl().port());
        recordRequest(trace, request, throwable);
      }

      // clear attachment.
      InterceptorGroupInvocation invocation = interceptorGroup.getCurrentInvocation();
      if (invocation != null && invocation.getAttachment() != null) {
        invocation.removeAttachment();
      }
    } finally {
      trace.traceBlockEnd();
    }
  }
예제 #11
0
 @Override
 public void after(Object target, Object[] args, Object result, Throwable throwable) {
   if (isDebug) {
     logger.afterInterceptor(target, args, result, throwable);
   }
 }