use of com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation in project pinpoint by naver.
the class HttpEngineSendRequestMethodInterceptor 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;
}
if (!validate(target)) {
return;
}
try {
SpanEventRecorder recorder = trace.currentSpanEventRecorder();
recorder.recordApi(methodDescriptor);
recorder.recordException(throwable);
// typeCheck validate();
Request request = ((UserRequestGetter) target)._$PINPOINT$_getUserRequest();
if (request != null) {
try {
recorder.recordAttribute(AnnotationKey.HTTP_URL, InterceptorUtils.getHttpUrl(request.urlString(), param));
final String endpoint = getDestinationId(request.url());
recorder.recordDestinationId(endpoint);
} catch (Exception ignored) {
logger.warn("Failed to invoke of request.url(). {}", ignored.getMessage());
}
recordRequest(trace, request, throwable);
}
// clear attachment.
InterceptorScopeInvocation invocation = interceptorScope.getCurrentInvocation();
if (invocation != null && invocation.getAttachment() != null) {
invocation.removeAttachment();
}
} finally {
trace.traceBlockEnd();
}
}
use of com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation in project pinpoint by naver.
the class RequestBuilderBuildMethodBackwardCompatibilityInterceptor 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;
}
try {
if (!(target instanceof Request.Builder)) {
return;
}
final Request.Builder builder = ((Request.Builder) target);
if (!trace.canSampled()) {
if (isDebug) {
logger.debug("set Sampling flag=false");
}
((Request.Builder) target).header(Header.HTTP_SAMPLED.toString(), SamplingFlagUtils.SAMPLING_RATE_FALSE);
return;
}
final InterceptorScopeInvocation invocation = interceptorScope.getCurrentInvocation();
if (invocation == null || invocation.getAttachment() == null || !(invocation.getAttachment() instanceof TraceId)) {
logger.debug("Invalid interceptor scope invocation. {}", invocation);
return;
}
final TraceId nextId = (TraceId) invocation.getAttachment();
builder.header(Header.HTTP_TRACE_ID.toString(), nextId.getTransactionId());
builder.header(Header.HTTP_SPAN_ID.toString(), String.valueOf(nextId.getSpanId()));
builder.header(Header.HTTP_PARENT_SPAN_ID.toString(), String.valueOf(nextId.getParentSpanId()));
builder.header(Header.HTTP_FLAGS.toString(), String.valueOf(nextId.getFlags()));
builder.header(Header.HTTP_PARENT_APPLICATION_NAME.toString(), traceContext.getApplicationName());
builder.header(Header.HTTP_PARENT_APPLICATION_TYPE.toString(), Short.toString(traceContext.getServerTypeCode()));
if (target instanceof UrlGetter) {
final URL url = ((UrlGetter) target)._$PINPOINT$_getUrl();
if (url != null) {
final String endpoint = getDestinationId(url);
logger.debug("Set HTTP_HOST {}", endpoint);
builder.header(Header.HTTP_HOST.toString(), endpoint);
}
}
} 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 RequestBuilderBuildMethodInterceptor 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;
}
try {
if (!(target instanceof Request.Builder)) {
return;
}
final Request.Builder builder = ((Request.Builder) target);
if (!trace.canSampled()) {
if (isDebug) {
logger.debug("set Sampling flag=false");
}
((Request.Builder) target).header(Header.HTTP_SAMPLED.toString(), SamplingFlagUtils.SAMPLING_RATE_FALSE);
return;
}
final InterceptorScopeInvocation invocation = interceptorScope.getCurrentInvocation();
if (invocation == null || invocation.getAttachment() == null || !(invocation.getAttachment() instanceof TraceId)) {
logger.debug("Invalid interceptor scope invocation. {}", invocation);
return;
}
final TraceId nextId = (TraceId) invocation.getAttachment();
builder.header(Header.HTTP_TRACE_ID.toString(), nextId.getTransactionId());
builder.header(Header.HTTP_SPAN_ID.toString(), String.valueOf(nextId.getSpanId()));
builder.header(Header.HTTP_PARENT_SPAN_ID.toString(), String.valueOf(nextId.getParentSpanId()));
builder.header(Header.HTTP_FLAGS.toString(), String.valueOf(nextId.getFlags()));
builder.header(Header.HTTP_PARENT_APPLICATION_NAME.toString(), traceContext.getApplicationName());
builder.header(Header.HTTP_PARENT_APPLICATION_TYPE.toString(), Short.toString(traceContext.getServerTypeCode()));
if (target instanceof HttpUrlGetter) {
final HttpUrl url = ((HttpUrlGetter) target)._$PINPOINT$_getHttpUrl();
if (url != null) {
final String endpoint = getDestinationId(url);
logger.debug("Set HTTP_HOST {}", endpoint);
builder.header(Header.HTTP_HOST.toString(), endpoint);
}
}
} 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 TBaseProcessorProcessInterceptor method getMethodUri.
private String getMethodUri(Object target) {
String methodUri = ThriftConstants.UNKNOWN_METHOD_URI;
InterceptorScopeInvocation currentTransaction = this.scope.getCurrentInvocation();
Object attachment = currentTransaction.getAttachment();
if (attachment instanceof ThriftClientCallContext && target instanceof TBaseProcessor) {
ThriftClientCallContext clientCallContext = (ThriftClientCallContext) attachment;
String methodName = clientCallContext.getMethodName();
methodUri = ThriftUtils.getProcessorNameAsUri((TBaseProcessor<?>) target);
StringBuilder sb = new StringBuilder(methodUri);
if (!methodUri.endsWith("/")) {
sb.append("/");
}
sb.append(methodName);
methodUri = sb.toString();
}
return methodUri;
}
use of com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation in project pinpoint by naver.
the class TProtocolWriteFieldStopInterceptor method appendParentTraceInfo.
private void appendParentTraceInfo(TProtocol oprot) throws TException {
InterceptorScopeInvocation currentTransaction = this.scope.getCurrentInvocation();
ThriftRequestProperty parentTraceInfo = (ThriftRequestProperty) currentTransaction.getAttachment();
if (parentTraceInfo == null) {
return;
}
boolean shouldSample = parentTraceInfo.shouldSample(true);
if (!shouldSample) {
parentTraceInfo.writeTraceHeader(ThriftHeader.THRFIT_SAMPLED, oprot);
return;
}
parentTraceInfo.writeTraceHeader(ThriftHeader.THRIFT_TRACE_ID, oprot);
parentTraceInfo.writeTraceHeader(ThriftHeader.THRIFT_SPAN_ID, oprot);
parentTraceInfo.writeTraceHeader(ThriftHeader.THRIFT_PARENT_SPAN_ID, oprot);
parentTraceInfo.writeTraceHeader(ThriftHeader.THRIFT_FLAGS, oprot);
parentTraceInfo.writeTraceHeader(ThriftHeader.THRIFT_PARENT_APPLICATION_NAME, oprot);
parentTraceInfo.writeTraceHeader(ThriftHeader.THRIFT_PARENT_APPLICATION_TYPE, oprot);
parentTraceInfo.writeTraceHeader(ThriftHeader.THRIFT_HOST, oprot);
}
Aggregations