logfire
logfire copied to clipboard
Vendor dependencies
Description
The idea is to vendor/remove the following dependencies:
dependencies = [
"opentelemetry-sdk >= 1.21.0",
"opentelemetry-exporter-otlp-proto-http >= 1.21.0", # vendor
"opentelemetry-instrumentation >= 0.41b0",
"rich >= 13.4.2", # remove
"protobuf >= 4.23.4", # vendor
"typing-extensions >= 4.1.0",
"tomli >= 2.0.1; python_version < '3.11'",
"executing>=2.0.1", # vendor
]
The first step here is actually to investigate the ratio between amount of work and dependencies removed.
Let's start by trying to remove rich.
By remove, we mean just drop the dependency and try to make the output similar, or vendor?
drop the dependency and try to make the output similar
I think we should discuss the SimpleConsoleSpanExporter, and how we want to provide that functionality.
For example, when using Uvicorn:
from fastapi import FastAPI
import logfire
app = FastAPI()
logfire.configure()
logfire.instrument_fastapi(app)
@app.get('/')
def read_root():
return {'Hello': 'World'}
I would have the following output:
❯ uvicorn main:app --reload
INFO: Will watch for changes in these directories: ['/Users/marcelotryle/dev/pydantic/logfire']
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [65861] using StatReload
INFO: Started server process [65863]
INFO: Waiting for application startup.
INFO: Application startup complete.
Logfire project URL: https://logfire.pydantic.dev/kludex/potato
09:14:49.919 GET /
09:14:49.925 FastAPI arguments
INFO: 127.0.0.1:58833 - "GET / HTTP/1.1" 200 OK
The 09:14:49.919 GET / and INFO: 127.0.0.1:58833 - "GET / HTTP/1.1" 200 OK are pretty much duplicated. When you have a lot of those, it gets annoying. When I brought this subject before, we agreed that the recommendation would be to disable the console (logfire.configure(console=False)).
I'm not sure what's the right answer here, but I think we should have some answer...
On a related note, if I remove rich from logfire._internal.config, this message will not be highlighted:
Logfire project URL: https://logfire.pydantic.dev/kludex/potato
And... I think the highlight on it is helpful.
I'm mentioning this because it seems that rich handles some different environments to provide colors everywhere.
https://github.com/pydantic/logfire/issues/235#issuecomment-2567471491 feels unrelated to the rest of the issue. But I think we could recommend logfire.with_settings(console_log=False).instrument_fastapi(...) or make that the default and allow turning it on with instrument_fastapi(console_log=True)
If we want reliable colors in console logs in general we will need the kind of logic rich has, not just for that project URL. Searching for windows in rich gives lots of results and suggests that extracting it to vendor will be hard. colorama is no longer maintained and I don't know if we can trust it. I'm disappointed I can't find a library just for this purpose. Might need to have a conversation about this.