Search in sources :

Example 6 with TraceRoot

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

the class OrderedSpanRecorderTest method testMultipleSpanOrdering.

@Test
public void testMultipleSpanOrdering() {
    // given
    final long startTime1 = 100;
    final long spanId1 = 1L;
    final TraceId traceId1 = new DefaultTraceId(agentId, startTime1, 0, -1L, spanId1, (short) 0);
    final TraceRoot traceRoot1 = new DefaultTraceRoot(traceId1, agentId, startTime1, 0);
    final long startTime2 = startTime1 + 10L;
    final long spanId2 = 2L;
    final TraceId traceId2 = new DefaultTraceId(agentId, startTime2, 0, -1L, spanId2, (short) 0);
    final TraceRoot traceRoot2 = new DefaultTraceRoot(traceId2, agentId, startTime2, 0);
    Span span1 = createSpan(traceRoot1, startTime1);
    SpanChunk event1_0 = wrapSpanChunk(traceRoot1, createSpanEvent(traceRoot1, 1, 0));
    SpanChunk event1_1 = wrapSpanChunk(traceRoot1, createSpanEvent(traceRoot1, 2, 1));
    SpanChunk asyncEvent1_0 = wrapSpanChunk(traceRoot1, createAsyncSpanEvent(traceRoot1, 1, 0), new DefaultLocalAsyncId(1, (short) 1));
    SpanChunk asyncEvent1_1 = wrapSpanChunk(traceRoot1, createAsyncSpanEvent(traceRoot1, 2, 1), new DefaultLocalAsyncId(1, (short) 1));
    Span span2 = createSpan(traceRoot2, startTime2);
    SpanChunk event2_0 = wrapSpanChunk(traceRoot2, createSpanEvent(traceRoot2, 0, 0));
    SpanChunk event2_1 = wrapSpanChunk(traceRoot2, createSpanEvent(traceRoot2, 1, 1));
    SpanChunk asyncEvent2_0 = wrapSpanChunk(traceRoot2, createAsyncSpanEvent(traceRoot2, 0, 0), new DefaultLocalAsyncId(2, (short) 1));
    final List<SpanType> expectedOrder = Arrays.asList(span1, event1_0, event1_1, span2, event2_0, event2_1, asyncEvent1_0, asyncEvent1_1, asyncEvent2_0);
    // when
    final List<SpanType> listToBeHandled = Arrays.asList(span1, event1_0, event1_1, span2, event2_0, event2_1, asyncEvent1_0, asyncEvent1_1, asyncEvent2_0);
    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());
}
Also used : PrintStream(java.io.PrintStream) SpanType(com.navercorp.pinpoint.profiler.context.SpanType) DefaultTraceId(com.navercorp.pinpoint.profiler.context.id.DefaultTraceId) DefaultTraceRoot(com.navercorp.pinpoint.profiler.context.id.DefaultTraceRoot) DefaultSpanChunk(com.navercorp.pinpoint.profiler.context.DefaultSpanChunk) SpanChunk(com.navercorp.pinpoint.profiler.context.SpanChunk) DefaultAsyncSpanChunk(com.navercorp.pinpoint.profiler.context.DefaultAsyncSpanChunk) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId) DefaultTraceId(com.navercorp.pinpoint.profiler.context.id.DefaultTraceId) DefaultLocalAsyncId(com.navercorp.pinpoint.profiler.context.DefaultLocalAsyncId) DefaultTraceRoot(com.navercorp.pinpoint.profiler.context.id.DefaultTraceRoot) TraceRoot(com.navercorp.pinpoint.profiler.context.id.TraceRoot) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Span(com.navercorp.pinpoint.profiler.context.Span) Test(org.junit.Test)

Example 7 with TraceRoot

use of com.navercorp.pinpoint.profiler.context.id.TraceRoot 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 8 with TraceRoot

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

the class SpanThriftMessageConverterTest method newSpanChunk.

