Module for integrations with Pydantic Logfire
with_logfire(cls)
Wraps a pydantic class with a Logfire span.
Source code in mirascope/logfire/logfire.py
| def with_logfire(cls):
"""Wraps a pydantic class with a Logfire span."""
wrap_mirascope_class_functions(
cls,
handle_before_call=handle_before_call,
handle_after_call=handle_after_call,
)
instrumented_providers = ["openai", "anthropic"]
if cls._provider and cls._provider in instrumented_providers:
if hasattr(cls, "configuration"):
cls.configuration = cls.configuration.model_copy(
update={
"client_wrappers": [*cls.configuration.client_wrappers, "logfire"]
}
)
else:
# TODO: Use instrument instead when they are integrated into logfire
if hasattr(cls, "configuration"):
cls.configuration = cls.configuration.model_copy(
update={"llm_ops": [*cls.configuration.llm_ops, mirascope_logfire()]}
)
return cls
|