Search in sources :

Example 1 with ProcessFunction

use of org.apache.thrift.ProcessFunction 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 (ArrayUtils.getLength(args) != 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)

Aggregations

InterceptorScopeInvocation (com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation)1 ThriftClientCallContext (com.navercorp.pinpoint.plugin.thrift.ThriftClientCallContext)1 ServerMarkerFlagFieldAccessor (com.navercorp.pinpoint.plugin.thrift.field.accessor.ServerMarkerFlagFieldAccessor)1 ProcessFunction (org.apache.thrift.ProcessFunction)1