mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-20 18:25:55 +10:00
[강운덕] [LUCYSUS-1744] sampling 율에 따라 connector가 sampling flag를 전달하도록 수정
git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@1525 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
+18
-10
@@ -6,6 +6,7 @@ import com.profiler.logging.Logger;
|
||||
import com.profiler.context.*;
|
||||
import com.profiler.interceptor.TraceContextSupport;
|
||||
import com.profiler.logging.LoggerFactory;
|
||||
import com.profiler.sampler.util.SamplingFlagUtils;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
|
||||
@@ -14,7 +15,6 @@ import com.profiler.common.ServiceType;
|
||||
import com.profiler.interceptor.ByteCodeMethodDescriptorSupport;
|
||||
import com.profiler.interceptor.MethodDescriptor;
|
||||
import com.profiler.interceptor.StaticAroundInterceptor;
|
||||
import com.profiler.logging.LoggingUtils;
|
||||
|
||||
/**
|
||||
* Method interceptor
|
||||
@@ -39,10 +39,22 @@ public class Execute2MethodInterceptor implements StaticAroundInterceptor, ByteC
|
||||
if (isDebug) {
|
||||
logger.beforeInterceptor(target, className, methodName, parameterDescription, args);
|
||||
}
|
||||
Trace trace = traceContext.currentTraceObject();
|
||||
if (trace == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Trace trace = traceContext.currentRawTraceObject();
|
||||
if (trace == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final HttpUriRequest request = (HttpUriRequest) args[0];
|
||||
// UUID format을 그대로.
|
||||
final boolean sampling = trace.canSampled();
|
||||
if (!sampling) {
|
||||
if(isDebug) {
|
||||
logger.debug("set Samplingflag= ");
|
||||
}
|
||||
request.addHeader(Header.HTTP_SAMPLED.toString(), SamplingFlagUtils.SAMPLING_RATE_FALSE);
|
||||
return;
|
||||
}
|
||||
|
||||
trace.traceBlockBegin();
|
||||
trace.markBeforeTime();
|
||||
@@ -50,14 +62,10 @@ public class Execute2MethodInterceptor implements StaticAroundInterceptor, ByteC
|
||||
TraceID nextId = trace.getTraceId().getNextTraceId();
|
||||
trace.recordNextSpanId(nextId.getSpanId());
|
||||
|
||||
|
||||
final HttpUriRequest request = (HttpUriRequest) args[0];
|
||||
// UUID format을 그대로.
|
||||
|
||||
request.addHeader(Header.HTTP_TRACE_ID.toString(), nextId.getId().toString());
|
||||
request.addHeader(Header.HTTP_SPAN_ID.toString(), Integer.toString(nextId.getSpanId()));
|
||||
request.addHeader(Header.HTTP_PARENT_SPAN_ID.toString(), Integer.toString(nextId.getParentSpanId()));
|
||||
request.addHeader(Header.HTTP_SAMPLED.toString(), String.valueOf(nextId.isSampled()));
|
||||
|
||||
request.addHeader(Header.HTTP_FLAGS.toString(), String.valueOf(nextId.getFlags()));
|
||||
request.addHeader(Header.HTTP_PARENT_APPLICATION_NAME.toString(), traceContext.getApplicationId());
|
||||
request.addHeader(Header.HTTP_PARENT_APPLICATION_TYPE.toString(), String.valueOf(ServiceType.TOMCAT.getCode()));
|
||||
|
||||
+18
-10
@@ -6,6 +6,7 @@ import com.profiler.common.AnnotationKey;
|
||||
import com.profiler.context.*;
|
||||
import com.profiler.interceptor.TraceContextSupport;
|
||||
import com.profiler.logging.LoggerFactory;
|
||||
import com.profiler.sampler.util.SamplingFlagUtils;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
|
||||
@@ -13,7 +14,6 @@ import com.profiler.common.ServiceType;
|
||||
import com.profiler.interceptor.ByteCodeMethodDescriptorSupport;
|
||||
import com.profiler.interceptor.MethodDescriptor;
|
||||
import com.profiler.interceptor.StaticAroundInterceptor;
|
||||
import com.profiler.logging.LoggingUtils;
|
||||
|
||||
/**
|
||||
* Method interceptor
|
||||
@@ -42,33 +42,42 @@ public class ExecuteMethodInterceptor implements StaticAroundInterceptor, ByteCo
|
||||
if (isDebug) {
|
||||
logger.beforeInterceptor(target, className, methodName, parameterDescription, args);
|
||||
}
|
||||
Trace trace = traceContext.currentTraceObject();
|
||||
Trace trace = traceContext.currentRawTraceObject();
|
||||
if (trace == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final HttpRequest request = (HttpRequest) args[1];
|
||||
final boolean sampling = trace.canSampled();
|
||||
if (!sampling) {
|
||||
request.addHeader(Header.HTTP_SAMPLED.toString(), SamplingFlagUtils.SAMPLING_RATE_FALSE);
|
||||
return;
|
||||
}
|
||||
|
||||
trace.traceBlockBegin();
|
||||
trace.markBeforeTime();
|
||||
|
||||
TraceID nextId = trace.getTraceId().getNextTraceId();
|
||||
trace.recordNextSpanId(nextId.getSpanId());
|
||||
|
||||
|
||||
final HttpHost host = (HttpHost) args[0];
|
||||
final HttpRequest request = (HttpRequest) args[1];
|
||||
|
||||
// UUID format을 그대로.
|
||||
request.addHeader(Header.HTTP_TRACE_ID.toString(), nextId.getId().toString());
|
||||
request.addHeader(Header.HTTP_SPAN_ID.toString(), Integer.toString(nextId.getSpanId()));
|
||||
request.addHeader(Header.HTTP_PARENT_SPAN_ID.toString(), Integer.toString(nextId.getParentSpanId()));
|
||||
request.addHeader(Header.HTTP_SAMPLED.toString(), String.valueOf(nextId.isSampled()));
|
||||
|
||||
request.addHeader(Header.HTTP_FLAGS.toString(), String.valueOf(nextId.getFlags()));
|
||||
request.addHeader(Header.HTTP_PARENT_APPLICATION_NAME.toString(), traceContext.getApplicationId());
|
||||
request.addHeader(Header.HTTP_PARENT_APPLICATION_TYPE.toString(), String.valueOf(ServiceType.TOMCAT.getCode()));
|
||||
request.addHeader(Header.HTTP_PARENT_APPLICATION_NAME.toString(), traceContext.getApplicationId());
|
||||
request.addHeader(Header.HTTP_PARENT_APPLICATION_TYPE.toString(), String.valueOf(ServiceType.TOMCAT.getCode()));
|
||||
|
||||
trace.recordServiceType(ServiceType.HTTP_CLIENT);
|
||||
|
||||
int port = host.getPort();
|
||||
int port = host.getPort();
|
||||
trace.recordDestinationId(host.getHostName() + ((port > 0) ? ":" + port : ""));
|
||||
|
||||
trace.recordAttribute(AnnotationKey.HTTP_URL, request.getRequestLine().getUri());
|
||||
trace.recordAttribute(AnnotationKey.HTTP_URL, request.getRequestLine().getUri());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -83,7 +92,6 @@ public class ExecuteMethodInterceptor implements StaticAroundInterceptor, ByteCo
|
||||
return;
|
||||
}
|
||||
trace.recordApi(descriptor);
|
||||
// trace.recordApi(this.apiId);
|
||||
trace.recordException(result);
|
||||
|
||||
trace.markAfterTime();
|
||||
|
||||
+16
-8
@@ -11,7 +11,7 @@ import com.profiler.interceptor.MethodDescriptor;
|
||||
import com.profiler.interceptor.StaticAroundInterceptor;
|
||||
import com.profiler.interceptor.TraceContextSupport;
|
||||
import com.profiler.logging.LoggerFactory;
|
||||
import com.profiler.logging.LoggingUtils;
|
||||
import com.profiler.sampler.util.SamplingFlagUtils;
|
||||
|
||||
/**
|
||||
* @author netspider
|
||||
@@ -30,23 +30,31 @@ public class ConnectMethodInterceptor implements StaticAroundInterceptor, ByteCo
|
||||
if (isDebug) {
|
||||
logger.beforeInterceptor(target, className, methodName, parameterDescription, args);
|
||||
}
|
||||
Trace trace = traceContext.currentTraceObject();
|
||||
if (trace == null) {
|
||||
return;
|
||||
}
|
||||
Trace trace = traceContext.currentRawTraceObject();
|
||||
if (trace == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
HttpURLConnection request = (HttpURLConnection) target;
|
||||
// UUID format을 그대로.
|
||||
final boolean sampling = trace.canSampled();
|
||||
if (!sampling) {
|
||||
request.addRequestProperty(Header.HTTP_SAMPLED.toString(), SamplingFlagUtils.SAMPLING_RATE_FALSE);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
trace.traceBlockBegin();
|
||||
trace.markBeforeTime();
|
||||
|
||||
TraceID nextId = trace.getTraceId().getNextTraceId();
|
||||
trace.recordNextSpanId(nextId.getSpanId());
|
||||
|
||||
HttpURLConnection request = (HttpURLConnection) target;
|
||||
|
||||
// UUID format을 그대로.
|
||||
request.setRequestProperty(Header.HTTP_TRACE_ID.toString(), nextId.getId().toString());
|
||||
request.setRequestProperty(Header.HTTP_SPAN_ID.toString(), Integer.toString(nextId.getSpanId()));
|
||||
request.setRequestProperty(Header.HTTP_PARENT_SPAN_ID.toString(), Integer.toString(nextId.getParentSpanId()));
|
||||
request.setRequestProperty(Header.HTTP_SAMPLED.toString(), String.valueOf(nextId.isSampled()));
|
||||
|
||||
request.setRequestProperty(Header.HTTP_FLAGS.toString(), String.valueOf(nextId.getFlags()));
|
||||
request.setRequestProperty(Header.HTTP_PARENT_APPLICATION_NAME.toString(), traceContext.getApplicationId());
|
||||
request.setRequestProperty(Header.HTTP_PARENT_APPLICATION_TYPE.toString(), String.valueOf(ServiceType.TOMCAT.getCode()));
|
||||
|
||||
Reference in New Issue
Block a user