Skip to Content
Rius

How do I see every tool call for calls to the OpenAI API?

Rius shows each OpenAI call as its own span in the trace, and the tool functions your code runs sit beside it when you wrap them in observe. The integration records the model, token usage, input and output messages, and the tool definitions you sent. Wrap the function that runs each tool in observe and wrap the agent loop in a root span, and the whole run reads as one tree in the waterfall.

How it works

Two layers make up the picture, and they come from different places.

  • The model call, recorded for you. Once init() has run, the OpenAI integration traces every chat completion made with the client, process-wide. Each one becomes a span for the model call with the requested and resolved model, token usage, input and output messages, finish reasons, the completion id and the tool definitions. Rius computes cost from the model and tokens. A call OpenAI rejects, such as a 429 or a timeout, shows as an error span with error.type set to the error class.
  • The tool itself, your own span. The integration instruments the OpenAI client, not the functions your code runs when the model asks for a tool. To see those as steps in the trace, wrap each tool function in observe, and wrap the function that runs the loop too. Name the wrapped functions, because the span takes its name from the function.

Without a wrapper around the loop, each model call arrives as a standalone trace. With it, the model calls and your tool spans nest under one root, in the order they ran.

Content follows your privacy controls. If capture_content=False (captureContent: false in TypeScript) or a mask is set, the messages are stripped. The rest of each span, including timings, tokens and cost, still shows.

Set it up

  1. Install the OpenAI instrumentation. The extra installs the instrumentation, not openai itself. The TypeScript SDK needs @arizeai/openinference-instrumentation-openai instead. The full setup is on the OpenAI integration page, and the other client libraries are listed under Integrations.

    pip install "glassflow-rius[openai]" openai
  2. Call init() before you create the client, then use the client as before.

    import rius from openai import OpenAI rius.init(api_key="ri_...", service_name="my-agent") client = OpenAI() # use the client exactly as before
  3. Wrap the function that runs each tool, and the function that runs the loop. The names get_weather and run_agent here are your own code, not Rius names.

    from rius import SpanKind @rius.observe(kind=SpanKind.TOOL) def get_weather(city: str) -> str: return lookup_weather(city) # your tool code @rius.observe def run_agent(question: str) -> str: ... # call client.chat.completions.create, run tools with get_weather, repeat
  4. If you stream, ask OpenAI for usage on the final chunk. Without stream_options set to include_usage, a streamed call has no token counts and so no cost.

  5. Run the agent once, then open Traces in the console and select the trace. For the wider picture of watching runs in production, see Monitor AI agents in production.

What you get

Open the trace in the waterfall view, where spans appear as a tree on a timeline, badged by kind (chain, llm, tool). The root you wrapped is at the top, and each model call and each wrapped tool function is a child in run order. Select a model call to see the Model section with provider, requested and response model, tokens and cost. The Input / Output tab shows the messages when content is captured.

To list tool steps across many runs:

  • Open the Spans tab and use the All kinds menu to pick Tool, or LLM to see only the model calls.
  • Type your function’s name into the search box, which matches span names, to find every run of one tool across the time range.
  • Sort by Duration or Cost, or filter by status to find the failing ones.

Two tools on the trace page help with loops. Back-to-back calls of the same tool or step collapse into one row such as fetch_article · 3 attempts · recovered, and you can expand it for each attempt. For a trace with several model calls, the context growth strip plots input tokens per call in order. On a model call with captured messages, Since previous llm call shows what the last tool result added to the prompt. Read more in Exploring traces.

Costs are list-price estimates in US dollars. A call that reported no token usage shows a blank cost rather than $0.

When something else fits

  • If your tools run inside a framework such as LangChain, the OpenAI Agents SDK or the Vercel AI SDK, use that framework’s integration from Integrations, which brings in the run structure from the framework’s own spans.
  • If you call the OpenAI API from a language or setup the SDK does not cover, send OpenTelemetry traces to Rius directly, or record the call as a manual generation.

Still stuck? Get help

Last updated on