Search in sources :

Example 1 with SpanRecorder

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;
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Trace(com.navercorp.pinpoint.bootstrap.context.Trace) SpanRecorder(com.navercorp.pinpoint.bootstrap.context.SpanRecorder) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId)

Example 2 with SpanRecorder

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;
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Trace(com.navercorp.pinpoint.bootstrap.context.Trace) SpanRecorder(com.navercorp.pinpoint.bootstrap.context.SpanRecorder) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId)

Example 3 with SpanRecorder

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();
}
Also used : SpanRecorder(com.navercorp.pinpoint.bootstrap.context.SpanRecorder) DefaultSpanRecorder(com.navercorp.pinpoint.profiler.context.recorder.DefaultSpanRecorder) DefaultSpanRecorder(com.navercorp.pinpoint.profiler.context.recorder.DefaultSpanRecorder) Span(com.navercorp.pinpoint.profiler.context.Span)

Example 4 with SpanRecorder

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);
}
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 5 with SpanRecorder

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;
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) SpanRecorder(com.navercorp.pinpoint.bootstrap.context.SpanRecorder) Connection(org.jboss.remoting3.Connection)

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