Search in sources :

Example 1 with ConnectedGetter

use of com.navercorp.pinpoint.plugin.jdk.http.ConnectedGetter in project pinpoint by naver.

the class HttpURLConnectionInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    Trace trace = traceContext.currentRawTraceObject();
    if (trace == null) {
        return;
    }
    final HttpURLConnection request = (HttpURLConnection) target;
    boolean connected = false;
    if (target instanceof ConnectedGetter) {
        connected = ((ConnectedGetter) target)._$PINPOINT$_isConnected();
    }
    boolean connecting = false;
    if (target instanceof ConnectingGetter) {
        connecting = ((ConnectingGetter) target)._$PINPOINT$_isConnecting();
    }
    if (connected || connecting) {
        return;
    }
    final boolean sampling = trace.canSampled();
    if (!sampling) {
        request.setRequestProperty(Header.HTTP_SAMPLED.toString(), SamplingFlagUtils.SAMPLING_RATE_FALSE);
        return;
    }
    scope.getCurrentInvocation().setAttachment(TRACE_BLOCK_BEGIN_MARKER);
    SpanEventRecorder recorder = trace.traceBlockBegin();
    TraceId nextId = trace.getTraceId().getNextTraceId();
    recorder.recordNextSpanId(nextId.getSpanId());
    final URL url = request.getURL();
    final String host = url.getHost();
    final int port = url.getPort();
    // TODO How to represent protocol?
    String endpoint = getEndpoint(host, port);
    request.setRequestProperty(Header.HTTP_TRACE_ID.toString(), nextId.getTransactionId());
    request.setRequestProperty(Header.HTTP_SPAN_ID.toString(), String.valueOf(nextId.getSpanId()));
    request.setRequestProperty(Header.HTTP_PARENT_SPAN_ID.toString(), String.valueOf(nextId.getParentSpanId()));
    request.setRequestProperty(Header.HTTP_FLAGS.toString(), String.valueOf(nextId.getFlags()));
    request.setRequestProperty(Header.HTTP_PARENT_APPLICATION_NAME.toString(), traceContext.getApplicationName());
    request.setRequestProperty(Header.HTTP_PARENT_APPLICATION_TYPE.toString(), Short.toString(traceContext.getServerTypeCode()));
    if (host != null) {
        request.setRequestProperty(Header.HTTP_HOST.toString(), endpoint);
    }
    recorder.recordServiceType(JdkHttpConstants.SERVICE_TYPE);
    // Don't record end point because it's same with destination id.
    recorder.recordDestinationId(endpoint);
    recorder.recordAttribute(AnnotationKey.HTTP_URL, InterceptorUtils.getHttpUrl(url.toString(), param));
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) HttpURLConnection(java.net.HttpURLConnection) ConnectedGetter(com.navercorp.pinpoint.plugin.jdk.http.ConnectedGetter) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) ConnectingGetter(com.navercorp.pinpoint.plugin.jdk.http.ConnectingGetter) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId) URL(java.net.URL)

Aggregations

SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)1 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)1 TraceId (com.navercorp.pinpoint.bootstrap.context.TraceId)1 ConnectedGetter (com.navercorp.pinpoint.plugin.jdk.http.ConnectedGetter)1 ConnectingGetter (com.navercorp.pinpoint.plugin.jdk.http.ConnectingGetter)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1