fix tomcat span without peer host and peer port issue
This commit is contained in:
parent
21696f132f
commit
765b15e026
|
|
@ -55,10 +55,10 @@ public class DubboInterceptor implements InstanceMethodsAroundInterceptor {
|
|||
Tags.URL.set(span, generateRequestURL(requestURL, invocation));
|
||||
Tags.COMPONENT.set(span, DUBBO_COMPONENT);
|
||||
Tags.SPAN_LAYER.asRPCFramework(span);
|
||||
Tags.PEER_HOST.set(span, requestURL.getHost());
|
||||
Tags.PEER_PORT.set(span, requestURL.getPort());
|
||||
|
||||
if (isConsumer) {
|
||||
Tags.PEER_HOST.set(span, requestURL.getHost());
|
||||
Tags.PEER_PORT.set(span, requestURL.getPort());
|
||||
Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_CLIENT);
|
||||
ContextCarrier contextCarrier = new ContextCarrier();
|
||||
ContextManager.INSTANCE.inject(contextCarrier);
|
||||
|
|
|
|||
|
|
@ -43,6 +43,8 @@ public class TomcatInterceptor implements InstanceMethodsAroundInterceptor {
|
|||
|
||||
Span span = ContextManager.INSTANCE.createSpan(request.getRequestURI());
|
||||
Tags.COMPONENT.set(span, TOMCAT_COMPONENT);
|
||||
Tags.PEER_HOST.set(span, fetchRequestPeerHost(request));
|
||||
Tags.PEER_PORT.set(span, request.getRemotePort());
|
||||
Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_SERVER);
|
||||
Tags.URL.set(span, request.getRequestURL().toString());
|
||||
Tags.SPAN_LAYER.asHttp(span);
|
||||
|
|
@ -76,4 +78,29 @@ public class TomcatInterceptor implements InstanceMethodsAroundInterceptor {
|
|||
Tags.ERROR.set(span, true);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
public String fetchRequestPeerHost(HttpServletRequest request) {
|
||||
String ip = request.getHeader("X-Forwarded-For");
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("Proxy-Client-IP");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("WL-Proxy-Client-IP");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("HTTP_CLIENT_IP");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getRemoteAddr();
|
||||
}
|
||||
return ip;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue