pydantic / logfire

Uncomplicated Observability for Python and beyond! 🪵🔥
https://docs.pydantic.dev/logfire/
MIT License
1.62k stars 46 forks source link

`logfire.instrument_*()` methods #193

Open alexmojaki opened 1 month ago

alexmojaki commented 1 month ago

e.g. logfire.instrument_sqlalchemy() instead of from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor; SQLAlchemyInstrumentor().instrument(). Same for all integrations documented in https://docs.pydantic.dev/logfire/integrations/#opentelemetry-integrations.

alexmojaki commented 1 month ago

Remaining methods to add:

I'm not sure about the names of the last 5. It is important that they're methods of logfire objects rather than classes imported from logfire. It would be nice for everything to start with instrument_ but instrument_logging_handler sounds like it's instrumenting a logging handler, rather than returning a handler that 'instruments logging'.

@Kludex I'm going to start working on the first 6, please do the other half.

alexmojaki commented 3 weeks ago

@Kludex I think we should have logfire.instrument_loguru() which calls logger.add(**logfire.loguru_handler()). That makes the naming less weird and should be easier for users, avoiding problems like https://github.com/pydantic/logfire/issues/228. logfire.loguru_handler() can be kept for compatibility but not recommended.