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));
}
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));
}
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);
}
}
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);
}
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);
}
Aggregations