Search in sources :

Example 41 with AnnotationBo

use of com.navercorp.pinpoint.common.server.bo.AnnotationBo in project pinpoint by naver.

the class GrpcSpanBinder method newSpanBo.

// for test
SpanBo newSpanBo(PSpan pSpan, Header header) {
    final SpanBo spanBo = new SpanBo();
    spanBo.setVersion(pSpan.getVersion());
    spanBo.setAgentId(header.getAgentId());
    spanBo.setApplicationId(header.getApplicationName());
    spanBo.setAgentStartTime(header.getAgentStartTime());
    if (!pSpan.hasTransactionId()) {
        throw new IllegalStateException("hasTransactionId() is false " + MessageFormatUtils.debugLog(pSpan));
    }
    final TransactionId transactionId = newTransactionId(pSpan.getTransactionId(), spanBo.getAgentId());
    spanBo.setTransactionId(transactionId);
    spanBo.setSpanId(pSpan.getSpanId());
    spanBo.setParentSpanId(pSpan.getParentSpanId());
    spanBo.setStartTime(pSpan.getStartTime());
    spanBo.setElapsed(pSpan.getElapsed());
    spanBo.setServiceType((short) pSpan.getServiceType());
    spanBo.setFlag((short) pSpan.getFlag());
    spanBo.setApiId(pSpan.getApiId());
    spanBo.setErrCode(pSpan.getErr());
    spanBo.setLoggingTransactionInfo((byte) pSpan.getLoggingTransactionInfo());
    spanBo.setApplicationServiceType((short) pSpan.getApplicationServiceType());
    if (pSpan.hasAcceptEvent()) {
        final PAcceptEvent acceptEvent = pSpan.getAcceptEvent();
        final String rpc = acceptEvent.getRpc();
        if (StringUtils.hasLength(rpc)) {
            spanBo.setRpc(rpc);
        }
        final String remoteAddr = acceptEvent.getRemoteAddr();
        if (StringUtils.hasLength(remoteAddr)) {
            spanBo.setRemoteAddr(remoteAddr);
        }
        final String endPoint = acceptEvent.getEndPoint();
        if (StringUtils.hasLength(endPoint)) {
            spanBo.setEndPoint(endPoint);
        }
        if (acceptEvent.hasParentInfo()) {
            final PParentInfo parentInfo = acceptEvent.getParentInfo();
            final String acceptorHost = parentInfo.getAcceptorHost();
            if (StringUtils.hasLength(acceptorHost)) {
                spanBo.setAcceptorHost(acceptorHost);
            }
            final String parentApplicationName = parentInfo.getParentApplicationName();
            if (StringUtils.hasLength(parentApplicationName)) {
                spanBo.setParentApplicationId(parentApplicationName);
            }
            spanBo.setParentApplicationServiceType((short) parentInfo.getParentApplicationType());
        }
    }
    // because exceptionInfo is the error information of span itself, exceptionInfo can be null even if errCode is not 0
    if (pSpan.hasExceptionInfo()) {
        final PIntStringValue exceptionInfo = pSpan.getExceptionInfo();
        spanBo.setExceptionInfo(exceptionInfo.getIntValue(), getExceptionMessage(exceptionInfo));
    }
    List<AnnotationBo> annotationBoList = buildAnnotationList(pSpan.getAnnotationList());
    spanBo.setAnnotationBoList(annotationBoList);
    return spanBo;
}
Also used : AnnotationBo(com.navercorp.pinpoint.common.server.bo.AnnotationBo) PIntStringValue(com.navercorp.pinpoint.grpc.trace.PIntStringValue) PParentInfo(com.navercorp.pinpoint.grpc.trace.PParentInfo) PAcceptEvent(com.navercorp.pinpoint.grpc.trace.PAcceptEvent) SpanBo(com.navercorp.pinpoint.common.server.bo.SpanBo) PTransactionId(com.navercorp.pinpoint.grpc.trace.PTransactionId) TransactionId(com.navercorp.pinpoint.common.profiler.util.TransactionId)

Example 42 with AnnotationBo

use of com.navercorp.pinpoint.common.server.bo.AnnotationBo in project pinpoint by naver.

the class GrpcSpanBinder method bind.

