zach-taylor / splunk_handler

Python logging handler for sending logs to Splunk Enterprise
MIT License
55 stars 41 forks source link

Lambda using this handler is forwarding logs from Cloudwatch multiple times #54

Open nnixen opened 3 years ago

nnixen commented 3 years ago

Hi, I'm writing AWS Lambda to forward logs from Cloudwatch to Splunk Cloud. Everything works, but when there is small amount of events (logs pushed to Cloudwatch loggroup) my lambda forwards them multiple times, sometimes 2, sometimes more. I'm positive I don't call this handler multiple times for the same event, so can it be something in the handler itself? I changed this bit of code to get parameters' substitution working like I needed it to do (function format_record()):

temp = json.loads(str(record.getMessage()))
        params = {
            'time': temp['_time'],
            'host': temp['_host'],
            'index': temp['_index'],
            'source': temp['_source'],
            'sourcetype': temp['_sourcetype'],
            'event': temp['event']
        }

Is it possible that it broke something and now handler workers are forwarding same logs multiple times? I make list of all Cloudwatch events and then iterate over it calling this handler:

for message in messages:
                logger.critical(message) 
                splunk.force_flush()
JeffreyLMelvin commented 2 years ago

If you are going to force_flush every message, why not just set the flush_interval to zero? This will disable the use of a queue and timer and send the logs individually to Splunk

JeffreyLMelvin commented 2 years ago

WRT the observed duplicate logs, this is also something I have observed, but is not something that I have necessarily attributed to this library. If you are able to identify the cause and can update this issue or open a new one with the details or a PR with a fix, that would be awesome.