Search in sources :

Example 16 with SpanRecorder

use of com.navercorp.pinpoint.bootstrap.context.SpanRecorder 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 17 with SpanRecorder

use of com.navercorp.pinpoint.bootstrap.context.SpanRecorder 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)

Example 18 with SpanRecorder

use of com.navercorp.pinpoint.bootstrap.context.SpanRecorder in project pinpoint by naver.

the class TBaseProcessorProcessInterceptor method processTraceObject.

private void processTraceObject(final Trace trace, Object target, Object[] args, Throwable throwable) {
    // end spanEvent
    try {
        SpanEventRecorder recorder = trace.currentSpanEventRecorder();
        // TODO Might need a way to collect and record method arguments
        // trace.recordAttribute(...);
        recorder.recordException(throwable);
        recorder.recordApi(this.descriptor);
    } catch (Throwable t) {
        logger.warn("Error processing trace object. Cause:{}", t.getMessage(), t);
    } finally {
        trace.traceBlockEnd();
    }
    // end root span
    SpanRecorder recorder = trace.getSpanRecorder();
    String methodUri = getMethodUri(target);
    recorder.recordRpcName(methodUri);
    // retrieve connection information
    String localIpPort = ThriftConstants.UNKNOWN_ADDRESS;
    String remoteAddress = ThriftConstants.UNKNOWN_ADDRESS;
    if (args.length == 2 && args[0] instanceof TProtocol) {
        TProtocol inputProtocol = (TProtocol) args[0];
        TTransport inputTransport = inputProtocol.getTransport();
        if (inputTransport instanceof SocketFieldAccessor) {
            Socket socket = ((SocketFieldAccessor) inputTransport)._$PINPOINT$_getSocket();
            if (socket != null) {
                localIpPort = ThriftUtils.getHostPort(socket.getLocalSocketAddress());
                remoteAddress = ThriftUtils.getHost(socket.getRemoteSocketAddress());
            }
        } else {
            if (isDebug) {
                logger.debug("Invalid target object. Need field accessor({}).", SocketFieldAccessor.class.getName());
            }
        }
    }
    if (localIpPort != ThriftConstants.UNKNOWN_ADDRESS) {
        recorder.recordEndPoint(localIpPort);
    }
    if (remoteAddress != ThriftConstants.UNKNOWN_ADDRESS) {
        recorder.recordRemoteAddress(remoteAddress);
    }
}
Also used : SpanRecorder(com.navercorp.pinpoint.bootstrap.context.SpanRecorder) TProtocol(org.apache.thrift.protocol.TProtocol) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) SocketFieldAccessor(com.navercorp.pinpoint.plugin.thrift.field.accessor.SocketFieldAccessor) TTransport(org.apache.thrift.transport.TTransport) Socket(java.net.Socket)

Example 19 with SpanRecorder

use of com.navercorp.pinpoint.bootstrap.context.SpanRecorder in project pinpoint by naver.

the class SpanSimpleAroundInterceptorTest method beforeAfterExceptionLifeCycle.

@Test
public void beforeAfterExceptionLifeCycle() {
    Trace trace = newTrace();
    TraceContext context = newTraceContext(trace);
    TestSpanSimpleAroundInterceptor interceptor = new TestSpanSimpleAroundInterceptor(context) {

        @Override
        protected void doInBeforeTrace(SpanRecorder recorder, Object target, Object[] args) {
            touchBefore();
            throw new RuntimeException();
        }

        @Override
        protected void doInAfterTrace(SpanRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) {
            touchAfter();
            throw new RuntimeException();
        }
    };
    checkSpanInterceptor(context, interceptor);
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) SpanRecorder(com.navercorp.pinpoint.bootstrap.context.SpanRecorder) TraceContext(com.navercorp.pinpoint.bootstrap.context.TraceContext) Test(org.junit.Test)

Example 20 with SpanRecorder

use of com.navercorp.pinpoint.bootstrap.context.SpanRecorder in project pinpoint by naver.

the class SpanSimpleAroundInterceptorTest method beforeExceptionLifeCycle.

@Test
public void beforeExceptionLifeCycle() {
    Trace trace = newTrace();
    TraceContext context = newTraceContext(trace);
    TestSpanSimpleAroundInterceptor interceptor = new TestSpanSimpleAroundInterceptor(context) {

        @Override
        protected void doInBeforeTrace(SpanRecorder trace, Object target, Object[] args) {
            touchBefore();
            throw new RuntimeException();
        }
    };
    checkSpanInterceptor(context, interceptor);
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) SpanRecorder(com.navercorp.pinpoint.bootstrap.context.SpanRecorder) TraceContext(com.navercorp.pinpoint.bootstrap.context.TraceContext) Test(org.junit.Test)

Aggregations

SpanRecorder (com.navercorp.pinpoint.bootstrap.context.SpanRecorder)38 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)23 TraceId (com.navercorp.pinpoint.bootstrap.context.TraceId)10 Test (org.junit.Test)10 WrappedSpanEventRecorder (com.navercorp.pinpoint.profiler.context.recorder.WrappedSpanEventRecorder)8 Storage (com.navercorp.pinpoint.profiler.context.storage.Storage)8 TraceRoot (com.navercorp.pinpoint.profiler.context.id.TraceRoot)6 TraceContext (com.navercorp.pinpoint.bootstrap.context.TraceContext)4 TraceSampler (com.navercorp.pinpoint.bootstrap.sampler.TraceSampler)4 ActiveTraceHandle (com.navercorp.pinpoint.profiler.context.active.ActiveTraceHandle)4 DefaultSpanRecorder (com.navercorp.pinpoint.profiler.context.recorder.DefaultSpanRecorder)4 Span (com.navercorp.pinpoint.profiler.context.Span)3 DefaultTraceId (com.navercorp.pinpoint.profiler.context.id.DefaultTraceId)3 AsyncState (com.navercorp.pinpoint.bootstrap.context.AsyncState)2 SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)2 DefaultTraceRoot (com.navercorp.pinpoint.profiler.context.id.DefaultTraceRoot)2 ListenableAsyncState (com.navercorp.pinpoint.profiler.context.id.ListenableAsyncState)2 AMQP (com.rabbitmq.client.AMQP)2 AMQConnection (com.rabbitmq.client.impl.AMQConnection)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2