private SpanChunk newSpanChunk() {
    final TraceId traceId = new DefaultTraceId(AGENT_ID, AGENT_START_TIME, 1L);
    final TraceRoot traceRoot = new DefaultTraceRoot(traceId, AGENT_ID, AGENT_START_TIME, 100L);
    return new DefaultSpanChunk(traceRoot, Arrays.asList(new SpanEvent()));
}
Also used : DefaultTraceId(com.navercorp.pinpoint.profiler.context.id.DefaultTraceId) DefaultTraceRoot(com.navercorp.pinpoint.profiler.context.id.DefaultTraceRoot) SpanEvent(com.navercorp.pinpoint.profiler.context.SpanEvent) TSpanEvent(com.navercorp.pinpoint.thrift.dto.TSpanEvent) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId) DefaultTraceId(com.navercorp.pinpoint.profiler.context.id.DefaultTraceId) DefaultTraceRoot(com.navercorp.pinpoint.profiler.context.id.DefaultTraceRoot) TraceRoot(com.navercorp.pinpoint.profiler.context.id.TraceRoot) DefaultSpanChunk(com.navercorp.pinpoint.profiler.context.DefaultSpanChunk)

Example 9 with TraceRoot

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

the class TraceTest method trace.

@Test
public void trace() {
    final TraceId traceId = new DefaultTraceId(agentId, agentStartTime, 1);
    final TraceRoot traceRoot = new DefaultTraceRoot(traceId, agentId, traceStartTime, 0);
    final CallStack<SpanEvent> callStack = newCallStack();
    final Span span = newSpan(traceRoot);
    boolean root = span.getTraceRoot().getTraceId().isRoot();
    SpanRecorder spanRecorder = new DefaultSpanRecorder(span, root, true, stringMetaDataService, sqlMetaDataService, errorHandler);
    WrappedSpanEventRecorder wrappedSpanEventRecorder = new WrappedSpanEventRecorder(traceRoot, asyncContextFactory, stringMetaDataService, sqlMetaDataService, errorHandler);
    AsyncContextFactory asyncContextFactory = mock(AsyncContextFactory.class);
    Storage storage = mock(Storage.class);
    Trace trace = new DefaultTrace(span, callStack, storage, true, spanRecorder, wrappedSpanEventRecorder, ActiveTraceHandle.EMPTY_HANDLE);
    trace.traceBlockBegin();
    // get data form db
    getDataFromDB(trace);
    // response to client
    trace.traceBlockEnd();
    verify(storage, times(2)).store(Mockito.any(SpanEvent.class));
    verify(storage, never()).store(Mockito.any(Span.class));
}
Also used : DefaultTraceId(com.navercorp.pinpoint.profiler.context.id.DefaultTraceId) DefaultTraceRoot(com.navercorp.pinpoint.profiler.context.id.DefaultTraceRoot) WrappedSpanEventRecorder(com.navercorp.pinpoint.profiler.context.recorder.WrappedSpanEventRecorder) Trace(com.navercorp.pinpoint.bootstrap.context.Trace) SpanRecorder(com.navercorp.pinpoint.bootstrap.context.SpanRecorder) DefaultSpanRecorder(com.navercorp.pinpoint.profiler.context.recorder.DefaultSpanRecorder) Storage(com.navercorp.pinpoint.profiler.context.storage.Storage) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId) DefaultTraceId(com.navercorp.pinpoint.profiler.context.id.DefaultTraceId) DefaultTraceRoot(com.navercorp.pinpoint.profiler.context.id.DefaultTraceRoot) TraceRoot(com.navercorp.pinpoint.profiler.context.id.TraceRoot) DefaultSpanRecorder(com.navercorp.pinpoint.profiler.context.recorder.DefaultSpanRecorder) Test(org.junit.Test)

Example 10 with TraceRoot

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

the class TraceTest method popEventTest.