private void bind(SpanEventBo spanEvent, PSpanEvent pSpanEvent, SpanEventBo prevSpanEvent) {
    spanEvent.setSequence((short) pSpanEvent.getSequence());
    if (prevSpanEvent == null) {
        int startElapsed = pSpanEvent.getStartElapsed();
        spanEvent.setStartElapsed(startElapsed);
    } else {
        int startElapsed = pSpanEvent.getStartElapsed() + prevSpanEvent.getStartElapsed();
        spanEvent.setStartElapsed(startElapsed);
    }
    spanEvent.setEndElapsed(pSpanEvent.getEndElapsed());
    spanEvent.setServiceType((short) pSpanEvent.getServiceType());
    spanEvent.setApiId(pSpanEvent.getApiId());
    // v2 spec
    final int depth = pSpanEvent.getDepth();
    if (depth == 0) {
        // depth compact case
        if (prevSpanEvent == null) {
            // first spanEvent
            spanEvent.setDepth(0);
        } else {
            spanEvent.setDepth(prevSpanEvent.getDepth());
        }
    } else {
        spanEvent.setDepth(depth);
    }
    if (pSpanEvent.hasNextEvent()) {
        final PNextEvent nextEvent = pSpanEvent.getNextEvent();
        final PNextEvent.FieldCase fieldCase = nextEvent.getFieldCase();
        if (fieldCase == PNextEvent.FieldCase.MESSAGEEVENT) {
            final PMessageEvent messageEvent = nextEvent.getMessageEvent();
            spanEvent.setNextSpanId(messageEvent.getNextSpanId());
            final String destinationId = messageEvent.getDestinationId();
            if (StringUtils.hasLength(destinationId)) {
                spanEvent.setDestinationId(destinationId);
            }
            final String endPoint = messageEvent.getEndPoint();
            if (StringUtils.hasLength(endPoint)) {
                spanEvent.setEndPoint(endPoint);
            }
        } else {
            logger.info("unknown nextEvent:{}", nextEvent);
        }
    }
    final int asyncEvent = pSpanEvent.getAsyncEvent();
    spanEvent.setNextAsyncId(asyncEvent);
    List<AnnotationBo> annotationList = buildAnnotationList(pSpanEvent.getAnnotationList());
    spanEvent.setAnnotationBoList(annotationList);
    if (pSpanEvent.hasExceptionInfo()) {
        final PIntStringValue exceptionInfo = pSpanEvent.getExceptionInfo();
        spanEvent.setExceptionInfo(exceptionInfo.getIntValue(), getExceptionMessage(exceptionInfo));
    }
}
Also used : AnnotationBo(com.navercorp.pinpoint.common.server.bo.AnnotationBo) PNextEvent(com.navercorp.pinpoint.grpc.trace.PNextEvent) PMessageEvent(com.navercorp.pinpoint.grpc.trace.PMessageEvent) PIntStringValue(com.navercorp.pinpoint.grpc.trace.PIntStringValue)

Example 43 with AnnotationBo

use of com.navercorp.pinpoint.common.server.bo.AnnotationBo in project pinpoint by naver.

the class SpanEncoderV0 method writeFirstSpanEvent.

public void writeFirstSpanEvent(Buffer buffer, SpanEventBo spanEventBo, SpanEncodingContext<?> encodingContext) {
    final SpanEventBitField bitField = SpanEventBitField.buildFirst(spanEventBo);
    final byte firstSpanBitField1 = (byte) bitField.getBitField();
    buffer.putByte(firstSpanBitField1);
    buffer.putVInt(spanEventBo.getStartElapsed());
    buffer.putVInt(spanEventBo.getEndElapsed());
    buffer.putShort(spanEventBo.getSequence());
    buffer.putSVInt(spanEventBo.getDepth());
    buffer.putShort(spanEventBo.getServiceType());
    if (bitField.isSetRpc()) {
        buffer.putPrefixedString(spanEventBo.getRpc());
    }
    if (bitField.isSetEndPoint()) {
        buffer.putPrefixedString(spanEventBo.getEndPoint());
    }
    if (bitField.isSetDestinationId()) {
        buffer.putPrefixedString(spanEventBo.getDestinationId());
    }
    buffer.putSVInt(spanEventBo.getApiId());
    if (bitField.isSetNextSpanId()) {
        buffer.putLong(spanEventBo.getNextSpanId());
    }
    if (bitField.isSetHasException()) {
        buffer.putSVInt(spanEventBo.getExceptionId());
        buffer.putPrefixedString(spanEventBo.getExceptionMessage());
    }
    if (bitField.isSetAnnotation()) {
        final List<AnnotationBo> annotationBoList = spanEventBo.getAnnotationBoList();
        writeAnnotationList(buffer, annotationBoList, encodingContext);
    }
    if (bitField.isSetNextAsyncId()) {
        buffer.putSVInt(spanEventBo.getNextAsyncId());
    }
// if (bitField.isSetAsyncId()) {
// buffer.putInt(spanEventBo.getAsyncId());
// buffer.putVInt(spanEventBo.getAsyncSequence());
// }
}
Also used : SpanEventBitField(com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.bitfield.SpanEventBitField) AnnotationBo(com.navercorp.pinpoint.common.server.bo.AnnotationBo)

