Search in sources :

Example 26 with InterceptorScopeInvocation

use of com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation in project pinpoint by naver.

the class HttpRequestExecuteAsyncMethodInnerClassConstructorInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    try {
        if (!validate(target, args)) {
            return;
        }
        final InterceptorScopeInvocation transaction = interceptorScope.getCurrentInvocation();
        if (transaction != null && transaction.getAttachment() != null) {
            final AsyncTraceId asyncTraceId = (AsyncTraceId) transaction.getAttachment();
            // type check validate();
            ((AsyncTraceIdAccessor) target)._$PINPOINT$_setAsyncTraceId(asyncTraceId);
            // clear.
            transaction.removeAttachment();
        }
    } catch (Throwable t) {
        logger.warn("Failed to BEFORE process. {}", t.getMessage(), t);
    }
}
Also used : InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) AsyncTraceId(com.navercorp.pinpoint.bootstrap.context.AsyncTraceId) AsyncTraceIdAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncTraceIdAccessor)

Example 27 with InterceptorScopeInvocation

use of com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation in project pinpoint by naver.

the class HttpRequestExecuteAsyncMethodInterceptor method after.

@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;
    }
    try {
        SpanEventRecorder recorder = trace.currentSpanEventRecorder();
        recorder.recordApi(methodDescriptor);
        recorder.recordServiceType(HttpClientConstants.HTTP_CLIENT_INTERNAL);
        recorder.recordException(throwable);
        // remove async id.
        InterceptorScopeInvocation transaction = interceptorScope.getCurrentInvocation();
        if (transaction != null) {
            // clear
            transaction.removeAttachment();
        }
    } finally {
        trace.traceBlockEnd();
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)

Example 28 with InterceptorScopeInvocation

use of com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation in project pinpoint by naver.

the class HttpMethodBaseRequestAndResponseMethodInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, methodDescriptor.getClassName(), methodDescriptor.getMethodName(), "", args, result, throwable);
    }
    final Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    InterceptorScopeInvocation invocation = interceptorScope.getCurrentInvocation();
    if (invocation != null && invocation.getAttachment() != null && invocation.getAttachment() instanceof HttpClient3CallContext) {
        HttpClient3CallContext callContext = (HttpClient3CallContext) invocation.getAttachment();
        if (methodDescriptor.getMethodName().equals("writeRequest")) {
            callContext.setWriteEndTime(System.currentTimeMillis());
            callContext.setWriteFail(throwable != null);
        } else {
            callContext.setReadEndTime(System.currentTimeMillis());
            callContext.setReadFail(throwable != null);
        }
        logger.debug("Set call context {}", callContext);
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) HttpClient3CallContext(com.navercorp.pinpoint.plugin.httpclient3.HttpClient3CallContext)

Example 29 with InterceptorScopeInvocation

use of com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation in project pinpoint by naver.

the class TAsyncClientManagerCallInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    if (!validate(target, args)) {
        return;
    }
    final Trace trace = this.traceContext.currentRawTraceObject();
    if (trace == null) {
        return;
    }
    try {
        ThriftRequestProperty parentTraceInfo = new ThriftRequestProperty();
        final boolean shouldSample = trace.canSampled();
        if (!shouldSample) {
            if (isDebug) {
                logger.debug("set Sampling flag=false");
            }
            parentTraceInfo.setShouldSample(shouldSample);
        } else {
            SpanEventRecorder recorder = trace.traceBlockBegin();
            Object asyncMethodCallObj = args[0];
            // inject async trace info to AsyncMethodCall object
            final AsyncTraceId asyncTraceId = injectAsyncTraceId(asyncMethodCallObj, trace);
            // retrieve connection information
            String remoteAddress = getRemoteAddress(asyncMethodCallObj);
            final TraceId nextId = asyncTraceId.getNextTraceId();
            // Inject nextSpanId as the actual sending of data will be handled asynchronously.
            final long nextSpanId = nextId.getSpanId();
            parentTraceInfo.setSpanId(nextSpanId);
            parentTraceInfo.setTraceId(nextId.getTransactionId());
            parentTraceInfo.setParentSpanId(nextId.getParentSpanId());
            parentTraceInfo.setFlags(nextId.getFlags());
            parentTraceInfo.setParentApplicationName(this.traceContext.getApplicationName());
            parentTraceInfo.setParentApplicationType(this.traceContext.getServerTypeCode());
            parentTraceInfo.setAcceptorHost(remoteAddress);
            recorder.recordServiceType(ThriftConstants.THRIFT_CLIENT);
            recorder.recordNextSpanId(nextSpanId);
            recorder.recordDestinationId(remoteAddress);
            String methodUri = ThriftUtils.getAsyncMethodCallName((TAsyncMethodCall<?>) asyncMethodCallObj);
            String thriftUrl = remoteAddress + "/" + methodUri;
            recorder.recordAttribute(ThriftConstants.THRIFT_URL, thriftUrl);
        }
        InterceptorScopeInvocation currentTransaction = this.scope.getCurrentInvocation();
        currentTransaction.setAttachment(parentTraceInfo);
    } catch (Throwable t) {
        logger.warn("BEFORE error. Caused:{}", t.getMessage(), t);
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) ThriftRequestProperty(com.navercorp.pinpoint.plugin.thrift.ThriftRequestProperty) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) AsyncTraceId(com.navercorp.pinpoint.bootstrap.context.AsyncTraceId) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId) AsyncTraceId(com.navercorp.pinpoint.bootstrap.context.AsyncTraceId)

Example 30 with InterceptorScopeInvocation

use of com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation in project pinpoint by naver.

the class HttpEngineSendRequestMethodInterceptor method before.

@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(OkHttpConstants.OK_HTTP_CLIENT);
        InterceptorScopeInvocation invocation = interceptorScope.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);
    }
}
Also used : InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) AttachmentFactory(com.navercorp.pinpoint.bootstrap.interceptor.scope.AttachmentFactory)

Aggregations

InterceptorScopeInvocation (com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation)53 Test (org.junit.Test)20 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)15 DefaultInterceptorScopeInvocation (com.navercorp.pinpoint.profiler.interceptor.scope.DefaultInterceptorScopeInvocation)15 SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)8 ThriftClientCallContext (com.navercorp.pinpoint.plugin.thrift.ThriftClientCallContext)7 DefaultInterceptorScopeDefinition (com.navercorp.pinpoint.bootstrap.instrument.DefaultInterceptorScopeDefinition)6 HttpCallContext (com.navercorp.pinpoint.plugin.httpclient4.HttpCallContext)6 ThriftRequestProperty (com.navercorp.pinpoint.plugin.thrift.ThriftRequestProperty)5 CommandContext (com.navercorp.pinpoint.plugin.redis.CommandContext)4 ServerMarkerFlagFieldAccessor (com.navercorp.pinpoint.plugin.thrift.field.accessor.ServerMarkerFlagFieldAccessor)4 AsyncTraceId (com.navercorp.pinpoint.bootstrap.context.AsyncTraceId)3 TraceId (com.navercorp.pinpoint.bootstrap.context.TraceId)3 Request (com.squareup.okhttp.Request)3 AttachmentFactory (com.navercorp.pinpoint.bootstrap.interceptor.scope.AttachmentFactory)2 HttpClient3CallContext (com.navercorp.pinpoint.plugin.httpclient3.HttpClient3CallContext)2 EndPointAccessor (com.navercorp.pinpoint.plugin.redis.EndPointAccessor)2 HttpRequest (org.apache.http.HttpRequest)2 AsyncTraceIdAccessor (com.navercorp.pinpoint.bootstrap.async.AsyncTraceIdAccessor)1 UrlGetter (com.navercorp.pinpoint.plugin.okhttp.UrlGetter)1