theogravity / datadog-transports

A monorepo for logging plugins that ship logs to datadog
MIT License
6 stars 2 forks source link

Lambda missing log: log didn't send to datadog if execution is fast #16

Open mary2501 opened 4 weeks ago

mary2501 commented 4 weeks ago

Hi folks, I found this error: I have a valid configuration for Datadog; when I send the datadog's log, if the lambda execution is too fast, this log will not be sent. I tried using the same configuration and adding a sleep instruction, and the log was sent correctly.

Would anyone be able to help me find a solution? I also tried without success:

mary2501 commented 4 weeks ago

Additional information: if I use the datadog library on the CDK, which adds a lambda layer (https://docs.datadoghq.com/serverless/libraries_integrations/cdk/), I don't have this problem.

theogravity commented 4 days ago

My guess since the issue is that your lambda ends quickly is because the logs are sent in an async fashion outside the normal execution flow:

https://github.com/theogravity/datadog-transports/blob/main/packages/datadog-transport-common/src/DataDogTransport.ts#L59

So if you have something like pino.info("test") and your lambda ends quickly, there is always that chance that the logs don't get sent out because the log send is sent out-of-band, so the async call to send the log may or may not resolve.

but overall, if you're using pino for this it's prob not a good idea because pino is async out-of-band by design

for your issue to be resolved, src/DataDogTransport.ts would have to be refactored to add the ability to await on the send, and you'd have to use a logging library that is not pino (or create your own) that you can await on