Search in sources :

Example 6 with DefaultTraceId

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

the class SpanStreamSendDataPlanerTest method createSpan.

private Span createSpan(List<SpanEvent> spanEventList) {
    DefaultTraceId traceId = new DefaultTraceId("test", 0, 1);
    Span span = new Span();
    for (SpanEvent spanEvent : spanEventList) {
        span.addToSpanEventList(spanEvent);
    }
    span.setAgentId("agentId");
    span.recordTraceId(traceId);
    return span;
}
Also used : DefaultTraceId(com.navercorp.pinpoint.profiler.context.id.DefaultTraceId) SpanEvent(com.navercorp.pinpoint.profiler.context.SpanEvent) TSpanEvent(com.navercorp.pinpoint.thrift.dto.TSpanEvent) Span(com.navercorp.pinpoint.profiler.context.Span)

Example 7 with DefaultTraceId

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

the class InvokeMethodInterceptorTest method testValidHeaderExists.

/**
     * Test valid header exists.
     */
@SuppressWarnings("unchecked")
@Test
public void testValidHeaderExists() {
    when(request.getRequestURI()).thenReturn("/hellotest.nhn");
    when(request.getRemoteAddr()).thenReturn("10.0.0.1");
    TraceId traceId = new DefaultTraceId("agentTest", System.currentTimeMillis(), 1);
    when(request.getHeader(Header.HTTP_TRACE_ID.toString())).thenReturn(traceId.getTransactionId());
    when(request.getHeader(Header.HTTP_PARENT_SPAN_ID.toString())).thenReturn("PARENTSPANID");
    when(request.getHeader(Header.HTTP_SPAN_ID.toString())).thenReturn("SPANID");
    when(request.getHeader(Header.HTTP_SAMPLED.toString())).thenReturn("false");
    when(request.getHeader(Header.HTTP_FLAGS.toString())).thenReturn("0");
    final Enumeration<?> enumeration = mock(Enumeration.class);
    when(request.getParameterNames()).thenReturn((Enumeration<String>) enumeration);
    TraceContext traceContext = spyTraceContext();
    final StandardHostValveInvokeInterceptor interceptor = new StandardHostValveInvokeInterceptor(traceContext, descriptor);
    interceptor.before("target", new Object[] { request, response });
    interceptor.after("target", new Object[] { request, response }, new Object(), null);
    verify(traceContext, times(1)).continueTraceObject(any(TraceId.class));
    interceptor.before("target", new Object[] { request, response });
    interceptor.after("target", new Object[] { request, response }, new Object(), null);
    verify(traceContext, times(2)).continueTraceObject(any(TraceId.class));
}
Also used : DefaultTraceId(com.navercorp.pinpoint.profiler.context.id.DefaultTraceId) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId) DefaultTraceId(com.navercorp.pinpoint.profiler.context.id.DefaultTraceId) TraceContext(com.navercorp.pinpoint.bootstrap.context.TraceContext) StandardHostValveInvokeInterceptor(com.navercorp.pinpoint.plugin.jboss.interceptor.StandardHostValveInvokeInterceptor) Test(org.junit.Test)

Example 8 with DefaultTraceId

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

the class DefaultTraceContextTest method parseTest.

@Test
public void parseTest() {
    String agent = "test";
    long agentStartTime = System.currentTimeMillis();
    long agentTransactionCount = 10;
    TraceId traceId = new DefaultTraceId(agent, agentStartTime, agentTransactionCount);
    String id = traceId.getTransactionId();
    logger.debug("id={}", id);
    TransactionId transactionid = TransactionIdUtils.parseTransactionId(id);
    Assert.assertEquals(transactionid.getAgentId(), agent);
    Assert.assertEquals(transactionid.getAgentStartTime(), agentStartTime);
    Assert.assertEquals(transactionid.getTransactionSequence(), agentTransactionCount);
}
Also used : DefaultTraceId(com.navercorp.pinpoint.profiler.context.id.DefaultTraceId) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId) DefaultTraceId(com.navercorp.pinpoint.profiler.context.id.DefaultTraceId) TransactionId(com.navercorp.pinpoint.common.util.TransactionId) Test(org.junit.Test)

Example 9 with DefaultTraceId

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

the class DefaultTraceContextTest method transactionCountTest.

