Search in sources :

Example 1 with ThriftClientCallContext

use of com.navercorp.pinpoint.plugin.thrift.ThriftClientCallContext in project pinpoint by naver.

the class ProcessFunctionProcessInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    // process(int seqid, TProtocol iprot, TProtocol oprot, I iface)
    if (args.length != 4) {
        return;
    }
    String methodName = ThriftConstants.UNKNOWN_METHOD_NAME;
    if (target instanceof ProcessFunction) {
        ProcessFunction<?, ?> processFunction = (ProcessFunction<?, ?>) target;
        methodName = processFunction.getMethodName();
    }
    ThriftClientCallContext clientCallContext = new ThriftClientCallContext(methodName);
    InterceptorScopeInvocation currentTransaction = this.scope.getCurrentInvocation();
    currentTransaction.setAttachment(clientCallContext);
    // Set server marker - server handlers may create a client to call another Thrift server.
    // When this happens, TProtocol interceptors for clients are triggered since technically they're still within THRIFT_SERVER_SCOPE.
    // We set the marker inside server's input protocol to safeguard against such cases.
    Object iprot = args[1];
    // With the addition of TProtocolDecorator, iprot may actually be a wrapper around the actual input protocol
    Object rootInputProtocol = getRootInputProtocol(iprot);
    if (validateInputProtocol(rootInputProtocol)) {
        ((ServerMarkerFlagFieldAccessor) rootInputProtocol)._$PINPOINT$_setServerMarkerFlag(true);
    }
}
Also used : ProcessFunction(org.apache.thrift.ProcessFunction) InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) ThriftClientCallContext(com.navercorp.pinpoint.plugin.thrift.ThriftClientCallContext) ServerMarkerFlagFieldAccessor(com.navercorp.pinpoint.plugin.thrift.field.accessor.ServerMarkerFlagFieldAccessor)

Example 2 with ThriftClientCallContext

use of com.navercorp.pinpoint.plugin.thrift.ThriftClientCallContext in project pinpoint by naver.

the class TProtocolReadMessageEndInterceptor method after.

@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 = ((ServerMarkerFlagFieldAccessor) target)._$PINPOINT$_getServerMarkerFlag();
    if (shouldTrace) {
        InterceptorScopeInvocation currentTransaction = this.scope.getCurrentInvocation();
        Object attachment = currentTransaction.getAttachment();
        if (attachment instanceof ThriftClientCallContext) {
            ThriftClientCallContext clientCallContext = (ThriftClientCallContext) attachment;
            String methodName = clientCallContext.getMethodName();
            ThriftRequestProperty parentTraceInfo = clientCallContext.getTraceHeader();
            try {
                this.logger.debug("parentTraceInfo : {}", parentTraceInfo);
                recordTrace(target, parentTraceInfo, methodName);
            } catch (Throwable t) {
                logger.warn("Error creating trace object. Cause:{}", t.getMessage(), t);
            }
        }
    }
}
Also used : InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) ThriftClientCallContext(com.navercorp.pinpoint.plugin.thrift.ThriftClientCallContext) ThriftRequestProperty(com.navercorp.pinpoint.plugin.thrift.ThriftRequestProperty) ServerMarkerFlagFieldAccessor(com.navercorp.pinpoint.plugin.thrift.field.accessor.ServerMarkerFlagFieldAccessor)

Example 3 with ThriftClientCallContext

use of com.navercorp.pinpoint.plugin.thrift.ThriftClientCallContext in project pinpoint by naver.

the class TBaseAsyncProcessorProcessInterceptor method getMethodUri.

