Search in sources :

Example 1 with ServerMarkerFlagFieldAccessor

use of com.navercorp.pinpoint.plugin.thrift.field.accessor.ServerMarkerFlagFieldAccessor 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;
            try {
                recordTrace(target, clientCallContext);
            } 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) ServerMarkerFlagFieldAccessor(com.navercorp.pinpoint.plugin.thrift.field.accessor.ServerMarkerFlagFieldAccessor)

Example 2 with ServerMarkerFlagFieldAccessor

use of com.navercorp.pinpoint.plugin.thrift.field.accessor.ServerMarkerFlagFieldAccessor 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)

Example 3 with ServerMarkerFlagFieldAccessor

use of com.navercorp.pinpoint.plugin.thrift.field.accessor.ServerMarkerFlagFieldAccessor 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)

Example 4 with ServerMarkerFlagFieldAccessor

use of com.navercorp.pinpoint.plugin.thrift.field.accessor.ServerMarkerFlagFieldAccessor in project pinpoint by naver.

the class TProtocolReadTTypeInterceptor 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;
            ThriftHeader headerKeyToBeRead = clientCallContext.getTraceHeaderToBeRead();
            if (headerKeyToBeRead == NONE) {
                return;
            }
            ThriftRequestProperty parentTraceInfo = clientCallContext.getTraceHeader();
            if (parentTraceInfo == null) {
                parentTraceInfo = new ThriftRequestProperty();
                clientCallContext.setTraceHeader(parentTraceInfo);
            }
            try {
                parentTraceInfo.setTraceHeader(headerKeyToBeRead, result);
            } catch (Throwable t) {
                logger.warn("Error reading trace header.", t);
            } finally {
                clientCallContext.setTraceHeaderToBeRead(NONE);
            }
        }
    }
}
Also used : InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) ThriftClientCallContext(com.navercorp.pinpoint.plugin.thrift.ThriftClientCallContext) ThriftRequestProperty(com.navercorp.pinpoint.plugin.thrift.ThriftRequestProperty) ThriftHeader(com.navercorp.pinpoint.plugin.thrift.ThriftHeader) ServerMarkerFlagFieldAccessor(com.navercorp.pinpoint.plugin.thrift.field.accessor.ServerMarkerFlagFieldAccessor)

Aggregations

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