@Override public void before(Object target, Object[] args) { if (isDebug) { logger.beforeInterceptor(target, args); } final Trace trace = traceContext.currentRawTraceObject(); if (trace == null) { return; } if (!validate(target)) { return; } if (!trace.canSampled()) { return; } SpanEventRecorder recorder = trace.traceBlockBegin(); try { final TraceId nextId = trace.getTraceId().getNextTraceId(); recorder.recordNextSpanId(nextId.getSpanId()); recorder.recordServiceType(OK_HTTP_CLIENT); InterceptorGroupInvocation invocation = interceptorGroup.getCurrentInvocation(); if (invocation != null) { invocation.getOrCreateAttachment( new AttachmentFactory() { @Override public Object createAttachment() { return nextId; } }); } } catch (Throwable t) { logger.warn("Failed to BEFORE process. {}", t.getMessage(), t); } }
@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(); } }