logtail / logtail-python

Better Stack Python client
https://betterstack.com/logs
Other
36 stars 10 forks source link

Logtail (token key) thrown OSError in DigitalOcean App platform #10

Closed sumandari closed 1 year ago

sumandari commented 1 year ago

I'm using DO App platform for Flask and trying to integrate it with logtail handler. The code will run smoothly on my local server and send the message to logtail source. But if I deployed the code to DO app platform it will throw errors:

[2023-03-16 08:09:15 +0000] [20] [ERROR] Exception in worker process                                                                    
Traceback (most recent call last):                                                                                                      
  File "/workspace/.heroku/python/lib/python3.10/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker                          
    worker.init_process()                                                                                                               
  File "/workspace/.heroku/python/lib/python3.10/site-packages/gunicorn/workers/base.py", line 134, in init_process                     
    self.load_wsgi()                                                                                                                    
  File "/workspace/.heroku/python/lib/python3.10/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi                        
    self.wsgi = self.app.wsgi()                                                                                                         
  File "/workspace/.heroku/python/lib/python3.10/site-packages/gunicorn/app/base.py", line 67, in wsgi                                  
    self.callable = self.load()                                                                                                         
  File "/workspace/.heroku/python/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 58, in load                               
    return self.load_wsgiapp()                                                                                                          
  File "/workspace/.heroku/python/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp                       
    return util.import_app(self.app_uri)                                                                                                
  File "/workspace/.heroku/python/lib/python3.10/site-packages/gunicorn/util.py", line 412, in import_app                               
    app = app(*args, **kwargs)                                                                                                          
  File "/workspace/app/__init__.py", line 116, in create_app                                                                            
    logtail_handler = LogtailHandler(source_token=app.config['LOGTAIL_EXCEPTION'])                                                      
  File "/workspace/.heroku/python/lib/python3.10/site-packages/logtail/handler.py", line 35, in __init__                                
    self.pipe = multiprocessing.JoinableQueue(maxsize=buffer_capacity)                                                                  
  File "/workspace/.heroku/python/lib/python3.10/multiprocessing/context.py", line 108, in JoinableQueue                                
    return JoinableQueue(maxsize, ctx=self.get_context())                                                                               
  File "/workspace/.heroku/python/lib/python3.10/multiprocessing/queues.py", line 297, in __init__                                      
    Queue.__init__(self, maxsize, ctx=ctx)                                                                                              
  File "/workspace/.heroku/python/lib/python3.10/multiprocessing/queues.py", line 43, in __init__                                       
    self._rlock = ctx.Lock()                                                                                                            
  File "/workspace/.heroku/python/lib/python3.10/multiprocessing/context.py", line 68, in Lock                                          
    return Lock(ctx=self.get_context())                                                                                                 
  File "/workspace/.heroku/python/lib/python3.10/multiprocessing/synchronize.py", line 162, in __init__                                 
    SemLock.__init__(self, SEMAPHORE, 1, 1, ctx=ctx)                                                                                    
  File "/workspace/.heroku/python/lib/python3.10/multiprocessing/synchronize.py", line 57, in __init__                                  
    sl = self._semlock = _multiprocessing.SemLock(                                                                                      
OSError: [Errno 38] Function not implemented                                                                                            

gunicorn run command:

gunicorn --log-level warning --timeout 90 -w 5 --worker-tmp-dir /dev/shm "app:create_app()" -b 0.0.0.0:8001

app.py

def create_app():
    app = Flask(__name__)

    ...

    logtail_handler = LogtailHandler(source_token=app.config['LOGTAIL_EXCEPTION'])
    logtail_handler.setLevel(logging.WARNING)
    logtail_handler.setFormatter(formatter)
    app.logger.addHandler(logtail_handler)

   ...
   return app
curusarn commented 1 year ago

Hi @sumandari,

Thank you for the bug report.

We are tracking this issue internally. I don't have a time estimate to share but I will make sure to keep you updated.

curusarn commented 1 year ago

Hi @sumandari,

I appreciate your patience.

The error is likely caused by the use of multiprocessing which often isn't available on serverless platforms. I have just released a new version v0.2.0 which doesn't use multiprocessing anymore.

Could you upgrade to v0.2.0 and let me know if it solves your issue? 🙏

sumandari commented 1 year ago

Thanks a lot for your help @curusarn

I will upgrade the version tomorrow or early next week and will let you know.

sumandari commented 1 year ago

I have tested it on DO app platform and it works like a charm! Thanks, @curusarn! I will close this issue now