use of com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder 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();
}
use of com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder in project pinpoint by naver.
the class HttpMethodBaseExecuteMethodInterceptor method recordDestination.
private void recordDestination(final Trace trace, final HttpMethod httpMethod, final Object[] args) {
final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
try {
final URI uri = httpMethod.getURI();
final HttpConnection httpConnection = getHttpConnection(args);
// if uri have schema or not found HttpConnection argument.
if (uri.isAbsoluteURI() || httpConnection == null) {
recorder.recordAttribute(AnnotationKey.HTTP_URL, InterceptorUtils.getHttpUrl(uri.getURI(), param));
recorder.recordDestinationId(getEndpoint(uri.getHost(), uri.getPort()));
return;
}
if (isDebug) {
logger.debug("URI is not absolute. {}", uri.getURI());
}
// use HttpConnection argument.
final String host = httpConnection.getHost();
int port = httpConnection.getPort();
final StringBuilder httpUrl = new StringBuilder();
final Protocol protocol = httpConnection.getProtocol();
if (protocol != null) {
httpUrl.append(protocol.getScheme()).append("://");
httpUrl.append(httpConnection.getHost());
// if port is default port number.
if (httpConnection.getPort() == protocol.getDefaultPort()) {
port = -1;
} else {
httpUrl.append(":").append(port);
}
}
httpUrl.append(uri.getURI());
recorder.recordAttribute(AnnotationKey.HTTP_URL, InterceptorUtils.getHttpUrl(httpUrl.toString(), param));
recorder.recordDestinationId(getEndpoint(host, port));
} catch (URIException e) {
logger.error("Fail get URI", e);
recorder.recordDestinationId("unknown");
}
}
use of com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder in project pinpoint by naver.
the class RetryMethodInterceptor method after.
@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
if (isDebug) {
logger.afterInterceptor(target, args);
}
Trace trace = traceContext.currentTraceObject();
if (trace == null) {
return;
}
try {
final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
recorder.recordApi(descriptor);
recorder.recordException(throwable);
final StringBuilder sb = new StringBuilder();
if (args != null && args.length >= 2 && args[1] != null && args[1] instanceof Exception) {
sb.append(args[1].getClass().getName()).append(", ");
}
if (args != null && args.length >= 3 && args[2] != null && args[2] instanceof Integer) {
sb.append(args[2]);
}
recorder.recordAttribute(AnnotationKey.HTTP_INTERNAL_DISPLAY, sb.toString());
if (result != null) {
recorder.recordAttribute(AnnotationKey.RETURN_DATA, result);
}
} finally {
trace.traceBlockEnd();
}
}
use of com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder in project pinpoint by naver.
the class RetryMethodInterceptor method before.
@Override
public void before(Object target, Object[] args) {
if (isDebug) {
logger.beforeInterceptor(target, args);
}
Trace trace = traceContext.currentTraceObject();
if (trace == null) {
return;
}
final SpanEventRecorder recorder = trace.traceBlockBegin();
recorder.recordServiceType(HttpClient3Constants.HTTP_CLIENT_3_INTERNAL);
}
use of com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder in project pinpoint by naver.
the class ExecuteRequestInterceptor 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 (args.length == 0 || !(args[0] instanceof com.ning.http.client.Request)) {
return;
}
final com.ning.http.client.Request httpRequest = (com.ning.http.client.Request) args[0];
final boolean sampling = trace.canSampled();
if (!sampling) {
if (isDebug) {
logger.debug("set Sampling flag=false");
}
if (httpRequest != null) {
final FluentCaseInsensitiveStringsMap httpRequestHeaders = httpRequest.getHeaders();
httpRequestHeaders.add(Header.HTTP_SAMPLED.toString(), SamplingFlagUtils.SAMPLING_RATE_FALSE);
}
return;
}
trace.traceBlockBegin();
SpanEventRecorder recorder = trace.currentSpanEventRecorder();
TraceId nextId = trace.getTraceId().getNextTraceId();
recorder.recordNextSpanId(nextId.getSpanId());
recorder.recordServiceType(NingAsyncHttpClientPlugin.ASYNC_HTTP_CLIENT);
if (httpRequest != null) {
final FluentCaseInsensitiveStringsMap httpRequestHeaders = httpRequest.getHeaders();
putHeader(httpRequestHeaders, Header.HTTP_TRACE_ID.toString(), nextId.getTransactionId());
putHeader(httpRequestHeaders, Header.HTTP_SPAN_ID.toString(), String.valueOf(nextId.getSpanId()));
putHeader(httpRequestHeaders, Header.HTTP_PARENT_SPAN_ID.toString(), String.valueOf(nextId.getParentSpanId()));
putHeader(httpRequestHeaders, Header.HTTP_FLAGS.toString(), String.valueOf(nextId.getFlags()));
putHeader(httpRequestHeaders, Header.HTTP_PARENT_APPLICATION_NAME.toString(), traceContext.getApplicationName());
putHeader(httpRequestHeaders, Header.HTTP_PARENT_APPLICATION_TYPE.toString(), Short.toString(traceContext.getServerTypeCode()));
final String hostString = getEndpoint(httpRequest.getURI().getHost(), httpRequest.getURI().getPort());
if (hostString != null) {
putHeader(httpRequestHeaders, Header.HTTP_HOST.toString(), hostString);
}
}
}
Aggregations