logfire
logfire copied to clipboard
`logfire-noop`
Description
My idea is that we release logfire-noop, this package has no dependencies and allows third-party libraries to integrate with logfire while still giving their users complete choice over whether to actually use Logfire.
The idea is that logfire-noop would contain two modules: logfire_noop and logfire_if_installed (name TBC)
logfire_noop exports types matching logfire but that do nothing, or do the minimum required for code to run, e.g. logfire.span() needs to return a context manager.
logfire_if_installed behaves like this:
- when
logfireis installed, it just the contents oflogfire - when logfire is not installed, it just the contents of
logfire_noop
Third party libraries would wuite code like this:
import logfire_if_installed
...
def my_library_method(...):
...
with logfire.span('doing a thing {sniffle=}', sniffle=rofl):
...
@willbakst might want to use this in https://github.com/Mirascope/mirascope.
I think we should use the same namespace for logfire-noop and logfire i.e. if you install logfire-noop, you'll be able to access the same methods as logfire.
We should probably create the package within this repository, and have a job that checks that everything you can use on logfire can be used on logfire_noop.
Would it be possible for logfire-noop to have the same effect as instrumenting with opentelemetry-api? So that packages instrumented this way become compatible with both opentelemetry and logfire. I would definitely use this in https://github.com/jackmpcollins/magentic Relevant issue there https://github.com/jackmpcollins/magentic/issues/136
@jackmpcollins I agree, I think that's where this is headed
I think this issue can be closed now with the creation of logfire-api which works great! I was able to use it for https://github.com/jackmpcollins/magentic/pull/265
https://github.com/pydantic/logfire/pull/268 https://docs.pydantic.dev/logfire/integrations/third_party/
@jackmpcollins Yep! Thanks! 🙏
@jackmpcollins awesome! If you open a PR we can add magentic docs under the https://docs.pydantic.dev/logfire/integrations/third_party/ section, similar to Mirascope and LiteLLM.