Search in sources :

Example 1 with Shared

use of com.navercorp.pinpoint.profiler.context.id.Shared in project pinpoint by naver.

the class GrpcSpanMessageConverter method buildPSpanChunk.

@VisibleForTesting
PSpanChunk buildPSpanChunk(SpanChunk spanChunk) {
    final PSpanChunk.Builder pSpanChunk = PSpanChunk.newBuilder();
    pSpanChunk.setVersion(SpanVersion.TRACE_V2);
    // tSpanChunk.setApplicationName(applicationName);
    // tSpanChunk.setAgentId(agentId);
    // tSpanChunk.setAgentStartTime(agentStartTime);
    pSpanChunk.setApplicationServiceType(applicationServiceType);
    final TraceRoot traceRoot = spanChunk.getTraceRoot();
    final TraceId traceId = traceRoot.getTraceId();
    final PTransactionId transactionId = newTransactionId(traceId);
    pSpanChunk.setTransactionId(transactionId);
    pSpanChunk.setSpanId(traceId.getSpanId());
    final Shared shared = traceRoot.getShared();
    final String endPoint = shared.getEndPoint();
    if (endPoint != null) {
        pSpanChunk.setEndPoint(endPoint);
    }
    if (spanChunk instanceof AsyncSpanChunk) {
        final AsyncSpanChunk asyncSpanChunk = (AsyncSpanChunk) spanChunk;
        final LocalAsyncId localAsyncId = asyncSpanChunk.getLocalAsyncId();
        final PLocalAsyncId.Builder pAsyncIdBuilder = PLocalAsyncId.newBuilder();
        pAsyncIdBuilder.setAsyncId(localAsyncId.getAsyncId());
        pAsyncIdBuilder.setSequence(localAsyncId.getSequence());
        final PLocalAsyncId pLocalAsyncId = pAsyncIdBuilder.build();
        pSpanChunk.setLocalAsyncId(pLocalAsyncId);
    }
    this.spanProcessor.preProcess(spanChunk, pSpanChunk);
    final List<SpanEvent> spanEventList = spanChunk.getSpanEventList();
    if (CollectionUtils.hasLength(spanEventList)) {
        final List<PSpanEvent> pSpanEvents = buildPSpanEventList(spanEventList);
        pSpanChunk.addAllSpanEvent(pSpanEvents);
    }
    this.spanProcessor.postProcess(spanChunk, pSpanChunk);
    return pSpanChunk.build();
}
Also used : PLocalAsyncId(com.navercorp.pinpoint.grpc.trace.PLocalAsyncId) LocalAsyncId(com.navercorp.pinpoint.profiler.context.LocalAsyncId) PLocalAsyncId(com.navercorp.pinpoint.grpc.trace.PLocalAsyncId) PSpanChunk(com.navercorp.pinpoint.grpc.trace.PSpanChunk) PTransactionId(com.navercorp.pinpoint.grpc.trace.PTransactionId) Shared(com.navercorp.pinpoint.profiler.context.id.Shared) AsyncSpanChunk(com.navercorp.pinpoint.profiler.context.AsyncSpanChunk) PSpanEvent(com.navercorp.pinpoint.grpc.trace.PSpanEvent) SpanEvent(com.navercorp.pinpoint.profiler.context.SpanEvent) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId) TraceRoot(com.navercorp.pinpoint.profiler.context.id.TraceRoot) PSpanEvent(com.navercorp.pinpoint.grpc.trace.PSpanEvent) VisibleForTesting(com.navercorp.pinpoint.common.annotations.VisibleForTesting)

Example 2 with Shared

use of com.navercorp.pinpoint.profiler.context.id.Shared in project pinpoint by naver.

the class GrpcSpanMessageConverter method buildPSpan.

@VisibleForTesting
PSpan buildPSpan(Span span) {
    final PSpan.Builder pSpan = PSpan.newBuilder();
    pSpan.setVersion(SpanVersion.TRACE_V2);
    pSpan.setApplicationServiceType(applicationServiceType);
    final TraceRoot traceRoot = span.getTraceRoot();
    final TraceId traceId = traceRoot.getTraceId();
    final PTransactionId transactionId = newTransactionId(traceId);
    pSpan.setTransactionId(transactionId);
    pSpan.setSpanId(traceId.getSpanId());
    pSpan.setParentSpanId(traceId.getParentSpanId());
    pSpan.setStartTime(span.getStartTime());
    pSpan.setElapsed(span.getElapsedTime());
    pSpan.setServiceType(span.getServiceType());
    PAcceptEvent pAcceptEvent = newAcceptEvent(span);
    pSpan.setAcceptEvent(pAcceptEvent);
    pSpan.setFlag(traceId.getFlags());
    Shared shared = span.getTraceRoot().getShared();
    pSpan.setErr(shared.getErrorCode());
    pSpan.setApiId(span.getApiId());
    final IntStringValue exceptionInfo = span.getExceptionInfo();
    if (exceptionInfo != null) {
        PIntStringValue pIntStringValue = buildPIntStringValue(exceptionInfo);
        pSpan.setExceptionInfo(pIntStringValue);
    }
    pSpan.setLoggingTransactionInfo(shared.getLoggingInfo());
    final List<Annotation<?>> annotations = span.getAnnotations();
    if (CollectionUtils.hasLength(annotations)) {
        final List<PAnnotation> tAnnotations = buildPAnnotation(annotations);
        pSpan.addAllAnnotation(tAnnotations);
    }
    this.spanProcessor.preProcess(span, pSpan);
    final List<SpanEvent> spanEventList = span.getSpanEventList();
    if (CollectionUtils.hasLength(spanEventList)) {
        final List<PSpanEvent> pSpanEvents = buildPSpanEventList(spanEventList);
        pSpan.addAllSpanEvent(pSpanEvents);
    }
    this.spanProcessor.postProcess(span, pSpan);
    return pSpan.build();
}
Also used : PAnnotation(com.navercorp.pinpoint.grpc.trace.PAnnotation) PTransactionId(com.navercorp.pinpoint.grpc.trace.PTransactionId) Shared(com.navercorp.pinpoint.profiler.context.id.Shared) Annotation(com.navercorp.pinpoint.profiler.context.Annotation) PAnnotation(com.navercorp.pinpoint.grpc.trace.PAnnotation) PSpan(com.navercorp.pinpoint.grpc.trace.PSpan) PIntStringValue(com.navercorp.pinpoint.grpc.trace.PIntStringValue) IntStringValue(com.navercorp.pinpoint.common.util.IntStringValue) PIntStringValue(com.navercorp.pinpoint.grpc.trace.PIntStringValue) PSpanEvent(com.navercorp.pinpoint.grpc.trace.PSpanEvent) SpanEvent(com.navercorp.pinpoint.profiler.context.SpanEvent) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId) TraceRoot(com.navercorp.pinpoint.profiler.context.id.TraceRoot) PAcceptEvent(com.navercorp.pinpoint.grpc.trace.PAcceptEvent) PSpanEvent(com.navercorp.pinpoint.grpc.trace.PSpanEvent) VisibleForTesting(com.navercorp.pinpoint.common.annotations.VisibleForTesting)

Example 3 with Shared

use of com.navercorp.pinpoint.profiler.context.id.Shared in project pinpoint by naver.

the class Span method finish.

public void finish() {
    // snapshot last image
    final Shared shared = traceRoot.getShared();
    if (shared.getStatusCode() != 0) {
        Annotation<Integer> annotation = Annotations.of(AnnotationKey.HTTP_STATUS_CODE.getCode(), shared.getStatusCode());
        this.addAnnotation(annotation);
    }
}
Also used : Shared(com.navercorp.pinpoint.profiler.context.id.Shared)

Example 4 with Shared

use of com.navercorp.pinpoint.profiler.context.id.Shared in project pinpoint by naver.

the class SpanThriftMessageConverterTest method buildTSpan.

