logfire icon indicating copy to clipboard operation
logfire copied to clipboard

`logfire-noop`

Open samuelcolvin opened this issue 1 year ago • 4 comments

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 logfire is installed, it just the contents of logfire
  • 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):
        ...

samuelcolvin avatar May 05 '24 12:05 samuelcolvin

@willbakst might want to use this in https://github.com/Mirascope/mirascope.

samuelcolvin avatar May 05 '24 12:05 samuelcolvin

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.

Kludex avatar May 06 '24 09:05 Kludex

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 avatar May 06 '24 17:05 jackmpcollins

@jackmpcollins I agree, I think that's where this is headed

adriangb avatar May 06 '24 17:05 adriangb

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 avatar Jul 15 '24 02:07 jackmpcollins

@jackmpcollins Yep! Thanks! 🙏

Kludex avatar Jul 15 '24 05:07 Kludex

@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.

alexmojaki avatar Jul 15 '24 10:07 alexmojaki