Customize Trace Names
Giving names to your traces for better visbility on Confident AI
Overview
Both traces and spans have names, and you can customize them based on your liking for better UI display. A good name makes a trace instantly recognizable in the observatory list — "Support Request" tells you far more than the name of whichever function happened to be outermost.
Set Name on Trace
Open a trace context around the work and provide the name you want the resulting trace to use:
from langchain_openai import ChatOpenAI
from confident_trace import init, trace_context
init()
model = ChatOpenAI(model="gpt-4o")
def llm_app(query: str):
with trace_context(name="Call LLM"):
return model.invoke(query)import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";
import { init, traceContext } from "confident-trace";
init();
const llmApp = (query: string) =>
traceContext({ name: "Call LLM" }, () =>
generateText({ model: openai("gpt-4o"), prompt: query }),
);Run your entry point with the Node preload so the Vercel AI SDK call is instrumented.
By default, no name is set on a trace. A trace context supplies the name to traces started inside it and doesn't overwrite a name already set on a trace. The trace name is independent of span names: setting one doesn't rename the other. See Update Trace Properties for the full behavior.
Set Name on Span
Span names are set when you create the span. A function wrapper defaults to the
function's name; pass name explicitly whenever you want something more
readable:
from langchain_openai import ChatOpenAI
from confident_trace import init, span
init()
model = ChatOpenAI(model="gpt-4o")
@span(type="tool", name="Web Search")
def web_search(query: str):
return search(query)
@span(type="agent", name="Call LLM")
def llm_app(query: str):
context = web_search(query)
return model.invoke(f"{context}\n\n{query}")import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";
import { init, span } from "confident-trace";
init();
const webSearch = span({ name: "Web Search", type: "tool" }, async (query: string) => {
return search(query);
});
const llmApp = span(
{ name: "Call LLM", type: "agent" },
async (query: string) => {
const context = await webSearch(query);
return generateText({
model: openai("gpt-4o"),
prompt: `${context}\n\n${query}`,
});
});Next Steps
Span Types
Classify spans as LLM, retriever, tool, or agent so they render with the right icon and type-specific fields.
Tags
Add filterable labels to traces on top of a readable name.
Last updated on