@Test
public void buildTSpan() {
    final Span span = newSpan();
    span.setStartTime(System.currentTimeMillis());
    span.setElapsedTime(RandomExUtils.nextInt(0, 100));
    span.setAcceptorHost("acceptorHost");
    span.setExceptionInfo(new IntStringValue(RandomExUtils.nextInt(0, 100), "error"));
    span.setApiId(RandomExUtils.nextInt(0, 100));
    span.setServiceType((short) RandomExUtils.nextInt(0, 100));
    span.setRemoteAddr("remoteAddr");
    span.setParentApplicationName("pApp");
    span.setParentApplicationType((short) RandomExUtils.nextInt(0, 100));
    final TraceRoot traceRoot = span.getTraceRoot();
    Shared shared = traceRoot.getShared();
    shared.setEndPoint("endPoint");
    shared.setRpcName("rpcName");
    shared.setLoggingInfo((byte) RandomExUtils.nextInt(0, 10));
    shared.maskErrorCode(RandomExUtils.nextInt(0, 100));
    shared.setStatusCode(RandomExUtils.nextInt(0, 100));
    span.addAnnotation(Annotations.of(1));
    span.setSpanEventList(Collections.singletonList(new SpanEvent()));
    final TSpan tSpan = messageConverter.buildTSpan(span);
    Assert.assertEquals(span.getStartTime(), tSpan.getStartTime());
    Assert.assertEquals(span.getElapsedTime(), tSpan.getElapsed());
    Assert.assertEquals(span.getAcceptorHost(), tSpan.getAcceptorHost());
    Assert.assertEquals(span.getExceptionInfo().getIntValue(), tSpan.getExceptionInfo().getIntValue());
    Assert.assertEquals(span.getExceptionInfo().getStringValue(), tSpan.getExceptionInfo().getStringValue());
    Assert.assertEquals(span.getApiId(), tSpan.getApiId());
    Assert.assertEquals(span.getServiceType(), tSpan.getServiceType());
    Assert.assertEquals(span.getRemoteAddr(), tSpan.getRemoteAddr());
    Assert.assertEquals(span.getParentApplicationName(), tSpan.getParentApplicationName());
    Assert.assertEquals(span.getParentApplicationType(), tSpan.getParentApplicationType());
    Assert.assertEquals(traceRoot.getTraceId().getSpanId(), tSpan.getSpanId());
    Assert.assertEquals(traceRoot.getShared().getEndPoint(), tSpan.getEndPoint());
    Assert.assertEquals(traceRoot.getShared().getRpcName(), tSpan.getRpc());
    Assert.assertEquals(traceRoot.getShared().getLoggingInfo(), tSpan.getLoggingTransactionInfo());
    Assert.assertEquals(traceRoot.getShared().getErrorCode(), tSpan.getErr());
    // TODO
    // Assert.assertEquals(traceRoot.getShared().getStatusCode(),  );
    Assert.assertEquals(span.getAnnotations().size(), tSpan.getAnnotations().size());
    Assert.assertEquals(span.getSpanEventList().size(), tSpan.getSpanEventList().size());
}
Also used : IntStringValue(com.navercorp.pinpoint.common.util.IntStringValue) SpanEvent(com.navercorp.pinpoint.profiler.context.SpanEvent) TSpanEvent(com.navercorp.pinpoint.thrift.dto.TSpanEvent) TSpan(com.navercorp.pinpoint.thrift.dto.TSpan) DefaultTraceRoot(com.navercorp.pinpoint.profiler.context.id.DefaultTraceRoot) TraceRoot(com.navercorp.pinpoint.profiler.context.id.TraceRoot) Shared(com.navercorp.pinpoint.profiler.context.id.Shared) TSpan(com.navercorp.pinpoint.thrift.dto.TSpan) Span(com.navercorp.pinpoint.profiler.context.Span) Test(org.junit.Test)

Example 5 with Shared

use of com.navercorp.pinpoint.profiler.context.id.Shared in project pinpoint by naver.

the class SpanThriftMessageConverter method buildTSpanChunk.

