Launch Week 3: Five days of launches

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:

main.py
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)

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:

main.py
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}")

Next Steps

Ready to monitor AI in production?Connect traces, alerts, dashboards, and evals in one production workflowBook a demo

Last updated on

Built byConfident AI