Search in sources :

Example 61 with SpanEventRecorder

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();
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId)

Example 62 with SpanEventRecorder

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");
    }
}
Also used : URIException(org.apache.commons.httpclient.URIException) HttpConnection(org.apache.commons.httpclient.HttpConnection) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) Protocol(org.apache.commons.httpclient.protocol.Protocol) URI(org.apache.commons.httpclient.URI)

Example 63 with SpanEventRecorder

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();
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)

Example 64 with SpanEventRecorder

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);
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)

Example 65 with SpanEventRecorder

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);
        }
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) FluentCaseInsensitiveStringsMap(com.ning.http.client.FluentCaseInsensitiveStringsMap) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId)

Aggregations

SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)86 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)75 AsyncTraceId (com.navercorp.pinpoint.bootstrap.context.AsyncTraceId)12 TraceId (com.navercorp.pinpoint.bootstrap.context.TraceId)9 AsyncTraceIdAccessor (com.navercorp.pinpoint.bootstrap.async.AsyncTraceIdAccessor)8 InterceptorScopeInvocation (com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation)8 DatabaseInfoAccessor (com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor)5 DatabaseInfo (com.navercorp.pinpoint.bootstrap.context.DatabaseInfo)4 Socket (java.net.Socket)3 HttpRequest (org.apache.http.HttpRequest)3 Test (org.junit.Test)3 MethodDescriptor (com.navercorp.pinpoint.bootstrap.context.MethodDescriptor)2 ParsingResult (com.navercorp.pinpoint.bootstrap.context.ParsingResult)2 SpanRecorder (com.navercorp.pinpoint.bootstrap.context.SpanRecorder)2 TraceContext (com.navercorp.pinpoint.bootstrap.context.TraceContext)2 BindValueAccessor (com.navercorp.pinpoint.bootstrap.plugin.jdbc.BindValueAccessor)2 DefaultDatabaseInfo (com.navercorp.pinpoint.bootstrap.plugin.jdbc.DefaultDatabaseInfo)2 JdbcUrlParser (com.navercorp.pinpoint.bootstrap.plugin.jdbc.JdbcUrlParser)2 ParsingResultAccessor (com.navercorp.pinpoint.bootstrap.plugin.jdbc.ParsingResultAccessor)2 UnKnownDatabaseInfo (com.navercorp.pinpoint.bootstrap.plugin.jdbc.UnKnownDatabaseInfo)2