How to retrieve the call chain / stack trace in the aspect?
andrashatvani opened this issue · 3 comments
andrashatvani commented
I've got a LoggerAspect, an HttpService and many components and services which use the HttpService. How can I retrieve the HttpService caller's name in the LoggerAspect?
mgechev commented
You can find the caller of the HttpService without creating a specific instance of the HttpService for each individual consumer, or passing the consumer as argument.
If you have:
const HttpService = { get: () => {} }
const Consumer = {
makeRequest() {
HttpService.get();
}
};
Consumer.makeRequest();
There's no way to know if Consumer
delegated it's call to HttpService
or not.
andrashatvani commented
I've found https://www.stacktracejs.com/#!/docs/stacktrace-js - wouldn't that be an option?
mgechev commented
console.trace
is another option but you'll get the consumer's name as string, which won't work after mangling.