Example 44 with AnnotationBo

use of com.navercorp.pinpoint.common.server.bo.AnnotationBo in project pinpoint by naver.

the class SpanEncoderV0 method writeNextSpanEvent.

public void writeNextSpanEvent(Buffer buffer, SpanEventBo spanEventBo, SpanEventBo prevSpanEvent, SpanEncodingContext<?> encodingContext) {
    final SpanEventBitField bitField = SpanEventBitField.build(spanEventBo, prevSpanEvent);
    buffer.putShort(bitField.getBitField());
    switch(bitField.getStartElapsedEncodingStrategy()) {
        case PREV_DELTA:
            final int startTimeDelta = spanEventBo.getStartElapsed() - prevSpanEvent.getStartElapsed();
            buffer.putVInt(startTimeDelta);
            break;
        case PREV_EQUALS:
            // skip bitfield
            break;
        default:
            throw new IllegalStateException("unsupported StartElapsedEncodingStrategy");
    }
    buffer.putVInt(spanEventBo.getEndElapsed());
    switch(bitField.getSequenceEncodingStrategy()) {
        case PREV_DELTA:
            final int sequenceDelta = spanEventBo.getSequence() - prevSpanEvent.getSequence();
            buffer.putVInt(sequenceDelta);
            break;
        case PREV_ADD1:
            // skip bitfield
            break;
        default:
            throw new IllegalStateException("unsupported SequenceEncodingStrategy");
    }
    switch(bitField.getDepthEncodingStrategy()) {
        case RAW:
            buffer.putSVInt(spanEventBo.getDepth());
            break;
        case PREV_EQUALS:
            // skip bitfield
            break;
        default:
            throw new IllegalStateException("unsupported DepthEncodingStrategy");
    }
    switch(bitField.getServiceTypeEncodingStrategy()) {
        case RAW:
            buffer.putShort(spanEventBo.getServiceType());
            break;
        case PREV_EQUALS:
            // skip bitfield
            break;
        default:
            throw new IllegalStateException("unsupported ServiceTypeEncodingStrategy");
    }
    buffer.putSVInt(spanEventBo.getApiId());
    if (bitField.isSetRpc()) {
        buffer.putPrefixedString(spanEventBo.getRpc());
    }
    if (bitField.isSetEndPoint()) {
        buffer.putPrefixedString(spanEventBo.getEndPoint());
    }
    if (bitField.isSetDestinationId()) {
        buffer.putPrefixedString(spanEventBo.getDestinationId());
    }
    if (bitField.isSetNextSpanId()) {
        buffer.putLong(spanEventBo.getNextSpanId());
    }
    if (bitField.isSetHasException()) {
        buffer.putSVInt(spanEventBo.getExceptionId());
        buffer.putPrefixedString(spanEventBo.getExceptionMessage());
    }
    if (bitField.isSetAnnotation()) {
        List<AnnotationBo> annotationBoList = spanEventBo.getAnnotationBoList();
        writeAnnotationList(buffer, annotationBoList, encodingContext);
    }
    if (bitField.isSetNextAsyncId()) {
        buffer.putSVInt(spanEventBo.getNextAsyncId());
    }
    if (bitField.isSetAsyncId()) {
        buffer.putInt(spanEventBo.getAsyncId());
        buffer.putVInt(spanEventBo.getAsyncSequence());
    }
}
Also used : SpanEventBitField(com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.bitfield.SpanEventBitField) AnnotationBo(com.navercorp.pinpoint.common.server.bo.AnnotationBo)

Example 45 with AnnotationBo

use of com.navercorp.pinpoint.common.server.bo.AnnotationBo in project pinpoint by naver.

the class SpanEncoderV0 method encodeSpanColumnValue.

