Search in sources :

Example 16 with TraceId

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

the class InvokeMethodInterceptorTest method testInvalidHeaderExists.

@Test
public void testInvalidHeaderExists() {
    when(request.getRequestURI()).thenReturn("/hellotest.nhn");
    when(request.getRemoteAddr()).thenReturn("10.0.0.1");
    when(request.getHeader(Header.HTTP_TRACE_ID.toString())).thenReturn("TRACEID");
    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");
    Enumeration<?> enumeration = mock(Enumeration.class);
    when(request.getParameterNames()).thenReturn(enumeration);
    TraceContext traceContext = spyTraceContext();
    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, never()).newTraceObject();
    verify(traceContext, never()).disableSampling();
    verify(traceContext, never()).continueTraceObject(any(TraceId.class));
    interceptor.before("target", new Object[] { request, response });
    interceptor.after("target", new Object[] { request, response }, new Object(), null);
    verify(traceContext, never()).newTraceObject();
    verify(traceContext, never()).disableSampling();
    verify(traceContext, never()).continueTraceObject(any(TraceId.class));
}
Also used : TraceContext(com.navercorp.pinpoint.bootstrap.context.TraceContext) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId) DefaultTraceId(com.navercorp.pinpoint.profiler.context.id.DefaultTraceId) StandardHostValveInvokeInterceptor(com.navercorp.pinpoint.plugin.tomcat.interceptor.StandardHostValveInvokeInterceptor) Test(org.junit.Test)

Example 17 with TraceId

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

the class ActiveMQMessageConsumerDispatchInterceptor method createTrace.

@Override
protected Trace createTrace(Object target, Object[] args) {
    if (!validate(target, args)) {
        return null;
    }
    MessageDispatch md = (MessageDispatch) args[0];
    ActiveMQMessage message = (ActiveMQMessage) md.getMessage();
    if (filterDestination(message.getDestination())) {
        return null;
    }
    // These might trigger unmarshalling.
    if (!ActiveMQClientHeader.getSampled(message, true)) {
        return traceContext.disableSampling();
    }
    String transactionId = ActiveMQClientHeader.getTraceId(message, null);
    if (transactionId != null) {
        long parentSpanId = ActiveMQClientHeader.getParentSpanId(message, SpanId.NULL);
        long spanId = ActiveMQClientHeader.getSpanId(message, SpanId.NULL);
        short flags = ActiveMQClientHeader.getFlags(message, (short) 0);
        final TraceId traceId = traceContext.createTraceId(transactionId, parentSpanId, spanId, flags);
        return traceContext.continueTraceObject(traceId);
    } else {
        return traceContext.newTraceObject();
    }
}
Also used : MessageDispatch(org.apache.activemq.command.MessageDispatch) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage)

Example 18 with TraceId

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

the class ActiveMQMessageProducerSendInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    if (!validate(target, args)) {
        return;
    }
    ActiveMQDestination activeMQDestination = (ActiveMQDestination) args[0];
    if (filterDestination(activeMQDestination)) {
        return;
    }
    Trace trace = traceContext.currentRawTraceObject();
    if (trace == null) {
        return;
    }
    Message message = (Message) args[1];
    try {
        if (trace.canSampled()) {
            SpanEventRecorder recorder = trace.traceBlockBegin();
            recorder.recordServiceType(ActiveMQClientConstants.ACTIVEMQ_CLIENT);
            TraceId nextId = trace.getTraceId().getNextTraceId();
            recorder.recordNextSpanId(nextId.getSpanId());
            ActiveMQClientHeader.setTraceId(message, nextId.getTransactionId());
            ActiveMQClientHeader.setSpanId(message, nextId.getSpanId());
            ActiveMQClientHeader.setParentSpanId(message, nextId.getParentSpanId());
            ActiveMQClientHeader.setFlags(message, nextId.getFlags());
            ActiveMQClientHeader.setParentApplicationName(message, traceContext.getApplicationName());
            ActiveMQClientHeader.setParentApplicationType(message, traceContext.getServerTypeCode());
        } else {
            ActiveMQClientHeader.setSampled(message, false);
        }
    } catch (Throwable t) {
        logger.warn("BEFORE. Cause:{}", t.getMessage(), t);
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) Message(javax.jms.Message) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 19 with TraceId

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

the class CxfClientInvokeSyncMethodInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    Trace trace = traceContext.currentRawTraceObject();
    if (trace == null) {
        return;
    }
    if (!trace.canSampled()) {
        if (isDebug) {
            logger.debug("Sampling is disabled");
        }
        return;
    }
    String endpoint = getDestination(args);
    String operation = getOperation(args);
    Object[] parameters = getParameters(operation, args);
    SpanEventRecorder recorder = trace.traceBlockBegin();
    TraceId nextId = trace.getTraceId().getNextTraceId();
    recorder.recordNextSpanId(nextId.getSpanId());
    recorder.recordServiceType(CxfPluginConstants.CXF_CLIENT_SERVICE_TYPE);
    recorder.recordDestinationId(endpoint);
    recorder.recordAttribute(CxfPluginConstants.CXF_OPERATION, operation);
    recorder.recordAttribute(CxfPluginConstants.CXF_ARGS, Arrays.toString(parameters));
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId)

Example 20 with TraceId

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

the class HttpMethodBaseExecuteMethodInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    final Trace trace = traceContext.currentRawTraceObject();
    if (trace == null) {
        return;
    }
    if (!trace.canSampled()) {
        // set http header.
        setHttpSampledHeader(target);
        return;
    }
    final SpanEventRecorder recorder = trace.traceBlockBegin();
    // generate next trace id.
    final TraceId nextId = trace.getTraceId().getNextTraceId();
    recorder.recordNextSpanId(nextId.getSpanId());
    recorder.recordServiceType(HttpClient3Constants.HTTP_CLIENT_3);
    // set http header for trace.
    setHttpTraceHeader(target, args, nextId);
    // init attachment for io(read/write).
    initAttachment();
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId)

Aggregations

TraceId (com.navercorp.pinpoint.bootstrap.context.TraceId)28 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)17 SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)9 DefaultTraceId (com.navercorp.pinpoint.profiler.context.id.DefaultTraceId)9 Test (org.junit.Test)8 AsyncTraceId (com.navercorp.pinpoint.bootstrap.context.AsyncTraceId)6 TraceContext (com.navercorp.pinpoint.bootstrap.context.TraceContext)4 InterceptorScopeInvocation (com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation)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 AsyncStorage (com.navercorp.pinpoint.profiler.context.storage.AsyncStorage)3 SpanStorage (com.navercorp.pinpoint.profiler.context.storage.SpanStorage)3 Storage (com.navercorp.pinpoint.profiler.context.storage.Storage)3 SqlMetaDataService (com.navercorp.pinpoint.profiler.metadata.SqlMetaDataService)3 StringMetaDataService (com.navercorp.pinpoint.profiler.metadata.StringMetaDataService)3 SpanRecorder (com.navercorp.pinpoint.bootstrap.context.SpanRecorder)2 StandardHostValveInvokeInterceptor (com.navercorp.pinpoint.plugin.jboss.interceptor.StandardHostValveInvokeInterceptor)2 ThriftRequestProperty (com.navercorp.pinpoint.plugin.thrift.ThriftRequestProperty)2 StandardHostValveInvokeInterceptor (com.navercorp.pinpoint.plugin.tomcat.interceptor.StandardHostValveInvokeInterceptor)2