Logfire
Mirascope provides out-of-the-box integration with Logfire.
You can install the necessary packages directly or using the logfire
extras flag:
pip install "mirascope[logfire]"
You can then use the with_logfire
decorator to automatically log calls:
import logfire
from mirascope import llm
from mirascope.integrations.logfire import with_logfire
from pydantic import BaseModel
logfire.configure()
class Book(BaseModel):
title: str
author: str
@with_logfire()
@llm.call(provider="openai", model="gpt-4o-mini", response_model=Book)
def recommend_book(genre: str) -> str:
return f"Recommend a {genre} book."
print(recommend_book("fantasy"))
This will give you:
- A trace around the
recommend_book
function that captures LLM interactions - Structured logging of prompt templates, inputs, and outputs
- Token usage and context details
Example log
Handling streams