logdna / python

A python package for sending logs to LogDNA
MIT License
47 stars 35 forks source link

Getting this to work with FastAPI or another Async Backend #112

Open waseemhnyc opened 3 months ago

waseemhnyc commented 3 months ago

When attempting to do this in my FastAPI backend. I am noticing that the request is getting blocked.

    handler = LogDNAHandler(key='')
    logging.getLogger().addHandler(handler)
    logging.info("Checking to see if it works!")

Looking at the library. I included the print "Request Sent". It never gets printed, the request does not execute, the backend sits there and I need to restart the entire app.

        try:
            headers = {
                'user-agent': self.user_agent,
                'apikey': self.key
            }
            response = requests.post(url=self.url,
                                     json=data,
                                     params={
                                         'hostname': self.hostname,
                                         'ip': self.ip,
                                         'mac': self.mac,
                                         'tags': self.tags,
                                         'now': int(time.time() * 1000)
                                     },
                                     stream=True,
                                     allow_redirects=True,
                                     timeout=self.request_timeout,
                                     headers=headers)
            print("Request Sent")