@VisibleForTesting
TSpanChunk buildTSpanChunk(SpanChunk spanChunk) {
    final TSpanChunk tSpanChunk = new TSpanChunk();
    tSpanChunk.setApplicationName(applicationName);
    tSpanChunk.setAgentId(agentId);
    tSpanChunk.setAgentStartTime(agentStartTime);
    tSpanChunk.setApplicationServiceType(applicationServiceType);
    final TraceRoot traceRoot = spanChunk.getTraceRoot();
    final TraceId traceId = traceRoot.getTraceId();
    final ByteBuffer transactionId = transactionIdEncoder.encodeTransactionId(traceId);
    tSpanChunk.setTransactionId(transactionId);
    tSpanChunk.setSpanId(traceId.getSpanId());
    final Shared shared = traceRoot.getShared();
    tSpanChunk.setEndPoint(shared.getEndPoint());
    if (spanChunk instanceof AsyncSpanChunk) {
        final AsyncSpanChunk asyncSpanChunk = (AsyncSpanChunk) spanChunk;
        final LocalAsyncId localAsyncId = asyncSpanChunk.getLocalAsyncId();
        final TLocalAsyncId tLocalAsyncId = new TLocalAsyncId(localAsyncId.getAsyncId(), localAsyncId.getSequence());
        tSpanChunk.setLocalAsyncId(tLocalAsyncId);
    }
    spanPostProcessor.preProcess(spanChunk, tSpanChunk);
    final List<SpanEvent> spanEventList = spanChunk.getSpanEventList();
    if (CollectionUtils.hasLength(spanEventList)) {
        final List<TSpanEvent> tSpanEvents = buildTSpanEventList(spanEventList);
        tSpanChunk.setSpanEventList(tSpanEvents);
    }
    spanPostProcessor.postProcess(spanChunk, tSpanChunk);
    return tSpanChunk;
}
Also used : TSpanChunk(com.navercorp.pinpoint.thrift.dto.TSpanChunk) AsyncSpanChunk(com.navercorp.pinpoint.profiler.context.AsyncSpanChunk) TLocalAsyncId(com.navercorp.pinpoint.thrift.dto.TLocalAsyncId) LocalAsyncId(com.navercorp.pinpoint.profiler.context.LocalAsyncId) TLocalAsyncId(com.navercorp.pinpoint.thrift.dto.TLocalAsyncId) SpanEvent(com.navercorp.pinpoint.profiler.context.SpanEvent) TSpanEvent(com.navercorp.pinpoint.thrift.dto.TSpanEvent) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId) TraceRoot(com.navercorp.pinpoint.profiler.context.id.TraceRoot) Shared(com.navercorp.pinpoint.profiler.context.id.Shared) ByteBuffer(java.nio.ByteBuffer) TSpanEvent(com.navercorp.pinpoint.thrift.dto.TSpanEvent) VisibleForTesting(com.navercorp.pinpoint.common.annotations.VisibleForTesting)

Aggregations

Shared (com.navercorp.pinpoint.profiler.context.id.Shared)7 SpanEvent (com.navercorp.pinpoint.profiler.context.SpanEvent)5 TraceRoot (com.navercorp.pinpoint.profiler.context.id.TraceRoot)5 TraceId (com.navercorp.pinpoint.bootstrap.context.TraceId)4 VisibleForTesting (com.navercorp.pinpoint.common.annotations.VisibleForTesting)4 IntStringValue (com.navercorp.pinpoint.common.util.IntStringValue)3 TSpanEvent (com.navercorp.pinpoint.thrift.dto.TSpanEvent)3 PAcceptEvent (com.navercorp.pinpoint.grpc.trace.PAcceptEvent)2 PSpanEvent (com.navercorp.pinpoint.grpc.trace.PSpanEvent)2 PTransactionId (com.navercorp.pinpoint.grpc.trace.PTransactionId)2 Annotation (com.navercorp.pinpoint.profiler.context.Annotation)2 AsyncSpanChunk (com.navercorp.pinpoint.profiler.context.AsyncSpanChunk)2 LocalAsyncId (com.navercorp.pinpoint.profiler.context.LocalAsyncId)2 TSpan (com.navercorp.pinpoint.thrift.dto.TSpan)2 ByteBuffer (java.nio.ByteBuffer)2 PAnnotation (com.navercorp.pinpoint.grpc.trace.PAnnotation)1 PIntStringValue (com.navercorp.pinpoint.grpc.trace.PIntStringValue)1 PLocalAsyncId (com.navercorp.pinpoint.grpc.trace.PLocalAsyncId)1 PParentInfo (com.navercorp.pinpoint.grpc.trace.PParentInfo)1 PSpan (com.navercorp.pinpoint.grpc.trace.PSpan)1