Hi All,
I was wondering how one can determine if a transaction is finished?
I am working on an angular project and want to log how long a user is logged in.
When the user logs out, I start a transaction, calculate the session duration, and then end the transaction. However, I see in my network traffic in chrome that this transaction is not always sent, because part of the logoutprocess is to redirect the user back to the login page. As far as I can tell, this prevents the transaction from completing and no data is sent to elastic.
Here is the simplified code:
const transaction = apm.startTransaction('User authenticated logging out', 'custom');
// some session duration calculation is happening here
...
apm.addLabels({ sessionDuration: sessionDuration });
transaction.end();
this.router.navigateByUrl('/auth/login'); // sometimes prevents transaction from finishing
...
If I delay the rediction by, say, 1 second, like in the code below, then I have no issues and I can see the logout event in Kibana.
const transaction = apm.startTransaction('User authenticated logging out', 'custom');
// some session duration calculation is happening here
...
apm.addLabels({ sessionDuration: sessionDuration });
transaction.end();
setTimeout(() => {
this.router.navigateByUrl('/auth/login'); // transaction is always finished
}, 1000);
I've searched online for a solution, but I cant seem to find people experiencing the same problem, which suggests I'm probably doing something wrong.
I did find this api call: transaction.isFInished(): boolean, but unfortunately checking for this to be true before redirecting doesnt make a difference. Also the comment on this function says:
/**
* undocumented, might be removed in future versions
*/
isFinished(): boolean
Which is a real shame, cos it sounds exactly like what I need.
So how do I determine if a transaction is finished before executing other code?
I am using "@elastic/apm-rum-angular": "^1.1.9"
Also, I am very new to APM and this forum, so if more information is needed, please let me know.
Any help is greatly appreciated