kedro-org / kedro

Kedro is a toolbox for production-ready data science. It uses software engineering best practices to help you create data engineering and data science pipelines that are reproducible, maintainable, and modular.
https://kedro.org
Apache License 2.0
9.88k stars 893 forks source link

How to properly use Logfire in Kedro? #3978

Open astrojuanlu opened 3 months ago

astrojuanlu commented 3 months ago

Description

I was trying to use Logfire in Kedro, and it mostly worked. However, the results aren't optimal.

Context

Steps to Reproduce

  1. Create a new spaceflights project
  2. Add logfire.configure() in settings.py (for lack of a better place)
  3. Add a logfire handler to the logging. For example:
--- spaceflights-pandas-viz2/conf/logging.yml   2024-07-02 14:47:47
+++ spaceflights-pandas-viz/conf/logging.yml    2024-07-02 14:47:10
@@ -32,12 +32,15 @@
     # See https://docs.kedro.org/en/stable/logging/logging.html#project-side-logging-configuration
     # tracebacks_show_locals: False

+  logfire:
+    class: logfire.LogfireLoggingHandler
+
 loggers:
   kedro:
     level: INFO

 root:
-  handlers: [rich, info_file_handler]
+  handlers: [rich, info_file_handler, logfire]

Expected Result

The logs should display flawlessly on the Logfire web UI.

Actual Result

[!NOTE]
The shortcodes shouldn't leak any longer, see below

With this configuration, the shortcodes for rich coloring "leak" onto the logs:

image

(notice the [dark_orange] shortcodes)

If I disable the rich handler in logging.yml, the CLI output changes but the result on Logfire UI is the same.

And finally, I tried rich.uninstall() but it turns out logfire depends on rich 🙃


On top of that, I observe this big fat warning:

$ kedro run
[07/02/24 14:51:01] INFO     Using `conf/logging.yml` as logging configuration. You can change    __init__.py:249
                             this by setting the KEDRO_LOGGING_CONFIG environment variable                       
                             accordingly.                                                                        
                    WARNING  /Users/juan_cano/Projects/QuantumBlackLabs/workshop-from-zero-to-mlo warnings.py:110
                             ps/.venv/lib/python3.11/site-packages/kedro/framework/cli/catalog.py                
                             :15: LogfireNotConfiguredWarning: No logs or spans will be created                  
                             until `logfire.configure()` has been called. Set the environment                    
                             variable LOGFIRE_IGNORE_NO_CONFIG=1 or add ignore_no_config=true in                 
                             pyproject.toml to suppress this warning.                                            
                               from kedro.framework.project import pipelines, settings                           

Logfire project URL: https://logfire.pydantic.dev/astrojuanlu/test-simple
[07/02/24 14:51:03] INFO     Kedro project spaceflights-pandas-viz                                 session.py:324

Apart from that LOGFIRE_IGNORE_NO_CONFIG, is there a better way to achieve this?

Your Environment

astrojuanlu commented 3 months ago

The shortcodes are because of #3626, fixed by #3682 (thanks for the heads-up @noklam)

My question on LogfireNotConfiguredWarning still stands

astrojuanlu commented 2 weeks ago

FTR Logfire is leaving beta soon https://pydantic.notion.site/Pydantic-Logfire-Pricing-f719ee768d10457f970f78eedbff976e