@Test
public void popEventTest() {
    final TraceId traceId = new DefaultTraceId(agentId, agentStartTime, 1);
    final TraceRoot traceRoot = new DefaultTraceRoot(traceId, agentId, traceStartTime, 0);
    final CallStack<SpanEvent> callStack = newCallStack();
    final Span span = newSpan(traceRoot);
    final boolean root = span.getTraceRoot().getTraceId().isRoot();
    SpanRecorder spanRecorder = new DefaultSpanRecorder(span, root, true, stringMetaDataService, sqlMetaDataService, errorHandler);
    WrappedSpanEventRecorder wrappedSpanEventRecorder = new WrappedSpanEventRecorder(traceRoot, asyncContextFactory, stringMetaDataService, sqlMetaDataService, errorHandler);
    AsyncContextFactory asyncContextFactory = mock(AsyncContextFactory.class);
    Storage storage = mock(Storage.class);
    Trace trace = new DefaultTrace(span, callStack, storage, true, spanRecorder, wrappedSpanEventRecorder, ActiveTraceHandle.EMPTY_HANDLE);
    trace.close();
    verify(storage, never()).store(Mockito.any(SpanEvent.class));
    verify(storage).store(Mockito.any(Span.class));
}
Also used : DefaultTraceId(com.navercorp.pinpoint.profiler.context.id.DefaultTraceId) DefaultTraceRoot(com.navercorp.pinpoint.profiler.context.id.DefaultTraceRoot) WrappedSpanEventRecorder(com.navercorp.pinpoint.profiler.context.recorder.WrappedSpanEventRecorder) Trace(com.navercorp.pinpoint.bootstrap.context.Trace) SpanRecorder(com.navercorp.pinpoint.bootstrap.context.SpanRecorder) DefaultSpanRecorder(com.navercorp.pinpoint.profiler.context.recorder.DefaultSpanRecorder) Storage(com.navercorp.pinpoint.profiler.context.storage.Storage) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId) DefaultTraceId(com.navercorp.pinpoint.profiler.context.id.DefaultTraceId) DefaultTraceRoot(com.navercorp.pinpoint.profiler.context.id.DefaultTraceRoot) TraceRoot(com.navercorp.pinpoint.profiler.context.id.TraceRoot) DefaultSpanRecorder(com.navercorp.pinpoint.profiler.context.recorder.DefaultSpanRecorder) Test(org.junit.Test)

Aggregations

TraceRoot (com.navercorp.pinpoint.profiler.context.id.TraceRoot)36 TraceId (com.navercorp.pinpoint.bootstrap.context.TraceId)17 DefaultTraceRoot (com.navercorp.pinpoint.profiler.context.id.DefaultTraceRoot)16 Test (org.junit.Test)13 DefaultTraceId (com.navercorp.pinpoint.profiler.context.id.DefaultTraceId)12 SpanEvent (com.navercorp.pinpoint.profiler.context.SpanEvent)10 TSpanEvent (com.navercorp.pinpoint.thrift.dto.TSpanEvent)9 DefaultSpanChunk (com.navercorp.pinpoint.profiler.context.DefaultSpanChunk)7 Storage (com.navercorp.pinpoint.profiler.context.storage.Storage)7 SpanRecorder (com.navercorp.pinpoint.bootstrap.context.SpanRecorder)6 Span (com.navercorp.pinpoint.profiler.context.Span)6 SpanChunk (com.navercorp.pinpoint.profiler.context.SpanChunk)6 WrappedSpanEventRecorder (com.navercorp.pinpoint.profiler.context.recorder.WrappedSpanEventRecorder)6 TSpan (com.navercorp.pinpoint.thrift.dto.TSpan)6 SpanType (com.navercorp.pinpoint.profiler.context.SpanType)5 Shared (com.navercorp.pinpoint.profiler.context.id.Shared)5 ByteBuffer (java.nio.ByteBuffer)5 TraceSampler (com.navercorp.pinpoint.bootstrap.sampler.TraceSampler)4 VisibleForTesting (com.navercorp.pinpoint.common.annotations.VisibleForTesting)4 ActiveTraceHandle (com.navercorp.pinpoint.profiler.context.active.ActiveTraceHandle)4