Auto shutdown in collector-exporter can hurt performance in some browsers
See original GitHub issue- This only affects the JavaScript OpenTelemetry library
- This may affect other libraries, but I would like to get opinions here first
Hi 👋
@opentelemtry/exporter-collector by default adds event listener for the unload event on browser platforms.
According to MDN it can hurt website’s performance when doing back/forward buttons:
Additionally, the unload event is incompatible with the back/forward cache (bfcache) implemented in modern browsers. Some browsers, such as Firefox, handle this incompatibility by excluding pages from the bfcache if they contain unload handlers, thus hurting performance. See Avoid unload and beforeunload for more.
Also I’m not sure what’s the purpose of this behaviour? shutdown only returns a promise of already exported items, so doing it on unload doesn’t make more sense, does it? See the code I’m referring to.
Additionally, onShutdown is empty for node platform, so we could just remove the onInit and onShutdown functionalities. Am I missing something?
Issue Analytics
- State:
- Created 2 years ago
- Comments:16 (12 by maintainers)

Top Related StackOverflow Question
Got it. So sendBeacon is our best bet on shutdowns and if we have to use xhr we just have to hope
I believe
sendBeaconAPI is sync however the data is sent asynchronously, you just never get the callback. It ensentially just push the request into a queue that is handled even if the page is closed.