use of com.navercorp.pinpoint.bootstrap.context.SpanRecorder in project pinpoint by naver.
the class StandardHostValveInvokeInterceptor method createTrace.
/**
* Creates the trace.
*
* @param target the target
* @param args the args
* @return the trace
*/
private Trace createTrace(final Object target, final Object[] args) {
final HttpServletRequest request = (HttpServletRequest) args[0];
if (isAsynchronousProcess(request)) {
// servlet 3.0
final Trace trace = getTraceMetadata(request);
if (trace != null) {
// change api
final SpanRecorder recorder = trace.getSpanRecorder();
recorder.recordApi(SERVLET_ASYNCHRONOUS_API_TAG);
// attach current thread local.
traceContext.continueTraceObject(trace);
return trace;
}
}
final String requestURI = request.getRequestURI();
if (excludeUrlFilter.filter(requestURI)) {
if (isTrace) {
logger.trace("filter requestURI:{}", requestURI);
}
return null;
}
// check sampling flag from client. If the flag is false, do not sample this request.
final boolean sampling = samplingEnable(request);
if (!sampling) {
// Even if this transaction is not a sampling target, we have to create Trace object to mark 'not sampling'.
// For example, if this transaction invokes rpc call, we can add parameter to tell remote node 'don't sample this
// transaction'
final Trace trace = traceContext.disableSampling();
if (isDebug) {
logger.debug("remotecall sampling flag found. skip trace requestUrl:{}, remoteAddr:{}", request.getRequestURI(), request.getRemoteAddr());
}
return trace;
}
final TraceId traceId = populateTraceIdFromRequest(request);
if (traceId != null) {
// TODO Maybe we should decide to trace or not even if the sampling flag is true to prevent too many requests are
// traced.
final Trace trace = traceContext.continueTraceObject(traceId);
if (trace.canSampled()) {
final SpanRecorder recorder = trace.getSpanRecorder();
recordRootSpan(recorder, request);
setTraceMetadata(request, trace);
if (isDebug) {
logger.debug("TraceID exist. continue trace. traceId:{}, requestUrl:{}, remoteAddr:{}", traceId, request.getRequestURI(), request.getRemoteAddr());
}
} else {
if (isDebug) {
logger.debug("TraceID exist. camSampled is false. skip trace. traceId:{}, requestUrl:{}, remoteAddr:{}", traceId, request.getRequestURI(), request.getRemoteAddr());
}
}
return trace;
} else {
final Trace trace = traceContext.newTraceObject();
if (trace.canSampled()) {
final SpanRecorder recorder = trace.getSpanRecorder();
recordRootSpan(recorder, request);
setTraceMetadata(request, trace);
if (isDebug) {
logger.debug("TraceID not exist. start new trace. requestUrl:{}, remoteAddr:{}", request.getRequestURI(), request.getRemoteAddr());
}
} else {
if (isDebug) {
logger.debug("TraceID not exist. camSampled is false. skip trace. requestUrl:{}, remoteAddr:{}", request.getRequestURI(), request.getRemoteAddr());
}
}
return trace;
}
}
use of com.navercorp.pinpoint.bootstrap.context.SpanRecorder in project pinpoint by naver.
the class ServletInvocationInterceptor method createTrace.
private Trace createTrace(Object target, Object[] args) {
final HttpServletRequest request = (HttpServletRequest) args[0];
if (isAsynchronousProcess(request)) {
// servlet 3.0
final Trace trace = getTraceMetadata(request);
if (trace != null) {
// change api
SpanRecorder recorder = trace.getSpanRecorder();
recorder.recordApi(SERVLET_ASYNCHRONOUS_API_TAG);
// attach current thread local.
traceContext.continueTraceObject(trace);
return trace;
}
}
final Trace currentRawTraceObject = traceContext.currentRawTraceObject();
if (currentRawTraceObject != null) {
return currentRawTraceObject;
}
final String requestURI = request.getRequestURI();
if (excludeUrlFilter.filter(requestURI)) {
if (isDebug) {
logger.debug("filter requestURI:{}", requestURI);
}
return null;
}
// check sampling flag from client. If the flag is false, do not sample this request.
final boolean sampling = samplingEnable(request);
if (!sampling) {
// Even if this transaction is not a sampling target, we have to create Trace object to mark 'not sampling'.
// For example, if this transaction invokes rpc call, we can add parameter to tell remote node 'don't sample this transaction'
final Trace trace = traceContext.disableSampling();
if (isDebug) {
logger.debug("remotecall sampling flag found. skip trace requestUrl:{}, remoteAddr:{}", request.getRequestURI(), request.getRemoteAddr());
}
return trace;
}
final TraceId traceId = populateTraceIdFromRequest(request);
if (traceId != null) {
// TODO Maybe we should decide to trace or not even if the sampling flag is true to prevent too many requests are traced.
final Trace trace = traceContext.continueTraceObject(traceId);
if (trace.canSampled()) {
SpanRecorder recorder = trace.getSpanRecorder();
recordRootSpan(recorder, request);
setTraceMetadata(request, trace);
if (isDebug) {
logger.debug("TraceID exist. continue trace. traceId:{}, requestUrl:{}, remoteAddr:{}", traceId, request.getRequestURI(), request.getRemoteAddr());
}
} else {
if (isDebug) {
logger.debug("TraceID exist. camSampled is false. skip trace. traceId:{}, requestUrl:{}, remoteAddr:{}", traceId, request.getRequestURI(), request.getRemoteAddr());
}
}
return trace;
} else {
final Trace trace = traceContext.newTraceObject();
if (trace.canSampled()) {
SpanRecorder recorder = trace.getSpanRecorder();
recordRootSpan(recorder, request);
setTraceMetadata(request, trace);
if (isDebug) {
logger.debug("TraceID not exist. start new trace. requestUrl:{}, remoteAddr:{} , traceId:{}", request.getRequestURI(), request.getRemoteAddr(), trace.getTraceId());
}
} else {
if (isDebug) {
logger.debug("TraceID not exist. camSampled is false. skip trace. requestUrl:{}, remoteAddr:{}", request.getRequestURI(), request.getRemoteAddr());
}
}
return trace;
}
}
use of com.navercorp.pinpoint.bootstrap.context.SpanRecorder in project pinpoint by naver.
the class ActiveTrace method getEntryPoint.
public String getEntryPoint() {
if (!trace.canSampled()) {
return null;
}
SpanRecorder spanRecorder = trace.getSpanRecorder();
if (!(spanRecorder instanceof DefaultSpanRecorder)) {
return null;
}
Span span = ((DefaultSpanRecorder) spanRecorder).getSpan();
if (span == null) {
return null;
}
return span.getRpc();
}
use of com.navercorp.pinpoint.bootstrap.context.SpanRecorder in project pinpoint by naver.
the class SpanSimpleAroundInterceptorTest method afterExceptionLifeCycle.
@Test
public void afterExceptionLifeCycle() {
Trace trace = newTrace();
TraceContext context = newTraceContext(trace);
TestSpanSimpleAroundInterceptor interceptor = new TestSpanSimpleAroundInterceptor(context) {
@Override
protected void doInAfterTrace(SpanRecorder trace, 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 MethodInvocationHandlerInterceptor method createTrace.
/**
* Creates the trace.
*
* @param target the target
* @param args the args
* @return the trace
*/
private Trace createTrace(final Object target, final Object[] args) {
final Trace trace = traceContext.newTraceObject();
final Connection connection = RemotingContext.getConnection();
final String remoteAddress = JbossUtility.fetchRemoteAddress(connection);
if (trace.canSampled()) {
final SpanRecorder recorder = trace.getSpanRecorder();
final String methodName = getMethodName(args);
recordRootSpan(recorder, methodName, remoteAddress);
if (isDebug) {
logger.debug("Trace sampling is true, Recording trace. methodInvoked:{}, remoteAddress:{}", methodName, remoteAddress);
}
} else {
if (isDebug) {
final String methodName = getMethodName(args);
logger.debug("Trace sampling is false, Skip recording trace. methodInvoked:{}, remoteAddress:{}", methodName, remoteAddress);
}
}
return trace;
}
Aggregations