Skip to Content

I trace the OpenAI API with Traceloop. How do I switch to Rius?

Rius replaces your Traceloop setup for OpenAI with one init call, and each OpenAI call arrives as a span with model, tokens and cost. Install the OpenAI extra of the Rius SDK, swap Traceloop.init for rius.init, and remove OpenLLMetry from the process. If you would rather change no code, keep OpenLLMetry and re-point its exporter at Rius, as the Traceloop migration guide describes.

How it works

Traceloop’s SDK is OpenLLMetry, which instruments the OpenAI client and exports OpenTelemetry traces. The Rius SDK does the same job with its own OpenAI instrumentation. When you call init(), Rius detects the installed integration and instruments the OpenAI client for the whole process, so every call is traced without touching your call sites. The OpenAI integration page covers it in full, and the integrations overview lists the other libraries and frameworks.

Both tools instrument the same client library, so run one or the other in a process. Running both produces duplicate LLM spans.

The OpenLLMetry decorators map onto observe:

  • @workflow and @task become @rius.observe, which makes a generic step (the default kind is CHAIN).
  • @agent becomes @rius.observe(kind=SpanKind.AGENT, agent_name=...).
  • @tool becomes @rius.observe(kind=SpanKind.TOOL, tool_name=...).
  • @conversation and set_conversation_id become with rius.session(cid):.
  • set_association_properties with a user id becomes with rius.user(uid):, which sets user.id on every span in scope.

Set it up

  1. Create a Rius API key if you do not have one, and pick one service to move first. The other services keep reporting to Traceloop, so you can compare the two backends on similar traffic. In the service you move, remove the Traceloop SDK, its Traceloop.init call and TRACELOOP_API_KEY.

  2. Install the Rius instrumentation for OpenAI. The extra does not install openai itself, so a fresh environment names it too:

    pip install "glassflow-rius[openai]" openai
  3. Initialize Rius where you initialized Traceloop. app_name becomes service_name, which names the agent your traces are grouped under. Keep using the OpenAI client exactly 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
  4. Replace each OpenLLMetry decorator with observe, using the mapping above. If you use TypeScript, withWorkflow, withAgent and withTool become observe wrappers with the matching kind, and withConversation becomes withSession. Run npm install @arizeai/openinference-instrumentation-openai, call init() before you create the client, and await ready so the patch is in place before your first call:

    import { init } from '@glassflow-ai/rius' import OpenAI from 'openai' const rius = init({ apiKey: 'ri_...', serviceName: 'my-agent' }) await rius.ready const client = new OpenAI() // use the client exactly as before
  5. For streamed calls, ask OpenAI to send usage with the final chunk by passing stream_options with include_usage set to true. Without it, streamed spans have no token counts and so no cost.

  6. Update saved searches that match on span names. Unnamed agent and tool spans are called invoke_agent <name> and execute_tool <name>, not <name>.agent and <name>.tool, and workflow and task spans use their plain name.

  7. Run one request and open the trace in the console. Compare trace counts, token totals and cost with the services still on Traceloop for a few days, then move the rest. To send identical traces to both backends instead, keep OpenLLMetry and use the Collector fan-out. The wider path is in Migrate to Rius.

What you get

  • A span for each model call. Each chat completion shows the resolved model (for example gpt-4o-mini-2024-07-18), input and output token counts, and the input and output messages.
  • Cost per call. Rius computes it on the server from the model and tokens, as a list-price estimate in US dollars. You never send a cost value.
  • Errors recorded. A call OpenAI rejects, such as a 404 for an unknown model, a 429 or a timeout, appears as an ERROR span with error.type naming the error class.
  • Time to first token on Python streams. The Python integration records it without manual code. In TypeScript, streamed chat completions carry token usage and cost when you set include_usage, but no time to first token.
  • Your structure. Agents and tools appear as agent and tool spans with their names, and conversations appear as sessions.
  • Privacy controls. capture_content=False (captureContent: false in TypeScript) and masking apply to instrumented calls.

When something else fits

  • If you want no code changes, keep OpenLLMetry and change its base URL and auth header to point at Rius. Your decorators keep working.
  • If you rely on Traceloop’s monitors, evaluators, guardrails, prompt registry, datasets or experiments, keep Traceloop for those. Rius has no equivalent, so send traces to both while you decide.
  • Re-pointing OpenLLMetry in Python switches off Traceloop platform calls such as get_prompt(), so use a Collector fan-out if your code needs them.

Still stuck? Get help

Last updated on