Search in sources :

Example 26 with TraceRoot

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

the class OrderedSpanRecorderTest method testMultipleAsyncSpanEvents.

@Test
public void testMultipleAsyncSpanEvents() {
    // given
    final long startTime1 = 100;
    final long spanId = 1L;
    TraceId traceId1 = new DefaultTraceId(agentId, startTime1, 0, -1L, spanId, (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 span = createSpan(traceRoot1, startTime1);
    SpanChunk event1 = wrapSpanChunk(traceRoot1, createSpanEvent(traceRoot1, 0, 0));
    SpanChunk asyncEvent1_1_1 = wrapSpanChunk(traceRoot1, createAsyncSpanEvent(traceRoot1, 0, 0), new DefaultLocalAsyncId(1, (short) 1));
    SpanChunk asyncEvent1_1_2 = wrapSpanChunk(traceRoot1, createAsyncSpanEvent(traceRoot1, 0, 1), new DefaultLocalAsyncId(1, (short) 1));
    SpanChunk asyncEvent1_2_1 = wrapSpanChunk(traceRoot1, createAsyncSpanEvent(traceRoot1, 0, 0), new DefaultLocalAsyncId(1, (short) 2));
    SpanChunk event2 = wrapSpanChunk(traceRoot2, createSpanEvent(traceRoot2, 0, 1));
    SpanChunk asyncEvent2_1 = wrapSpanChunk(traceRoot2, createAsyncSpanEvent(traceRoot2, 0, 0), new DefaultLocalAsyncId(2, (short) 1));
    SpanChunk asyncEvent2_2 = wrapSpanChunk(traceRoot2, createAsyncSpanEvent(traceRoot2, 0, 0), new DefaultLocalAsyncId(2, (short) 2));
    final List<SpanType> expectedOrder = Arrays.asList(span, event1, event2, asyncEvent1_1_1, asyncEvent1_1_2, asyncEvent1_2_1, asyncEvent2_1, asyncEvent2_2);
    // when
    final List<SpanType> listToBeHandled = Arrays.asList(span, event1, asyncEvent1_1_1, asyncEvent1_1_2, asyncEvent1_2_1, event2, asyncEvent2_1, asyncEvent2_2);
    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 27 with TraceRoot

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

the class SpanAsyncStateListener method finish.

@Override
public void finish() {
    if (CLOSED_UPDATER.compareAndSet(this, OPEN, CLOSED)) {
        if (span.isTimeRecording()) {
            span.markAfterTime();
        }
        final TraceRoot traceRoot = span.getTraceRoot();
        SpanChunkFactory spanChunkFactory = new DefaultSpanChunkFactory(traceRoot);
        final Storage storage = storageFactory.createStorage(spanChunkFactory);
        storage.store(this.span);
        storage.close();
    }
}
Also used : Storage(com.navercorp.pinpoint.profiler.context.storage.Storage) TraceRoot(com.navercorp.pinpoint.profiler.context.id.TraceRoot)

Example 28 with TraceRoot

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

the class SpanThriftMessageConverterTest method buildTSpanChunk.

@Test
public void buildTSpanChunk() {
    final SpanChunk spanChunk = newSpanChunk();
    TraceRoot traceRoot = spanChunk.getTraceRoot();
    TSpanChunk tSpanChunk = messageConverter.buildTSpanChunk(spanChunk);
    Assert.assertEquals(traceRoot.getTraceId().getSpanId(), tSpanChunk.getSpanId());
    Assert.assertEquals(traceRoot.getShared().getEndPoint(), tSpanChunk.getEndPoint());
}
Also used : TSpanChunk(com.navercorp.pinpoint.thrift.dto.TSpanChunk) DefaultSpanChunk(com.navercorp.pinpoint.profiler.context.DefaultSpanChunk) SpanChunk(com.navercorp.pinpoint.profiler.context.SpanChunk) TSpanChunk(com.navercorp.pinpoint.thrift.dto.TSpanChunk) DefaultTraceRoot(com.navercorp.pinpoint.profiler.context.id.DefaultTraceRoot) TraceRoot(com.navercorp.pinpoint.profiler.context.id.TraceRoot) Test(org.junit.Test)

Example 29 with TraceRoot

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

the class SpanThriftMessageConverterTest method newSpan.

private Span newSpan() {
    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 Span(traceRoot);
}
Also used : DefaultTraceId(com.navercorp.pinpoint.profiler.context.id.DefaultTraceId) DefaultTraceRoot(com.navercorp.pinpoint.profiler.context.id.DefaultTraceRoot) 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) TSpan(com.navercorp.pinpoint.thrift.dto.TSpan) Span(com.navercorp.pinpoint.profiler.context.Span)

Example 30 with TraceRoot

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

the class DefaultTransactionIdEncoderTest method testNormalTransactionId.

@Test
public void testNormalTransactionId() {
    TraceRoot traceRoot = getExternalTraceId();
    TraceId traceId = traceRoot.getTraceId();
    ByteBuffer encodeTxId = transactionIdEncoder.encodeTransactionId(traceId);
    byte[] transactionId = Arrays.copyOf(encodeTxId.array(), encodeTxId.remaining());
    TransactionId parsedTxId = TransactionIdUtils.parseTransactionId(transactionId, DEFAULT_AGENT_ID);
    logger.debug("transactionId:{}", parsedTxId);
    Assert.assertEquals(parsedTxId.getAgentId(), agentId2);
    Assert.assertEquals(parsedTxId.getAgentStartTime(), agentStartTime2);
    Assert.assertEquals(parsedTxId.getTransactionSequence(), transactionId2);
}
Also used : DefaultTraceId(com.navercorp.pinpoint.profiler.context.id.DefaultTraceId) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId) DefaultTraceRoot(com.navercorp.pinpoint.profiler.context.id.DefaultTraceRoot) TraceRoot(com.navercorp.pinpoint.profiler.context.id.TraceRoot) ByteBuffer(java.nio.ByteBuffer) TransactionId(com.navercorp.pinpoint.common.profiler.util.TransactionId) 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