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