use of com.navercorp.pinpoint.plugin.jdk.http.ConnectingGetter 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));
}
Aggregations