use of com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation in project pinpoint by naver.
the class JedisPipelineMethodInterceptor method doInAfterTrace.
@Override
public void doInAfterTrace(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) {
String endPoint = null;
if (target instanceof EndPointAccessor) {
endPoint = ((EndPointAccessor) target)._$PINPOINT$_getEndPoint();
}
final InterceptorScopeInvocation invocation = interceptorScope.getCurrentInvocation();
if (invocation != null && invocation.getAttachment() != null && invocation.getAttachment() instanceof CommandContext) {
final CommandContext commandContext = (CommandContext) invocation.getAttachment();
logger.debug("Check command context {}", commandContext);
if (io) {
final StringBuilder sb = new StringBuilder();
sb.append("write=").append(commandContext.getWriteElapsedTime());
if (commandContext.isWriteFail()) {
sb.append("(fail)");
}
sb.append(", read=").append(commandContext.getReadElapsedTime());
if (commandContext.isReadFail()) {
sb.append("(fail)");
}
recorder.recordAttribute(AnnotationKey.ARGS0, sb.toString());
}
// clear
invocation.removeAttachment();
}
recorder.recordApi(getMethodDescriptor());
recorder.recordEndPoint(endPoint != null ? endPoint : "Unknown");
recorder.recordDestinationId(RedisConstants.REDIS.getName());
recorder.recordServiceType(RedisConstants.REDIS);
recorder.recordException(throwable);
}
use of com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation in project pinpoint by naver.
the class ProtocolSendCommandAndReadMethodInterceptor method before.
@Override
public void before(Object target, Object[] args) {
if (isDebug) {
logger.beforeInterceptor(target, args);
}
final Trace trace = traceContext.currentTraceObject();
if (trace == null) {
return;
}
try {
final InterceptorScopeInvocation invocation = interceptorScope.getCurrentInvocation();
if (invocation != null && invocation.getAttachment() != null && invocation.getAttachment() instanceof CommandContext) {
final CommandContext commandContext = (CommandContext) invocation.getAttachment();
if (methodDescriptor.getMethodName().equals("sendCommand")) {
commandContext.setWriteBeginTime(System.currentTimeMillis());
} else {
commandContext.setReadBeginTime(System.currentTimeMillis());
}
logger.debug("Set command context {}", commandContext);
}
} catch (Throwable t) {
logger.warn("Failed to BEFORE process. {}", t.getMessage(), t);
}
}
use of com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation in project pinpoint by naver.
the class HttpRequestExecutorDoSendRequestAndDoReceiveResponseMethodInterceptor method before.
@Override
public void before(Object target, Object[] args) {
if (isDebug) {
logger.beforeInterceptor(target, args);
}
final Trace trace = traceContext.currentTraceObject();
if (trace == null) {
return;
}
final InterceptorScopeInvocation invocation = interceptorScope.getCurrentInvocation();
if (invocation != null && invocation.getAttachment() != null && invocation.getAttachment() instanceof HttpCallContext) {
HttpCallContext callContext = (HttpCallContext) invocation.getAttachment();
if (methodDescriptor.getMethodName().equals("doSendRequest")) {
callContext.setWriteBeginTime(System.currentTimeMillis());
} else {
callContext.setReadBeginTime(System.currentTimeMillis());
}
if (isDebug) {
logger.debug("Set call context {}", callContext);
}
}
}
use of com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation in project pinpoint by naver.
the class HttpRequestExecutorExecuteMethodInterceptor method after.
@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
if (isDebug) {
logger.afterInterceptor(target, args);
}
final Trace trace = traceContext.currentTraceObject();
if (trace == null) {
return;
}
try {
final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
final HttpRequest httpRequest = getHttpRequest(args);
if (httpRequest != null) {
// Accessing httpRequest here not BEFORE() because it can cause side effect.
if (httpRequest.getRequestLine() != null) {
final String httpUrl = InterceptorUtils.getHttpUrl(httpRequest.getRequestLine().getUri(), param);
recorder.recordAttribute(AnnotationKey.HTTP_URL, httpUrl);
}
final NameIntValuePair<String> host = getHost();
if (host != null) {
final String endpoint = getEndpoint(host.getName(), host.getValue());
recorder.recordDestinationId(endpoint);
}
recordHttpRequest(trace, httpRequest, throwable);
}
if (statusCode) {
final Integer statusCodeValue = getStatusCode(result);
if (statusCodeValue != null) {
recorder.recordAttribute(AnnotationKey.HTTP_STATUS_CODE, statusCodeValue);
}
}
recorder.recordApi(methodDescriptor);
recorder.recordException(throwable);
final InterceptorScopeInvocation invocation = interceptorScope.getCurrentInvocation();
if (invocation != null && invocation.getAttachment() != null && invocation.getAttachment() instanceof HttpCallContext) {
final HttpCallContext callContext = (HttpCallContext) invocation.getAttachment();
logger.debug("Check call context {}", callContext);
if (io) {
final StringBuilder sb = new StringBuilder();
sb.append("write=").append(callContext.getWriteElapsedTime());
if (callContext.isWriteFail()) {
sb.append("(fail)");
}
sb.append(", read=").append(callContext.getReadElapsedTime());
if (callContext.isReadFail()) {
sb.append("(fail)");
}
recorder.recordAttribute(AnnotationKey.HTTP_IO, sb.toString());
}
// clear
invocation.removeAttachment();
}
} finally {
trace.traceBlockEnd();
}
}
use of com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation in project pinpoint by naver.
the class HttpRequestExecutorExecuteMethodInterceptor 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;
}
final HttpRequest httpRequest = getHttpRequest(args);
final boolean sampling = trace.canSampled();
if (!sampling) {
if (isDebug) {
logger.debug("set Sampling flag=false");
}
if (httpRequest != null) {
httpRequest.setHeader(Header.HTTP_SAMPLED.toString(), SamplingFlagUtils.SAMPLING_RATE_FALSE);
}
return;
}
final SpanEventRecorder recorder = trace.traceBlockBegin();
TraceId nextId = trace.getTraceId().getNextTraceId();
recorder.recordNextSpanId(nextId.getSpanId());
recorder.recordServiceType(HttpClient4Constants.HTTP_CLIENT_4);
if (httpRequest != null) {
httpRequest.setHeader(Header.HTTP_TRACE_ID.toString(), nextId.getTransactionId());
httpRequest.setHeader(Header.HTTP_SPAN_ID.toString(), String.valueOf(nextId.getSpanId()));
httpRequest.setHeader(Header.HTTP_PARENT_SPAN_ID.toString(), String.valueOf(nextId.getParentSpanId()));
httpRequest.setHeader(Header.HTTP_FLAGS.toString(), String.valueOf(nextId.getFlags()));
httpRequest.setHeader(Header.HTTP_PARENT_APPLICATION_NAME.toString(), traceContext.getApplicationName());
httpRequest.setHeader(Header.HTTP_PARENT_APPLICATION_TYPE.toString(), Short.toString(traceContext.getServerTypeCode()));
final NameIntValuePair<String> host = getHost();
if (host != null) {
final String endpoint = getEndpoint(host.getName(), host.getValue());
logger.debug("Get host {}", endpoint);
httpRequest.setHeader(Header.HTTP_HOST.toString(), endpoint);
}
}
InterceptorScopeInvocation invocation = interceptorScope.getCurrentInvocation();
if (invocation != null) {
invocation.getOrCreateAttachment(HttpCallContextFactory.HTTPCALL_CONTEXT_FACTORY);
}
}
Aggregations