[Python] How do I merge logs in Datadog for flask.send_static_file and /<path:filename>?

Discussão em 'Python' iniciado por Stack, Outubro 3, 2024.

  1. Stack

    Stack Membro Participativo

    My app uses Flask and I've been accessing random paths to test my 404 logic (eg http://url.com/asdf). All works as expected, but I noticed that in Datadog, I'd get two errors for hitting a 404. One from flask.send_static_file, and one from /<path:filename>.

    The way I understand it, there's one error for Flask trying to access a static file (even though it doesn't exist), and one error for the routing. Let me know if this assumption isn't correct.

    To fix this, I added an error handler in my code:

    @app.errorhandler(404)
    def not_found(error):
    error_id = str(uuid4())[:6]
    app.logger.warning(f"404 error: {error}", extra={"errorId": error_id})
    return f"errorId={error_id}", 404


    I thought the error handler in my code would consolidate these two errors in Datadog, but I'm still seeing both errors logged. Any thoughts how I could merge these two logs since they're essentially logging the same thing? Thanks in advance for the help.

    Continue reading...

Compartilhe esta Página