Skip to content

Google Colab/IPython cell output conflicts on logfire import #1267

@lifefoundry-scott

Description

@lifefoundry-scott

Description

Problem Statement

We have previously run some python scripts via Google Colab notebooks, usually using the shell command !uv run my_script.py . After instrumenting the codebase with logfire, there is some unexpected behavior blocking cell output.

Logfire configures properly within the script and the script itself executes perfectly. Spans and instrumented functions, auto-instrumented objects, etc are all properly logged and sent to the dashboard. However, the cell output shows Logfire Project URL: ____ (blank) in the output, rendered as expecting input but no change in behavior upon typing anything in. After this appears, everything further is blocked from appearing in the cell output, including print statements, Python logging records, or Logfire logging records (manual and instrumented).

Behavior of the same script is normal locally and in a container on a production server.

Investigation

  • Cell/script output is normal prior to import logfire and importing is what initiates the erroneous behavior.
  • Write token was used to configure, but behavior is the same whether supplied via env variable or logfire.configure(). The blank project URL printout appears prior to configuration regardless, but the write token is working fine as the script executes.
  • When !logfire auth is called, logfire logging statements, print statements, etc behave as expected when manually typed into notebook cells.
  • When !logfire auth is called and then the script is run via shell command, the script file itself behaves properly, but the first imported file that contains a logfire import triggers the erroneous behavior
  • As mentioned, behavior with the same script is normal locally and on a production server, as well as when run via the bash terminal supplied with the colab notebook.
  • Tried all documented logfire.configure() settings and environment variables, which seem not to do anything because the problem occurs on logfire import
  • Tried some Colab and IPython settings to reduce rendering of outputs, no luck there

Workarounds

  1. uv run my_script.py &> output.txt writes the expected output to the file
  2. Executing using the %%bash or %%sh cell magics prints the expected output, albeit dumped at the end of execution rather than printed real-time

Expected Behavior

  1. Importing logfire and using logfire-instrumented code does not cause any erroneous behavior that blocks real-time print statements, logging records, or logfire console outputs. If need be, environment variables, or config/credential files are supplied prior to script execution.
  2. Alternatively, a flag or environment variable is set that disables interactive outputs (and raises exceptions if disabled when CLI commands are called that rely on them)

Thanks! Enjoying logfire so far in general and looking forward to the future development

Python, Logfire & OS Versions, related packages (not required)

Behavior exhibited on 3.21.1 and 3.25.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions