New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Send batched export items in when visibilityState changes to hidden #1721
Comments
I think this should be handled by each exporter so if you need that in the collector exporter, i believe it should be added there. Potentially adding a buffer that waits for the event to send them. I also believe this should be optional, some might want to send telemetry data asap. EDIT: Are you interested to make a PR for this ? |
Agreed that it should be optional. So this could be a browser specific option extending from
How would this interop with the That's really the core of the problem -- the exporter is currently listening to
I would be interested in making a PR for this. I can make an implementation in my application to test it out, and then integrate directly into the library. As for option names, what do you think? Something along the lines of |
@bradfrosty I described my concerns about the Actually I can't see a way to implement such automatic flushing in the collector exporter, because spans waits in Did you succeed with some PR about it? I was thinking about providing browser implementation for the Also it needs to go together with the exporter implementation, because it will only work when |
@bradfrosty I had some time so I prepared a PR for that. You can review it at #2243. |
I think BSP is the correct place to implement this. Exporters don't implement batching because it's offloaded on the span processor. If a user really can't wait for their telemetry data they will likely either use SSP, use BSP with this option disabled, or use BSP and manually flush when their particular situation demands. |
Hey @kkruk-sumo I've been a bit busy, so I haven't been able to work on a PR. We've been maintaining manual flush logic for this use case in our OTel configuration, which is working for us now. Thanks for looking into this! |
…metry#1721) Co-authored-by: Marc Pichler <marc.pichler@dynatrace.com>
I would like to start a discussion about sending completed, batched export items when
document.visibilityState
becomeshidden
. Thevisibilitychange
event will be fired when the contents of the tab become hidden, which happens when the tab changes, closes, or the page unloads.The motivation behind this is to gather potentially useful information near the end of the page lifecycle. While there will likely not be many spans/export items available during this time, I am curious to know more what happens near or during the unload of the page.
This should only impact browser consumers utilizing any of the batch processors with the collector exporter. It also should export data in this scenario if
navigator.sendBeacon()
is supported to prevent a delay of the page unload. If it's not supported, just use the existing behavior.Due to the new recommendations on MDN and this Volument post on sendBeacon, I think
visibilitychange
should be used instead of sending inbeforeunload
as is traditionally recommended withnavigator.sendBeacon()
.If this were to be implemented, where would it go? Is this more of the responsibility of batch processors? Or is this something that belongs in
CollectorExportBrowserBase.ts
?The text was updated successfully, but these errors were encountered: