axiomhq / axiom-py

Official Python bindings for the Axiom API
https://axiom.co
MIT License
27 stars 19 forks source link

Can't see logs due to 'flush' issue #139

Closed FelipeLahti closed 1 month ago

FelipeLahti commented 1 month ago

Issue

Logs aren't propagating to axiom.

How to reproduce:

Possible solution:

FelipeLahti commented 1 month ago

Workaround: Spin up a thread to flush it every 30s. It could be add as built in into the lib if that makes sense.

        client = axiom_py.Client()
        handler = AxiomHandler(client, "my-dataset")

        def flush_handler_periodically():
            while True:
                handler.flush()
                time.sleep(30)

        thread = threading.Thread(target=flush_handler_periodically)
        thread.daemon = True
        thread.start()

        logging.getLogger().addHandler(handler)
bahlo commented 1 month ago

Hi @FelipeLahti, thanks! You’re right, we should fix this. Another option would be using a threading.Timer to flush logs at least every second—similarly to how we handle this situation in axiom-js. Will keep his open until that‘s implemented 😌

bahlo commented 1 month ago

Fixed in https://github.com/axiomhq/axiom-py/pull/140, will be in the next release

subham1099 commented 1 month ago

@bahlo Could we implement the same for structlog? Should I raise a PR with a similar change to the structlog module?