Search in sources :

Example 1 with ThriftRequestProperty

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

the class TServiceClientSendBaseInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    if (target instanceof TServiceClient) {
        TServiceClient client = (TServiceClient) target;
        TProtocol oprot = client.getOutputProtocol();
        TTransport transport = oprot.getTransport();
        final Trace trace = traceContext.currentRawTraceObject();
        if (trace == null) {
            return;
        }
        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();
            recorder.recordServiceType(ThriftConstants.THRIFT_CLIENT);
            // retrieve connection information
            String remoteAddress = ThriftConstants.UNKNOWN_ADDRESS;
            if (transport instanceof SocketFieldAccessor) {
                Socket socket = ((SocketFieldAccessor) transport)._$PINPOINT$_getSocket();
                if (socket != null) {
                    remoteAddress = ThriftUtils.getHostPort(socket.getRemoteSocketAddress());
                }
            } else {
                if (isDebug) {
                    logger.debug("Invalid target object. Need field accessor({}).", SocketFieldAccessor.class.getName());
                }
            }
            recorder.recordDestinationId(remoteAddress);
            String methodName = ThriftConstants.UNKNOWN_METHOD_NAME;
            if (args[0] instanceof String) {
                methodName = (String) args[0];
            }
            String serviceName = ThriftUtils.getClientServiceName(client);
            String thriftUrl = getServiceUrl(remoteAddress, serviceName, methodName);
            recorder.recordAttribute(ThriftConstants.THRIFT_URL, thriftUrl);
            TraceId nextId = trace.getTraceId().getNextTraceId();
            recorder.recordNextSpanId(nextId.getSpanId());
            parentTraceInfo.setTraceId(nextId.getTransactionId());
            parentTraceInfo.setSpanId(nextId.getSpanId());
            parentTraceInfo.setParentSpanId(nextId.getParentSpanId());
            parentTraceInfo.setFlags(nextId.getFlags());
            parentTraceInfo.setParentApplicationName(traceContext.getApplicationName());
            parentTraceInfo.setParentApplicationType(traceContext.getServerTypeCode());
            parentTraceInfo.setAcceptorHost(remoteAddress);
        }
        InterceptorScopeInvocation currentTransaction = this.scope.getCurrentInvocation();
        currentTransaction.setAttachment(parentTraceInfo);
    }
}
Also used : TServiceClient(org.apache.thrift.TServiceClient) Trace(com.navercorp.pinpoint.bootstrap.context.Trace) InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) TProtocol(org.apache.thrift.protocol.TProtocol) ThriftRequestProperty(com.navercorp.pinpoint.plugin.thrift.ThriftRequestProperty) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId) SocketFieldAccessor(com.navercorp.pinpoint.plugin.thrift.field.accessor.SocketFieldAccessor) TTransport(org.apache.thrift.transport.TTransport) Socket(java.net.Socket)

Example 2 with ThriftRequestProperty

use of com.navercorp.pinpoint.plugin.thrift.ThriftRequestProperty 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 ThriftRequestProperty

use of com.navercorp.pinpoint.plugin.thrift.ThriftRequestProperty 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 4 with ThriftRequestProperty

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

the class TProtocolWriteFieldStopInterceptor method appendParentTraceInfo.

private void appendParentTraceInfo(TProtocol oprot) throws TException {
    InterceptorScopeInvocation currentTransaction = this.scope.getCurrentInvocation();
    ThriftRequestProperty parentTraceInfo = (ThriftRequestProperty) currentTransaction.getAttachment();
    if (parentTraceInfo == null) {
        return;
    }
    boolean shouldSample = parentTraceInfo.shouldSample(true);
    if (!shouldSample) {
        parentTraceInfo.writeTraceHeader(ThriftHeader.THRFIT_SAMPLED, oprot);
        return;
    }
    parentTraceInfo.writeTraceHeader(ThriftHeader.THRIFT_TRACE_ID, oprot);
    parentTraceInfo.writeTraceHeader(ThriftHeader.THRIFT_SPAN_ID, oprot);
    parentTraceInfo.writeTraceHeader(ThriftHeader.THRIFT_PARENT_SPAN_ID, oprot);
    parentTraceInfo.writeTraceHeader(ThriftHeader.THRIFT_FLAGS, oprot);
    parentTraceInfo.writeTraceHeader(ThriftHeader.THRIFT_PARENT_APPLICATION_NAME, oprot);
    parentTraceInfo.writeTraceHeader(ThriftHeader.THRIFT_PARENT_APPLICATION_TYPE, oprot);
    parentTraceInfo.writeTraceHeader(ThriftHeader.THRIFT_HOST, oprot);
}
Also used : InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) ThriftRequestProperty(com.navercorp.pinpoint.plugin.thrift.ThriftRequestProperty)

Example 5 with ThriftRequestProperty

use of com.navercorp.pinpoint.plugin.thrift.ThriftRequestProperty 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)5 ThriftRequestProperty (com.navercorp.pinpoint.plugin.thrift.ThriftRequestProperty)5 SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)2 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)2 TraceId (com.navercorp.pinpoint.bootstrap.context.TraceId)2 ThriftClientCallContext (com.navercorp.pinpoint.plugin.thrift.ThriftClientCallContext)2 ServerMarkerFlagFieldAccessor (com.navercorp.pinpoint.plugin.thrift.field.accessor.ServerMarkerFlagFieldAccessor)2 AsyncTraceId (com.navercorp.pinpoint.bootstrap.context.AsyncTraceId)1 ThriftHeader (com.navercorp.pinpoint.plugin.thrift.ThriftHeader)1 SocketFieldAccessor (com.navercorp.pinpoint.plugin.thrift.field.accessor.SocketFieldAccessor)1 Socket (java.net.Socket)1 TServiceClient (org.apache.thrift.TServiceClient)1 TProtocol (org.apache.thrift.protocol.TProtocol)1 TTransport (org.apache.thrift.transport.TTransport)1