private String getMethodUri(Object target) {
    String methodUri = ThriftConstants.UNKNOWN_METHOD_URI;
    InterceptorScopeInvocation currentTransaction = this.scope.getCurrentInvocation();
    Object attachment = currentTransaction.getAttachment();
    if (attachment instanceof ThriftClientCallContext && target instanceof TBaseAsyncProcessor) {
        ThriftClientCallContext clientCallContext = (ThriftClientCallContext) attachment;
        String methodName = clientCallContext.getMethodName();
        methodUri = ThriftUtils.getAsyncProcessorNameAsUri((TBaseAsyncProcessor<?>) target);
        StringBuilder sb = new StringBuilder(methodUri);
        if (!methodUri.endsWith("/")) {
            sb.append("/");
        }
        sb.append(methodName);
        methodUri = sb.toString();
    }
    return methodUri;
}
Also used : InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) TBaseAsyncProcessor(org.apache.thrift.TBaseAsyncProcessor) ThriftClientCallContext(com.navercorp.pinpoint.plugin.thrift.ThriftClientCallContext)

Example 4 with ThriftClientCallContext

use of com.navercorp.pinpoint.plugin.thrift.ThriftClientCallContext in project pinpoint by naver.

the class TBaseProcessorProcessInterceptor method getMethodUri.

private String getMethodUri(Object target) {
    String methodUri = ThriftConstants.UNKNOWN_METHOD_URI;
    InterceptorScopeInvocation currentTransaction = this.scope.getCurrentInvocation();
    Object attachment = currentTransaction.getAttachment();
    if (attachment instanceof ThriftClientCallContext && target instanceof TBaseProcessor) {
        ThriftClientCallContext clientCallContext = (ThriftClientCallContext) attachment;
        String methodName = clientCallContext.getMethodName();
        methodUri = ThriftUtils.getProcessorNameAsUri((TBaseProcessor<?>) target);
        StringBuilder sb = new StringBuilder(methodUri);
        if (!methodUri.endsWith("/")) {
            sb.append("/");
        }
        sb.append(methodName);
        methodUri = sb.toString();
    }
    return methodUri;
}
Also used : InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) ThriftClientCallContext(com.navercorp.pinpoint.plugin.thrift.ThriftClientCallContext) TBaseProcessor(org.apache.thrift.TBaseProcessor)

Example 5 with ThriftClientCallContext

use of com.navercorp.pinpoint.plugin.thrift.ThriftClientCallContext in project pinpoint by naver.

the class TProtocolReadFieldBeginInterceptor method after.

@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 = ((ServerMarkerFlagFieldAccessor) target)._$PINPOINT$_getServerMarkerFlag();
    if (shouldTrace) {
        InterceptorScopeInvocation currentTransaction = this.scope.getCurrentInvocation();
        Object attachment = currentTransaction.getAttachment();
        if (attachment instanceof ThriftClientCallContext) {
            ThriftClientCallContext clientCallContext = (ThriftClientCallContext) attachment;
            if (result instanceof TField) {
                handleClientRequest((TField) result, clientCallContext);
            }
        }
    }
}
Also used : InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) TField(org.apache.thrift.protocol.TField) ThriftClientCallContext(com.navercorp.pinpoint.plugin.thrift.ThriftClientCallContext) ServerMarkerFlagFieldAccessor(com.navercorp.pinpoint.plugin.thrift.field.accessor.ServerMarkerFlagFieldAccessor)

Aggregations

InterceptorScopeInvocation (com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation)7 ThriftClientCallContext (com.navercorp.pinpoint.plugin.thrift.ThriftClientCallContext)7 ServerMarkerFlagFieldAccessor (com.navercorp.pinpoint.plugin.thrift.field.accessor.ServerMarkerFlagFieldAccessor)4 ThriftRequestProperty (com.navercorp.pinpoint.plugin.thrift.ThriftRequestProperty)2 ThriftHeader (com.navercorp.pinpoint.plugin.thrift.ThriftHeader)1 AsyncMarkerFlagFieldAccessor (com.navercorp.pinpoint.plugin.thrift.field.accessor.AsyncMarkerFlagFieldAccessor)1 ProcessFunction (org.apache.thrift.ProcessFunction)1 TBaseAsyncProcessor (org.apache.thrift.TBaseAsyncProcessor)1 TBaseProcessor (org.apache.thrift.TBaseProcessor)1 TField (org.apache.thrift.protocol.TField)1 TMessage (org.apache.thrift.protocol.TMessage)1