For those attempting to send metrics when the user session ends, the MDN recommends to use the visibilitychange
event:
@HostListener('window:visibilitychange')
onBeforeUnload(): void {
if (this.document.visibilityState === 'hidden') {
this.userSessionSpan.end();
}
}
https://developer.mozilla.org/en-US/docs/Web/API/Window/pagehide_event