@Test
public void transactionCountTest() {
    final int samplingRate = 5;
    final ProfilerConfig profilerConfig = Mockito.mock(ProfilerConfig.class);
    Mockito.when(profilerConfig.isTraceAgentActiveThread()).thenReturn(true);
    Mockito.when((profilerConfig.getSamplingRate())).thenReturn(samplingRate);
    Mockito.when((profilerConfig.isSamplingEnable())).thenReturn(true);
    MockTraceContextFactory mockTraceContextFactory = MockTraceContextFactory.newTestTraceContextFactory(profilerConfig);
    final TraceContext traceContext = mockTraceContextFactory.getTraceContext();
    final TransactionCounter transactionCounter = new DefaultTransactionCounter(mockTraceContextFactory.getIdGenerator());
    final long newTransactionCount = 22L;
    @SuppressWarnings("unused") final long expectedSampledNewCount = newTransactionCount / samplingRate + (newTransactionCount % samplingRate > 0 ? 1 : 0);
    final long expectedUnsampledNewCount = newTransactionCount - expectedSampledNewCount;
    for (int i = 0; i < newTransactionCount; ++i) {
        traceContext.newTraceObject();
        traceContext.removeTraceObject();
    }
    final long expectedSampledContinuationCount = 5L;
    for (int i = 0; i < expectedSampledContinuationCount; ++i) {
        traceContext.continueTraceObject(new DefaultTraceId("agentId", 0L, i));
        traceContext.removeTraceObject();
    }
    final long expectedUnsampledContinuationCount = 10L;
    for (int i = 0; i < expectedUnsampledContinuationCount; ++i) {
        traceContext.disableSampling();
        traceContext.removeTraceObject();
    }
    final long expectedTotalTransactionCount = expectedSampledNewCount + expectedUnsampledNewCount + expectedSampledContinuationCount + expectedUnsampledContinuationCount;
    Assert.assertEquals(expectedSampledNewCount, transactionCounter.getSampledNewCount());
    Assert.assertEquals(expectedUnsampledNewCount, transactionCounter.getUnSampledNewCount());
    Assert.assertEquals(expectedSampledContinuationCount, transactionCounter.getSampledContinuationCount());
    Assert.assertEquals(expectedUnsampledContinuationCount, transactionCounter.getUnSampledContinuationCount());
    Assert.assertEquals(expectedTotalTransactionCount, transactionCounter.getTotalTransactionCount());
}
Also used : DefaultTransactionCounter(com.navercorp.pinpoint.profiler.context.id.DefaultTransactionCounter) DefaultTraceId(com.navercorp.pinpoint.profiler.context.id.DefaultTraceId) ProfilerConfig(com.navercorp.pinpoint.bootstrap.config.ProfilerConfig) DefaultProfilerConfig(com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig) TraceContext(com.navercorp.pinpoint.bootstrap.context.TraceContext) DefaultTransactionCounter(com.navercorp.pinpoint.profiler.context.id.DefaultTransactionCounter) TransactionCounter(com.navercorp.pinpoint.profiler.context.id.TransactionCounter) Test(org.junit.Test)

Example 10 with DefaultTraceId

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

the class DefaultAsyncTraceIdTest method nextAsyncSequence.

@Test
public void nextAsyncSequence() throws Exception {
    long agentStartTime = System.currentTimeMillis();
    TraceId traceId = new DefaultTraceId("testAgentId", agentStartTime, 0);
    AsyncTraceId asyncTraceId = new DefaultAsyncTraceId(traceId, 0, agentStartTime + 10);
    Assert.assertEquals(asyncTraceId.nextAsyncSequence(), 1);
    Assert.assertEquals(asyncTraceId.nextAsyncSequence(), 2);
    Assert.assertEquals(asyncTraceId.nextAsyncSequence(), 3);
}
Also used : DefaultTraceId(com.navercorp.pinpoint.profiler.context.id.DefaultTraceId) AsyncTraceId(com.navercorp.pinpoint.bootstrap.context.AsyncTraceId) DefaultAsyncTraceId(com.navercorp.pinpoint.profiler.context.id.DefaultAsyncTraceId) DefaultTraceId(com.navercorp.pinpoint.profiler.context.id.DefaultTraceId) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId) AsyncTraceId(com.navercorp.pinpoint.bootstrap.context.AsyncTraceId) DefaultAsyncTraceId(com.navercorp.pinpoint.profiler.context.id.DefaultAsyncTraceId) DefaultAsyncTraceId(com.navercorp.pinpoint.profiler.context.id.DefaultAsyncTraceId) Test(org.junit.Test)

Aggregations

DefaultTraceId (com.navercorp.pinpoint.profiler.context.id.DefaultTraceId)11 Test (org.junit.Test)8 TraceId (com.navercorp.pinpoint.bootstrap.context.TraceId)7 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)3 TraceContext (com.navercorp.pinpoint.bootstrap.context.TraceContext)3 AsyncIdGenerator (com.navercorp.pinpoint.profiler.context.id.AsyncIdGenerator)3 DefaultRecorderFactory (com.navercorp.pinpoint.profiler.context.recorder.DefaultRecorderFactory)3 RecorderFactory (com.navercorp.pinpoint.profiler.context.recorder.RecorderFactory)3 SpanStorage (com.navercorp.pinpoint.profiler.context.storage.SpanStorage)3 SqlMetaDataService (com.navercorp.pinpoint.profiler.metadata.SqlMetaDataService)3 StringMetaDataService (com.navercorp.pinpoint.profiler.metadata.StringMetaDataService)3 Span (com.navercorp.pinpoint.profiler.context.Span)2 SpanEvent (com.navercorp.pinpoint.profiler.context.SpanEvent)2 TSpanEvent (com.navercorp.pinpoint.thrift.dto.TSpanEvent)2 DefaultProfilerConfig (com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig)1 ProfilerConfig (com.navercorp.pinpoint.bootstrap.config.ProfilerConfig)1 AsyncTraceId (com.navercorp.pinpoint.bootstrap.context.AsyncTraceId)1 TransactionId (com.navercorp.pinpoint.common.util.TransactionId)1 StandardHostValveInvokeInterceptor (com.navercorp.pinpoint.plugin.jboss.interceptor.StandardHostValveInvokeInterceptor)1 StandardHostValveInvokeInterceptor (com.navercorp.pinpoint.plugin.tomcat.interceptor.StandardHostValveInvokeInterceptor)1