@Override
public ByteBuffer encodeSpanColumnValue(SpanEncodingContext<SpanBo> encodingContext) {
    final SpanBo span = encodingContext.getValue();
    final SpanBitFiled bitField = SpanBitFiled.build(span);
    final Buffer buffer = new AutomaticBuffer(256);
    final byte version = span.getRawVersion();
    buffer.putByte(version);
    // bit field
    buffer.putByte(bitField.getBitField());
    final short serviceType = span.getServiceType();
    buffer.putShort(serviceType);
    switch(bitField.getApplicationServiceTypeEncodingStrategy()) {
        case PREV_EQUALS:
            break;
        case RAW:
            buffer.putShort(span.getApplicationServiceType());
            break;
        default:
            throw new IllegalStateException("applicationServiceType");
    }
    // buffer.put(spanID);
    if (!bitField.isRoot()) {
        buffer.putLong(span.getParentSpanId());
    }
    // prevSpanEvent coding
    final long startTime = span.getStartTime();
    final long startTimeDelta = span.getCollectorAcceptTime() - startTime;
    buffer.putVLong(startTimeDelta);
    buffer.putVInt(span.getElapsed());
    buffer.putPrefixedString(span.getRpc());
    buffer.putPrefixedString(span.getEndPoint());
    buffer.putPrefixedString(span.getRemoteAddr());
    buffer.putSVInt(span.getApiId());
    // BIT flag
    if (bitField.isSetErrorCode()) {
        buffer.putInt(span.getErrCode());
    }
    if (bitField.isSetHasException()) {
        buffer.putSVInt(span.getExceptionId());
        buffer.putPrefixedString(span.getExceptionMessage());
    }
    if (bitField.isSetFlag()) {
        buffer.putShort(span.getFlag());
    }
    if (bitField.isSetLoggingTransactionInfo()) {
        buffer.putByte(span.getLoggingTransactionInfo());
    }
    buffer.putPrefixedString(span.getAcceptorHost());
    if (bitField.isSetAnnotation()) {
        List<AnnotationBo> annotationBoList = span.getAnnotationBoList();
        writeAnnotationList(buffer, annotationBoList, encodingContext);
    }
    final List<SpanEventBo> spanEventBoList = span.getSpanEventBoList();
    writeSpanEventList(buffer, spanEventBoList, encodingContext);
    return buffer.wrapByteBuffer();
}
Also used : Buffer(com.navercorp.pinpoint.common.buffer.Buffer) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer) ByteBuffer(java.nio.ByteBuffer) AnnotationBo(com.navercorp.pinpoint.common.server.bo.AnnotationBo) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer) SpanBitFiled(com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.bitfield.SpanBitFiled) SpanBo(com.navercorp.pinpoint.common.server.bo.SpanBo) SpanEventBo(com.navercorp.pinpoint.common.server.bo.SpanEventBo)

Aggregations

AnnotationBo (com.navercorp.pinpoint.common.server.bo.AnnotationBo)55 ArrayList (java.util.ArrayList)17 SpanEventBo (com.navercorp.pinpoint.common.server.bo.SpanEventBo)14 SpanBo (com.navercorp.pinpoint.common.server.bo.SpanBo)13 ApiMetaDataBo (com.navercorp.pinpoint.common.server.bo.ApiMetaDataBo)7 Test (org.junit.Test)7 List (java.util.List)6 Buffer (com.navercorp.pinpoint.common.buffer.Buffer)5 TransactionId (com.navercorp.pinpoint.common.profiler.util.TransactionId)5 SpanEventBitField (com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.bitfield.SpanEventBitField)5 AnnotationKey (com.navercorp.pinpoint.common.trace.AnnotationKey)5 Align (com.navercorp.pinpoint.web.calltree.span.Align)4 SpanAlign (com.navercorp.pinpoint.web.calltree.span.SpanAlign)4 ByteBuffer (java.nio.ByteBuffer)4 AutomaticBuffer (com.navercorp.pinpoint.common.buffer.AutomaticBuffer)3 SpanBitFiled (com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.bitfield.SpanBitFiled)3 ServiceType (com.navercorp.pinpoint.common.trace.ServiceType)3 OffsetFixedBuffer (com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer)2 SqlMetaDataBo (com.navercorp.pinpoint.common.server.bo.SqlMetaDataBo)2 StringMetaDataBo (com.navercorp.pinpoint.common.server.bo.StringMetaDataBo)2