I want to trace the begining and end of a single operation. As the receiver receives 100 reqeust/seconds, i am unable to achive it. Kindly help
By the time first process ends, second process enters and changing the UUID value.
So i am unable to trace the begin and end of a single message/request.
This is not a Web application so can't use 'reqest' scope for Trace class, my application is a pub-sub model. Here is a sample application.
public class MainClass {
@Bean
@Autowired
public Receiver getEventHubReceiver(Trace trace, SomeOtherClass classex) {
return new Receiver(trace, classex);
}
}
@Component
class Trace{
String traceid;
public void setTraceid(String traceid) {
this.traceid = traceid;
}
public void trace(String msg){
System.out.println(traceid+" : Tracing : "+msg);
}
}
class Receiver{
private final SomeOtherClass classex;
private final Trace trace;
Receiver(Trace trace, SomeOtherClass classex){
this.trace= trace;
this.classex = classex;
}
//This is a callback method invoked by server internally.
public void receiver(){
trace.setTraceid(UUID.randomUUID().toString());
trace.trace("reached Receiver..started");
classex.invoke(); //==> I don't want to pass the Trace object here, same object should be used by multiple classes.
trace.trace("reached Receiver..completed");
}
}
class SomeOtherClass{
@Autowired
private Trace trace; // ==> ISSUE -- Behaving as a single ton.
public void invoke(){
trace.trace("Reached SomeOtherClass - started");
someLongRunProcess(); // it take almost 3-5 seconds to complete this.
trace.trace("Reached SomeOtherClass - completed");
}
private void someLongRunProcess() {
//DB invoke option
}
}