|
|
|
@@ -47,56 +47,56 @@ import org.eclipse.jetty.server.HttpChannel;
|
|
|
|
|
@TargetMethod(name = "handle", paramTypes = { "org.eclipse.jetty.server.HttpChannel" })
|
|
|
|
|
public class ServerHandleInterceptor implements SimpleAroundInterceptor, JettyConstants{
|
|
|
|
|
|
|
|
|
|
public static final JettySyncMethodDescriptor JETTY_SYNC_API_TAG = new JettySyncMethodDescriptor();
|
|
|
|
|
public static final JettySyncMethodDescriptor JETTY_SYNC_API_TAG = new JettySyncMethodDescriptor();
|
|
|
|
|
|
|
|
|
|
private PLogger logger = PLoggerFactory.getLogger(this.getClass());
|
|
|
|
|
private final boolean isDebug = logger.isDebugEnabled();
|
|
|
|
|
private final boolean isTrace = logger.isTraceEnabled();
|
|
|
|
|
private PLogger logger = PLoggerFactory.getLogger(this.getClass());
|
|
|
|
|
private final boolean isDebug = logger.isDebugEnabled();
|
|
|
|
|
private final boolean isTrace = logger.isTraceEnabled();
|
|
|
|
|
|
|
|
|
|
private MethodDescriptor methodDescriptor;
|
|
|
|
|
private TraceContext traceContext;
|
|
|
|
|
private Filter<String> excludeUrlFilter;
|
|
|
|
|
private MetadataAccessor traceAccessor;
|
|
|
|
|
private final MethodDescriptor methodDescriptor;
|
|
|
|
|
private final TraceContext traceContext;
|
|
|
|
|
private final Filter<String> excludeUrlFilter;
|
|
|
|
|
private final MetadataAccessor traceAccessor;
|
|
|
|
|
|
|
|
|
|
public ServerHandleInterceptor(TraceContext traceContext, MethodDescriptor descriptor, Filter<String> excludeFilter, @Name(METADATA_TRACE) MetadataAccessor traceAccessor) {
|
|
|
|
|
public ServerHandleInterceptor(TraceContext traceContext, MethodDescriptor descriptor, Filter<String> excludeFilter, @Name(METADATA_TRACE) MetadataAccessor traceAccessor) {
|
|
|
|
|
|
|
|
|
|
this.traceContext = traceContext;
|
|
|
|
|
this.methodDescriptor = descriptor;
|
|
|
|
|
this.traceContext = traceContext;
|
|
|
|
|
this.methodDescriptor = descriptor;
|
|
|
|
|
this.excludeUrlFilter = excludeFilter;
|
|
|
|
|
this.traceAccessor = traceAccessor;
|
|
|
|
|
this.traceAccessor = traceAccessor;
|
|
|
|
|
|
|
|
|
|
traceContext.cacheApi(JETTY_SYNC_API_TAG);
|
|
|
|
|
}
|
|
|
|
|
traceContext.cacheApi(JETTY_SYNC_API_TAG);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void before(Object target, Object[] args) {
|
|
|
|
|
if (isDebug) {
|
|
|
|
|
logger.beforeInterceptor(target, args);
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public void before(Object target, Object[] args) {
|
|
|
|
|
if (isDebug) {
|
|
|
|
|
logger.beforeInterceptor(target, args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
final Trace trace = createTrace(target, args);
|
|
|
|
|
if (trace == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// TODO STATDISABLE this logic was added to disable statistics tracing
|
|
|
|
|
if (!trace.canSampled()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// ------------------------------------------------------
|
|
|
|
|
SpanEventRecorder recorder = trace.traceBlockBegin();
|
|
|
|
|
recorder.recordServiceType(JETTY_METHOD);
|
|
|
|
|
} catch (Throwable th) {
|
|
|
|
|
if (logger.isWarnEnabled()) {
|
|
|
|
|
logger.warn("before. Caused:{}", th.getMessage(), th);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
final Trace trace = createTrace(target, args);
|
|
|
|
|
if (trace == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// TODO STATDISABLE this logic was added to disable statistics tracing
|
|
|
|
|
if (!trace.canSampled()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// ------------------------------------------------------
|
|
|
|
|
SpanEventRecorder recorder = trace.traceBlockBegin();
|
|
|
|
|
recorder.recordServiceType(JETTY_METHOD);
|
|
|
|
|
} catch (Throwable th) {
|
|
|
|
|
if (logger.isWarnEnabled()) {
|
|
|
|
|
logger.warn("before. Caused:{}", th.getMessage(), th);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Trace createTrace(Object target, Object[] args) {
|
|
|
|
|
final HttpChannel<?> channel = (HttpChannel<?>) args[0];
|
|
|
|
|
final HttpServletRequest request = (HttpServletRequest) channel.getRequest();
|
|
|
|
|
private Trace createTrace(Object target, Object[] args) {
|
|
|
|
|
final HttpChannel<?> channel = (HttpChannel<?>) args[0];
|
|
|
|
|
final HttpServletRequest request = (HttpServletRequest) channel.getRequest();
|
|
|
|
|
|
|
|
|
|
final String requestURI = request.getRequestURI();
|
|
|
|
|
if (excludeUrlFilter.filter(requestURI)) {
|
|
|
|
@@ -105,21 +105,21 @@ public class ServerHandleInterceptor implements SimpleAroundInterceptor, JettyCo
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
// check sampling flag from client. If the flag is false, do not sample this request.
|
|
|
|
|
final boolean sampling = samplingEnable(request);
|
|
|
|
|
if (!sampling) {
|
|
|
|
|
// Even if this transaction is not a sampling target, we have to create Trace object to mark 'not sampling'.
|
|
|
|
|
// For example, if this transaction invokes rpc call, we can add parameter to tell remote node 'don't sample this transaction'
|
|
|
|
|
final Trace trace = traceContext.disableSampling();
|
|
|
|
|
if (isDebug) {
|
|
|
|
|
logger.debug("remotecall sampling flag found. skip trace requestUrl:{}, remoteAddr:{}", request.getRequestURI(), request.getRemoteAddr());
|
|
|
|
|
}
|
|
|
|
|
return trace;
|
|
|
|
|
}
|
|
|
|
|
// check sampling flag from client. If the flag is false, do not sample this request.
|
|
|
|
|
final boolean sampling = samplingEnable(request);
|
|
|
|
|
if (!sampling) {
|
|
|
|
|
// Even if this transaction is not a sampling target, we have to create Trace object to mark 'not sampling'.
|
|
|
|
|
// For example, if this transaction invokes rpc call, we can add parameter to tell remote node 'don't sample this transaction'
|
|
|
|
|
final Trace trace = traceContext.disableSampling();
|
|
|
|
|
if (isDebug) {
|
|
|
|
|
logger.debug("remotecall sampling flag found. skip trace requestUrl:{}, remoteAddr:{}", request.getRequestURI(), request.getRemoteAddr());
|
|
|
|
|
}
|
|
|
|
|
return trace;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final TraceId traceId = populateTraceIdFromRequest(request);
|
|
|
|
|
if (traceId != null) {
|
|
|
|
|
final Trace trace = traceContext.continueTraceObject(traceId);
|
|
|
|
|
final TraceId traceId = populateTraceIdFromRequest(request);
|
|
|
|
|
if (traceId != null) {
|
|
|
|
|
final Trace trace = traceContext.continueTraceObject(traceId);
|
|
|
|
|
if (trace.canSampled()) {
|
|
|
|
|
SpanRecorder recorder = trace.getSpanRecorder();
|
|
|
|
|
recordRootSpan(recorder, request);
|
|
|
|
@@ -133,8 +133,8 @@ public class ServerHandleInterceptor implements SimpleAroundInterceptor, JettyCo
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return trace;
|
|
|
|
|
} else {
|
|
|
|
|
final Trace trace = traceContext.newTraceObject();
|
|
|
|
|
} else {
|
|
|
|
|
final Trace trace = traceContext.newTraceObject();
|
|
|
|
|
if (trace.canSampled()) {
|
|
|
|
|
SpanRecorder recorder = trace.getSpanRecorder();
|
|
|
|
|
recordRootSpan(recorder, request);
|
|
|
|
@@ -148,200 +148,148 @@ public class ServerHandleInterceptor implements SimpleAroundInterceptor, JettyCo
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return trace;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void after(Object target, Object[] args, Object result, Throwable throwable) {
|
|
|
|
|
@Override
|
|
|
|
|
public void after(Object target, Object[] args, Object result, Throwable throwable) {
|
|
|
|
|
if (isDebug) {
|
|
|
|
|
logger.afterInterceptor(target, args, result, throwable);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final Trace trace = traceContext.currentRawTraceObject();
|
|
|
|
|
if (trace == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
final Trace trace = traceContext.currentRawTraceObject();
|
|
|
|
|
if (trace == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// TODO STATDISABLE this logic was added to disable statistics tracing
|
|
|
|
|
if (!trace.canSampled()) {
|
|
|
|
|
traceContext.removeTraceObject();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// ------------------------------------------------------
|
|
|
|
|
try {
|
|
|
|
|
SpanEventRecorder recorder = trace.currentSpanEventRecorder();
|
|
|
|
|
final HttpChannel<?> channel = (HttpChannel<?>) args[0];
|
|
|
|
|
final HttpServletRequest request = (HttpServletRequest) channel.getRequest();
|
|
|
|
|
final String parameters = getRequestParameter(request, 64, 512);
|
|
|
|
|
if (parameters != null && parameters.length() > 0) {
|
|
|
|
|
recorder.recordAttribute(AnnotationKey.HTTP_PARAM, parameters);
|
|
|
|
|
}
|
|
|
|
|
// ------------------------------------------------------
|
|
|
|
|
try {
|
|
|
|
|
SpanEventRecorder recorder = trace.currentSpanEventRecorder();
|
|
|
|
|
final HttpChannel<?> channel = (HttpChannel<?>) args[0];
|
|
|
|
|
final HttpServletRequest request = (HttpServletRequest) channel.getRequest();
|
|
|
|
|
final String parameters = getRequestParameter(request, 64, 512);
|
|
|
|
|
if (parameters != null && parameters.length() > 0) {
|
|
|
|
|
recorder.recordAttribute(AnnotationKey.HTTP_PARAM, parameters);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
recorder.recordApi(methodDescriptor);
|
|
|
|
|
recorder.recordException(throwable);
|
|
|
|
|
} catch (Throwable th) {
|
|
|
|
|
if (logger.isWarnEnabled()) {
|
|
|
|
|
logger.warn("after. Caused:{}", th.getMessage(), th);
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
traceContext.removeTraceObject();
|
|
|
|
|
deleteTrace(trace, target, args, result, throwable);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean samplingEnable(HttpServletRequest request) {
|
|
|
|
|
// optional value
|
|
|
|
|
final String samplingFlag = request.getHeader(Header.HTTP_SAMPLED.toString());
|
|
|
|
|
if (isDebug) {
|
|
|
|
|
logger.debug("SamplingFlag:{}", samplingFlag);
|
|
|
|
|
}
|
|
|
|
|
return SamplingFlagUtils.isSamplingFlag(samplingFlag);
|
|
|
|
|
}
|
|
|
|
|
recorder.recordApi(methodDescriptor);
|
|
|
|
|
recorder.recordException(throwable);
|
|
|
|
|
} catch (Throwable th) {
|
|
|
|
|
if (logger.isWarnEnabled()) {
|
|
|
|
|
logger.warn("after. Caused:{}", th.getMessage(), th);
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
traceContext.removeTraceObject();
|
|
|
|
|
deleteTrace(trace, target, args, result, throwable);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setTraceMetadata(final HttpServletRequest request, final Trace trace) {
|
|
|
|
|
if(traceAccessor.isApplicable(request)) {
|
|
|
|
|
traceAccessor.set(request, trace);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private boolean samplingEnable(HttpServletRequest request) {
|
|
|
|
|
// optional value
|
|
|
|
|
final String samplingFlag = request.getHeader(Header.HTTP_SAMPLED.toString());
|
|
|
|
|
if (isDebug) {
|
|
|
|
|
logger.debug("SamplingFlag:{}", samplingFlag);
|
|
|
|
|
}
|
|
|
|
|
return SamplingFlagUtils.isSamplingFlag(samplingFlag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Override
|
|
|
|
|
// protected void doInAfterTrace(RecordableTrace trace, Object target, Object[] args, Object result, Throwable throwable) {
|
|
|
|
|
// final HttpChannel<?> channel = (HttpChannel<?>) args[0];
|
|
|
|
|
// final HttpServletRequest request = (HttpServletRequest) channel.getRequest();
|
|
|
|
|
// final String parameters = getRequestParameter(request, 64, 512);
|
|
|
|
|
// if (parameters != null && parameters.length() > 0) {
|
|
|
|
|
// trace.recordAttribute(AnnotationKey.HTTP_PARAM, parameters);
|
|
|
|
|
// }
|
|
|
|
|
// trace.recordApi(getMethodDescriptor());
|
|
|
|
|
// trace.recordException(throwable);
|
|
|
|
|
// trace.markAfterTime();
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
private void setTraceMetadata(final HttpServletRequest request, final Trace trace) {
|
|
|
|
|
if(traceAccessor.isApplicable(request)) {
|
|
|
|
|
traceAccessor.set(request, trace);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getRequestParameter(HttpServletRequest request, int eachLimit, int totalLimit) {
|
|
|
|
|
Enumeration<?> attrs = request.getParameterNames();
|
|
|
|
|
final StringBuilder params = new StringBuilder(64);
|
|
|
|
|
while (attrs.hasMoreElements()) {
|
|
|
|
|
if (params.length() != 0) {
|
|
|
|
|
params.append('&');
|
|
|
|
|
}
|
|
|
|
|
// skip appending parameters if parameter size is bigger than totalLimit
|
|
|
|
|
if (params.length() > totalLimit) {
|
|
|
|
|
params.append("...");
|
|
|
|
|
return params.toString();
|
|
|
|
|
}
|
|
|
|
|
String key = attrs.nextElement().toString();
|
|
|
|
|
params.append(StringUtils.drop(key, eachLimit));
|
|
|
|
|
params.append("=");
|
|
|
|
|
Object value = request.getParameter(key);
|
|
|
|
|
if (value != null) {
|
|
|
|
|
params.append(StringUtils.drop(StringUtils.toString(value), eachLimit));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return params.toString();
|
|
|
|
|
}
|
|
|
|
|
private String getRequestParameter(HttpServletRequest request, int eachLimit, int totalLimit) {
|
|
|
|
|
Enumeration<?> attrs = request.getParameterNames();
|
|
|
|
|
final StringBuilder params = new StringBuilder(64);
|
|
|
|
|
while (attrs.hasMoreElements()) {
|
|
|
|
|
if (params.length() != 0) {
|
|
|
|
|
params.append('&');
|
|
|
|
|
}
|
|
|
|
|
// skip appending parameters if parameter size is bigger than totalLimit
|
|
|
|
|
if (params.length() > totalLimit) {
|
|
|
|
|
params.append("...");
|
|
|
|
|
return params.toString();
|
|
|
|
|
}
|
|
|
|
|
String key = attrs.nextElement().toString();
|
|
|
|
|
params.append(StringUtils.drop(key, eachLimit));
|
|
|
|
|
params.append("=");
|
|
|
|
|
Object value = request.getParameter(key);
|
|
|
|
|
if (value != null) {
|
|
|
|
|
params.append(StringUtils.drop(StringUtils.toString(value), eachLimit));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return params.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// private void recordParentInfo(RecordableTrace trace, HttpServletRequest request) {
|
|
|
|
|
// String parentApplicationName = request.getHeader(Header.HTTP_PARENT_APPLICATION_NAME.toString());
|
|
|
|
|
// if (parentApplicationName != null) {
|
|
|
|
|
// final String host = request.getHeader(Header.HTTP_HOST.toString());
|
|
|
|
|
// if(host != null) {
|
|
|
|
|
// trace.recordAcceptorHost(host);
|
|
|
|
|
// } else {
|
|
|
|
|
// trace.recordAcceptorHost(NetworkUtils.getHostFromURL(request.getRequestURL().toString()));
|
|
|
|
|
// }
|
|
|
|
|
// final String type = request.getHeader(Header.HTTP_PARENT_APPLICATION_TYPE.toString());
|
|
|
|
|
// final short parentApplicationType = NumberUtils.parseShort(type, ServiceType.UNDEFINED.getCode());
|
|
|
|
|
// trace.recordParentApplication(parentApplicationName, parentApplicationType);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
private void recordParentInfo(SpanRecorder recorder, HttpServletRequest request) {
|
|
|
|
|
String parentApplicationName = request.getHeader(Header.HTTP_PARENT_APPLICATION_NAME.toString());
|
|
|
|
|
if (parentApplicationName != null) {
|
|
|
|
|
final String host = request.getHeader(Header.HTTP_HOST.toString());
|
|
|
|
|
if (host != null) {
|
|
|
|
|
recorder.recordAcceptorHost(host);
|
|
|
|
|
} else {
|
|
|
|
|
recorder.recordAcceptorHost(NetworkUtils.getHostFromURL(request.getRequestURL().toString()));
|
|
|
|
|
}
|
|
|
|
|
final String type = request.getHeader(Header.HTTP_PARENT_APPLICATION_TYPE.toString());
|
|
|
|
|
final short parentApplicationType = NumberUtils.parseShort(type, ServiceType.UNDEFINED.getCode());
|
|
|
|
|
recorder.recordParentApplication(parentApplicationName, parentApplicationType);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void recordParentInfo(SpanRecorder recorder, HttpServletRequest request) {
|
|
|
|
|
String parentApplicationName = request.getHeader(Header.HTTP_PARENT_APPLICATION_NAME.toString());
|
|
|
|
|
if (parentApplicationName != null) {
|
|
|
|
|
final String host = request.getHeader(Header.HTTP_HOST.toString());
|
|
|
|
|
if (host != null) {
|
|
|
|
|
recorder.recordAcceptorHost(host);
|
|
|
|
|
} else {
|
|
|
|
|
recorder.recordAcceptorHost(NetworkUtils.getHostFromURL(request.getRequestURL().toString()));
|
|
|
|
|
}
|
|
|
|
|
final String type = request.getHeader(Header.HTTP_PARENT_APPLICATION_TYPE.toString());
|
|
|
|
|
final short parentApplicationType = NumberUtils.parseShort(type, ServiceType.UNDEFINED.getCode());
|
|
|
|
|
recorder.recordParentApplication(parentApplicationName, parentApplicationType);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void recordRootSpan(final SpanRecorder recorder, final HttpServletRequest request) {
|
|
|
|
|
// root
|
|
|
|
|
recorder.recordServiceType(JettyConstants.JETTY);
|
|
|
|
|
|
|
|
|
|
// private void recordRootSpan(final Trace trace, final HttpServletRequest request) {
|
|
|
|
|
// // root
|
|
|
|
|
// trace.markBeforeTime();
|
|
|
|
|
// trace.recordServiceType(JettyConstants.JETTY);
|
|
|
|
|
//
|
|
|
|
|
// final String requestURL = request.getRequestURI();
|
|
|
|
|
// trace.recordRpcName(requestURL);
|
|
|
|
|
//
|
|
|
|
|
// final int port = request.getServerPort();
|
|
|
|
|
// final String endPoint = request.getServerName() + ":" + port;
|
|
|
|
|
// trace.recordEndPoint(endPoint);
|
|
|
|
|
//
|
|
|
|
|
// final String remoteAddr = request.getRemoteAddr();
|
|
|
|
|
// trace.recordRemoteAddress(remoteAddr);
|
|
|
|
|
//
|
|
|
|
|
// if (!trace.isRoot()) {
|
|
|
|
|
// recordParentInfo(trace, request);
|
|
|
|
|
// }
|
|
|
|
|
// trace.recordApi(JETTY_SYNC_API_TAG);
|
|
|
|
|
// // begin
|
|
|
|
|
// trace.traceBlockBegin();
|
|
|
|
|
// }
|
|
|
|
|
final String requestURL = request.getRequestURI();
|
|
|
|
|
recorder.recordRpcName(requestURL);
|
|
|
|
|
|
|
|
|
|
private void recordRootSpan(final SpanRecorder recorder, final HttpServletRequest request) {
|
|
|
|
|
// root
|
|
|
|
|
recorder.recordServiceType(JettyConstants.JETTY);
|
|
|
|
|
final int port = request.getServerPort();
|
|
|
|
|
final String endPoint = request.getServerName() + ":" + port;
|
|
|
|
|
recorder.recordEndPoint(endPoint);
|
|
|
|
|
|
|
|
|
|
final String requestURL = request.getRequestURI();
|
|
|
|
|
recorder.recordRpcName(requestURL);
|
|
|
|
|
final String remoteAddr = request.getRemoteAddr();
|
|
|
|
|
recorder.recordRemoteAddress(remoteAddr);
|
|
|
|
|
|
|
|
|
|
final int port = request.getServerPort();
|
|
|
|
|
final String endPoint = request.getServerName() + ":" + port;
|
|
|
|
|
recorder.recordEndPoint(endPoint);
|
|
|
|
|
if (!recorder.isRoot()) {
|
|
|
|
|
recordParentInfo(recorder, request);
|
|
|
|
|
}
|
|
|
|
|
recorder.recordApi(JETTY_SYNC_API_TAG);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final String remoteAddr = request.getRemoteAddr();
|
|
|
|
|
recorder.recordRemoteAddress(remoteAddr);
|
|
|
|
|
/**
|
|
|
|
|
* Populate source trace from HTTP Header.
|
|
|
|
|
*
|
|
|
|
|
* @param request
|
|
|
|
|
* @return TraceId when it is possible to get a transactionId from Http header. if not possible return null
|
|
|
|
|
*/
|
|
|
|
|
private TraceId populateTraceIdFromRequest(HttpServletRequest request) {
|
|
|
|
|
|
|
|
|
|
if (!recorder.isRoot()) {
|
|
|
|
|
recordParentInfo(recorder, request);
|
|
|
|
|
}
|
|
|
|
|
recorder.recordApi(JETTY_SYNC_API_TAG);
|
|
|
|
|
}
|
|
|
|
|
String transactionId = request.getHeader(Header.HTTP_TRACE_ID.toString());
|
|
|
|
|
if (transactionId != null) {
|
|
|
|
|
long parentSpanID = NumberUtils.parseLong(request.getHeader(Header.HTTP_PARENT_SPAN_ID.toString()), SpanId.NULL);
|
|
|
|
|
long spanID = NumberUtils.parseLong(request.getHeader(Header.HTTP_SPAN_ID.toString()), SpanId.NULL);
|
|
|
|
|
short flags = NumberUtils.parseShort(request.getHeader(Header.HTTP_FLAGS.toString()), (short) 0);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Populate source trace from HTTP Header.
|
|
|
|
|
*
|
|
|
|
|
* @param request
|
|
|
|
|
* @return TraceId when it is possible to get a transactionId from Http header. if not possible return null
|
|
|
|
|
*/
|
|
|
|
|
private TraceId populateTraceIdFromRequest(HttpServletRequest request) {
|
|
|
|
|
final TraceId id = traceContext.createTraceId(transactionId, parentSpanID, spanID, flags);
|
|
|
|
|
if (isDebug) {
|
|
|
|
|
logger.debug("TraceID exist. continue trace. {}", id);
|
|
|
|
|
}
|
|
|
|
|
return id;
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String transactionId = request.getHeader(Header.HTTP_TRACE_ID.toString());
|
|
|
|
|
if (transactionId != null) {
|
|
|
|
|
long parentSpanID = NumberUtils.parseLong(request.getHeader(Header.HTTP_PARENT_SPAN_ID.toString()), SpanId.NULL);
|
|
|
|
|
long spanID = NumberUtils.parseLong(request.getHeader(Header.HTTP_SPAN_ID.toString()), SpanId.NULL);
|
|
|
|
|
short flags = NumberUtils.parseShort(request.getHeader(Header.HTTP_FLAGS.toString()), (short) 0);
|
|
|
|
|
|
|
|
|
|
final TraceId id = traceContext.createTraceId(transactionId, parentSpanID, spanID, flags);
|
|
|
|
|
if (isDebug) {
|
|
|
|
|
logger.debug("TraceID exist. continue trace. {}", id);
|
|
|
|
|
}
|
|
|
|
|
return id;
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void deleteTrace(Trace trace, Object target, Object[] args, Object result, Throwable throwable) {
|
|
|
|
|
trace.traceBlockEnd();
|
|
|
|
|
trace.close();
|
|
|
|
|
final HttpChannel<?> channel = (HttpChannel<?>) args[0];
|
|
|
|
|
final HttpServletRequest request = (HttpServletRequest) channel.getRequest();
|
|
|
|
|
setTraceMetadata(request, null);
|
|
|
|
|
}
|
|
|
|
|
private void deleteTrace(Trace trace, Object target, Object[] args, Object result, Throwable throwable) {
|
|
|
|
|
trace.traceBlockEnd();
|
|
|
|
|
trace.close();
|
|
|
|
|
final HttpChannel<?> channel = (HttpChannel<?>) args[0];
|
|
|
|
|
final HttpServletRequest request = (HttpServletRequest) channel.getRequest();
|
|
|
|
|
setTraceMetadata(request, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|