Mirascope
cetra traces Mirascope calls with its ops tracing: each traced function is a chain span, and each model call is an llm span.
Install
Section titled “Install”pip install cetra-sdk "mirascope[openai,ops]"Set up
Section titled “Set up”Mirascope writes its spans to the tracer provider that you pass to ops.configure. Start cetra first and pass it cetra’s tracer provider. Set CETRA_API_KEY to your sk-cetra-… key and OPENAI_API_KEY to your OpenAI key.
import os
import cetrafrom mirascope import llm, ops
cetra.init()llm.register_provider( "openai:completions", scope="openai:completions/", api_key=os.environ["OPENAI_API_KEY"],)ops.configure(tracer_provider=cetra.tracer_provider())ops.instrument_llm()
@llm.tooldef get_weather(city: str) -> str: """Get the weather.""" return f"sunny in {city}"
@ops.trace@llm.call("openai:completions/gpt-4o-mini", tools=[get_weather])def ask(question: str) -> str: return question
@ops.tracedef run(question: str) -> str: response = ask(question) while response.tool_calls: response = response.resume(response.execute_tools()) return response.text()
with ops.session(id="sess-1"): run("What is the weather in Paris?")
cetra.flush()What you get
Section titled “What you get”With one tool call inside one session, a run produces:
- a
chainspan for each@ops.tracefunction, with its input and output (ask.call,run, and theResponse.resumespan for the tool loop); - an
llmspan for each model call, with the provideropenai, the model, the token counts, the cost computed from the built-in prices, the messages and the tool definitions.
The ops.session ID becomes the session of the @ops.trace spans.
Limits
Section titled “Limits”- The
openai:completions/prefix is stripped from the model name on Mirascope spans, so the model readsgpt-4o-mini. - The
llmspans in the fixture carry no session. The session is on the traced spans. - Each
@ops.tracespan is achainspan, so it adds no tokens or cost. - The fixture was captured with
mirascope2.8.2 and the OpenTelemetry SDK 1.45.2. - If a field is missing, look at the span’s Attributes tab and compare it with Span attributes.
- Traces: read the trace as a tree and a timeline.
- Cost and tokens: how cost is computed from the token counts.
- Online rules: score these traces automatically.