added caller information

This commit is contained in:
Lucio Lelii 2022-06-15 17:44:52 +02:00
parent 80f5de688a
commit 6f999bcedc
1 changed files with 12 additions and 12 deletions

View File

@ -28,7 +28,7 @@ public class RequestAccounting extends RequestHandler {
private static ThreadLocal<Long> startCallThreadLocal = new ThreadLocal<Long>(); private static ThreadLocal<Long> startCallThreadLocal = new ThreadLocal<Long>();
private static final String UNKNOWN = "Unknown";
@Override @Override
public String getName() { public String getName() {
@ -42,15 +42,14 @@ public class RequestAccounting extends RequestHandler {
String context = getContext(appContext); String context = getContext(appContext);
String calledMethod = e.request().getHeader(Constants.called_method_header); String calledMethod = e.request().getRequestURI().substring(e.request().getContextPath().length());
if (calledMethod==null){ if (calledMethod.isEmpty())
calledMethod = e.request().getRequestURI().substring(e.request().getContextPath().length()); calledMethod = "/";
if (calledMethod.isEmpty()) calledMethod= e.request().getMethod()+" "+calledMethod;
calledMethod = "/";
calledMethod= e.request().getMethod()+" "+calledMethod;
}
InnerMethodName.instance.set(calledMethod); InnerMethodName.instance.set(calledMethod);
String caller = "Unknown"; String caller = SecretManagerProvider.instance.get()!=null ? SecretManagerProvider.instance.get().getOwner().getId():
UNKNOWN;
startCallThreadLocal.set(System.currentTimeMillis()); startCallThreadLocal.set(System.currentTimeMillis());
log.info("REQUEST START ON {}:{}({}) CALLED FROM {}@{} IN SCOPE {} ", log.info("REQUEST START ON {}:{}({}) CALLED FROM {}@{} IN SCOPE {} ",
@ -67,8 +66,9 @@ public class RequestAccounting extends RequestHandler {
String context = getContext(appContext); String context = getContext(appContext);
String caller = "Unknown"; String caller = SecretManagerProvider.instance.get()!=null ? SecretManagerProvider.instance.get().getOwner().getId():
String callerQualifier = "UNKNOWN"; UNKNOWN;
String callerQualifier = UNKNOWN;
//retieves caller Ip when there is a proxy //retieves caller Ip when there is a proxy
String callerIp = e.request().getHeader("x-forwarded-for"); String callerIp = e.request().getHeader("x-forwarded-for");
if(callerIp==null) if(callerIp==null)
@ -77,7 +77,7 @@ public class RequestAccounting extends RequestHandler {
boolean success = e.response().getStatus()<400; boolean success = e.response().getStatus()<400;
if (appContext.container().configuration().mode()!=Mode.offline) if (appContext.container().configuration().mode()!=Mode.offline)
generateAccounting(caller,callerQualifier,callerIp==null?"UNKNOWN":callerIp , success, context, appContext); generateAccounting(caller,callerQualifier,callerIp==null?UNKNOWN:callerIp , success, context, appContext);
long durationInMillis = System.currentTimeMillis()-startCallThreadLocal.get(); long durationInMillis = System.currentTimeMillis()-startCallThreadLocal.get();