Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to properly use Logfire in Kedro? #3978

Open
astrojuanlu opened this issue Jul 2, 2024 · 2 comments
Open

How to properly use Logfire in Kedro? #3978

astrojuanlu opened this issue Jul 2, 2024 · 2 comments

Comments

@astrojuanlu
Copy link
Member

astrojuanlu commented Jul 2, 2024

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

  • Kedro version used (pip show kedro or kedro -V): 0.19.6
  • Python version used (python -V): 3.11.9
  • Operating system and version: macOS Sonoma 14.5
@astrojuanlu
Copy link
Member Author

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

My question on LogfireNotConfiguredWarning still stands

@astrojuanlu
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

1 participant