DataDog / serilog-sinks-datadog-logs

Serilog Sink that sends log events to Datadog https://www.datadoghq.com/
Apache License 2.0
60 stars 41 forks source link

Events lost after CloseAndFlush #106

Closed jorge-pascual closed 11 months ago

jorge-pascual commented 11 months ago

Hello everyone,

I had a suspicion that after a CloseAndFlush, events were being lost. I've set up a very simple proof of concept which is essentially a console application that writes some logs and then finishes. Upon running it, I notice that the logs aren’t in DataDog.

I’ve used the debugger and after executing CloseAndFlush, I see that indeed there's a DataDog thread working and if it terminates, obviously the data it still holds will be lost.

Looking at the code in Dispose, I don’t see that it's waiting for the events to finish sending. I'm not sure if this is truly a problem with this sink or with PeriodicBatching.

Screenshot 2023-09-19 at 18 10 47

Has anyone else experienced something similar?

Thank you!

gh123man commented 11 months ago

Hi @jorge-pascual

Thanks for raising this. I tried a similar setup and cannot reproduce the issue. However that could be related to my machine or network conditions. I did some debugging, and CloseAndFlush appears to block until all logs are flushed. If I do not call CloseAndFlush, logs are indeed dropped when the process terminates (as expected).

I tried to put a Thread.Sleep in the HTTP client to simulate a slow transaction, and it still correctly blocked until flush. I'll leave this issue open to see if anyone else has similar problems, or if we can get a more reliable repro.

jorge-pascual commented 11 months ago

Hi @gh123man

I've simplified the configuration and found that you are right. The Datadog Sink is behaving correctly. The problem was with a "parent" sink that didn't dispose of the child resources.

Thank you for your very fast reply. You can close the issue.

-- Jorge

gh123man commented 11 months ago

Great! Glad you found a solution. And no problem 👍