use of com.navercorp.pinpoint.profiler.context.id.TraceRoot 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();
}
use of com.navercorp.pinpoint.profiler.context.id.TraceRoot 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();
}
use of com.navercorp.pinpoint.profiler.context.id.TraceRoot in project pinpoint by naver.
the class SpanProcessorV1 method postProcess.
@Override
public void postProcess(SpanChunk spanChunk, TSpanChunk tSpanChunk) {
final TraceRoot traceRoot = spanChunk.getTraceRoot();
final long keyTime = traceRoot.getTraceStartTime();
final List<SpanEvent> spanEventList = spanChunk.getSpanEventList();
if (CollectionUtils.isEmpty(spanEventList)) {
throw new IllegalStateException("SpanChunk.spanEventList is empty");
}
final List<TSpanEvent> tSpanEventList = tSpanChunk.getSpanEventList();
if (CollectionUtils.isEmpty(tSpanEventList)) {
throw new IllegalStateException("TSpanChunk.spanEventList is empty");
}
postEventProcess(spanEventList, tSpanEventList, keyTime);
}
use of com.navercorp.pinpoint.profiler.context.id.TraceRoot in project pinpoint by naver.
the class DisableTraceTest method newChildTrace.
private Trace newChildTrace() {
TraceRoot traceRoot = mock(TraceRoot.class);
LocalAsyncId localAsyncId = mock(LocalAsyncId.class);
return new DisableAsyncChildTrace(traceRoot, localAsyncId);
}
use of com.navercorp.pinpoint.profiler.context.id.TraceRoot in project pinpoint by naver.
the class OrderedSpanRecorderTest method testOrderingWithSameEventTime.
@Test
public void testOrderingWithSameEventTime() {
// given
final long startTime = 100;
final long spanId = 1L;
TraceId traceId = new DefaultTraceId(agentId, startTime, 0, -1L, spanId, (short) 0);
final TraceRoot traceRoot = new DefaultTraceRoot(traceId, agentId, startTime, 0);
Span span = createSpan(traceRoot, startTime);
SpanChunk event = wrapSpanChunk(traceRoot, createSpanEvent(traceRoot, 0, 0));
SpanChunk event1 = wrapSpanChunk(traceRoot, createSpanEvent(traceRoot, 0, 1));
SpanChunk event2 = wrapSpanChunk(traceRoot, createSpanEvent(traceRoot, 0, 2));
SpanChunk asyncEvent1_1 = wrapSpanChunk(traceRoot, createAsyncSpanEvent(traceRoot, 0, 0), new DefaultLocalAsyncId(1, (short) 1));
SpanChunk asyncEvent1_2 = wrapSpanChunk(traceRoot, createAsyncSpanEvent(traceRoot, 0, 1), new DefaultLocalAsyncId(1, (short) 1));
SpanChunk asyncEvent2 = wrapSpanChunk(traceRoot, createAsyncSpanEvent(traceRoot, 0, 0), new DefaultLocalAsyncId(2, (short) 1));
final List<SpanType> expectedOrder = Arrays.asList(span, event, event1, event2, asyncEvent1_1, asyncEvent1_2, asyncEvent2);
// when
final List<SpanType> listToBeHandled = Arrays.asList(span, event, event1, event2, asyncEvent1_1, asyncEvent1_2, asyncEvent2);
Collections.shuffle(listToBeHandled);
for (SpanType base : listToBeHandled) {
this.recorder.handleSend(base);
}
// then
ByteArrayOutputStream baos = new ByteArrayOutputStream();
this.recorder.print(new PrintStream(baos));
this.logger.debug(baos.toString());
for (SpanType expectedBase : expectedOrder) {
SpanType actualBase = this.recorder.pop();
assertSame(expectedBase, actualBase);
}
assertNull(this.recorder.pop());
}
Aggregations