designcourse icon indicating copy to clipboard operation
designcourse copied to clipboard

Improve sending events on browser exit

Open igorko opened this issue 3 years ago • 9 comments

I don't see the ability to configure flush timeout. I see it's only set in DEFAULT_CONFIGURATION.

igorko avatar Mar 18 '21 10:03 igorko

This is not an option we expose publicly. What would be your use-case?

BenoitZugmeyer avatar Mar 18 '21 10:03 BenoitZugmeyer

I am not sure that flushOnVisibilityHidden will always work (it definitely will not under IE11, and I am not sure it will work when closing frame, checking this), so searching the way to make sure all logs are sent. The other solution would be probably to add manual flush function.

igorko avatar Mar 18 '21 10:03 igorko

We will re-explore the flushOnVisibilityHidden strategy to see what could be improved in the use cases you mention (IE11 and removed iframe)

We won't add a way to flush manually in the short term, as we prefer to control when events are flushed. But we will keep this in mind.

BenoitZugmeyer avatar Mar 18 '21 14:03 BenoitZugmeyer

Probably for IE11 the solution would be to send synchronous request in place where sendBeacon is used. Anyway the size of request is restricted, so it shouldn't block much.

igorko avatar Mar 19 '21 14:03 igorko

Also I don't see logs are sent by Firefox on browser exit.

igorko avatar Mar 19 '21 15:03 igorko

We also want the flush timeout can be configured or expose a API to be able to flush logs. Our use case is that we want to capture all the errors in all the cypress E2E tests(on headless mode). Once there is a failure happened, the test case/browser will be closed at once and there is no chance/time for flushing the errors. @BenoitZugmeyer

hehoo avatar Mar 24 '21 02:03 hehoo

In my use-case I have a logger call in beforeunload callback. Even though the callback is fired successfully DD fails to deliver those logs consistently in most cases (maybe 7 times out of 10 logs are not being delivered). I think it is related to the order in which beforeunload handlers are called i.e. DD is able to send logs if its own callback is fired after log method calls: https://github.com/DataDog/browser-sdk/blob/68d010c13efec6a7a1ccec821adc1fb88f51b300/packages/core/src/transport/transport.ts#L201

kanoshin avatar May 07 '21 21:05 kanoshin

Any update on this feature? Our use case is that we have a web app which may be displayed in a web view in a mobile application or accessed directly by mobile users on iOS or Android. It appears that beforeunload doesn't trigger on mobile devices when a page is closed and so we're losing batches of logs.

It'll be great if flushTimeout could be configured.

mesiu avatar Jan 10 '23 04:01 mesiu

I'm running Datadog inside a Chrome extension - the flush interval seems enormous to the point that I don't get most of my logs because the extension is minimized before the SDK flushes.

This should be configurable just like the Node.js client which allows for manual flushing.

faizan-ali avatar Jul 09 '23 23:07 faizan-ali