Nyraxis AI

Tracing

Group spans into meaningful traces with nyraxis_sdk.trace()

Tracing

The problem

When you use instrument=True, the SDK auto-traces all LLM calls, retrieval queries, and HTTP requests. Without a parent span, each of these becomes a separate trace in the dashboard — you'll see dozens of disconnected traces per user interaction instead of one.

The solution: nyraxis_sdk.trace()

Wrap your agent invocation with trace() to group all spans into a single trace:

import nyraxis_sdk

nyraxis_sdk.init(api_key="nyx_...", instrument=True, agent_name="my-agent")

# All spans inside become children of one trace:
with nyraxis_sdk.trace("handle-message", user_id="u123"):
    result = agent.invoke({"messages": [{"role": "user", "content": query}]})
import { trace } from "@nyraxis/sdk";

const result = await trace("handle-message", { userId: "u123" }, async () => {
  return await agent.invoke({ messages: [{ role: "user", content: query }] });
});

Where to place trace()

Put it wherever you handle a user interaction — one trace() per message:

def handle_chat(user_id: str, message: str):
    with nyraxis_sdk.trace("chat", user_id=user_id):
        # Everything here becomes one trace:
        # - RAG retrieval
        # - LLM calls
        # - Tool executions
        # - Sub-agent invocations
        result = graph.invoke({"messages": [{"role": "user", "content": message}]})
    return result

Decorator style

@nyraxis_sdk.traced("chat-handler")
def handle_chat(user_id: str, message: str):
    return graph.invoke({"messages": [{"role": "user", "content": message}]})

Custom attributes

Add metadata to traces for filtering in the dashboard:

with nyraxis_sdk.trace("chat",
    user_id="u123",
    session_id="s456",
    environment="production",
    model="gpt-4o",
):
    ...

What happens without trace()

With trace()Without trace()
1 trace per user message10+ traces per message
Full execution tree visibleDisconnected spans
Latency shows total timeIndividual call latencies only
Easy to debug failuresNeedle in a haystack

Works with all frameworks

trace() works with any framework. All auto-instrumented calls within it become children:

  • LangGraph / LangChain
  • CrewAI
  • LlamaIndex
  • AutoGen
  • Haystack
  • DSPy
  • Vercel AI SDK
  • Any OpenAI / Anthropic / vLLM call

No-op without instrumentation

If instrument=True is not set, trace() is a silent no-op — your code runs normally without any overhead.

On this page