Agent tracing spans
Skill kjuhwa/skills-hub/skills/observability/agent-tracing-spans
Wrap multi-agent workflows in named traces and custom spans for debugging in the OpenAI Traces dashboard.From its SKILL.md
npx -y skills add kjuhwa/skills-hub --skill agent-tracing-spansAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
2.6 KB, 497 tokens by cl100k_base, as published. Nobody here has run it
agent-tracing-spans
Use the trace() context manager to group multiple Runner.run() calls into a single workflow trace. Use custom_span() to add arbitrary spans. Built-in spans (agent, generation, tool, handoff) are created automatically.
When to apply
Debugging complex multi-agent workflows, performance profiling, or monitoring production agent runs. The OpenAI Traces dashboard at platform.openai.com/traces visualizes the tree.
Core snippet
import asyncio
import uuid
from agents import Agent, Runner, trace, custom_span, gen_trace_id
agent = Agent(name="Assistant", instructions="Be helpful.")
async def main():
conversation_id = str(uuid.uuid4().hex[:16])
# Multiple runs in one trace
with trace("My workflow", group_id=conversation_id):
result1 = await Runner.run(agent, "Step 1 input")
result2 = await Runner.run(agent, result1.to_input_list() + [{"role": "user", "content": "Step 2"}])
# Custom spans for non-agent work
with trace("Data pipeline"):
with custom_span("fetch_data"):
data = fetch_data() # your code
result = await Runner.run(agent, str(data))
Background worker flush
from agents import Runner, trace, flush_traces
# In Celery/FastAPI background tasks:
def run_agent_task(prompt: str):
try:
with trace("celery_task"):
result = Runner.run_sync(agent, prompt)
return result.final_output
finally:
flush_traces() # Ensure immediate export
Disable tracing
from agents import set_tracing_disabled
set_tracing_disabled(True) # Globally
# Per-run:
from agents import RunConfig
run_config = RunConfig(tracing_disabled=True)
result = await Runner.run(agent, "Hello", run_config=run_config)
Key notes
- Tracing is enabled by default; disable with
OPENAI_AGENTS_DISABLE_TRACING=1env var trace(workflow_name, group_id=...)groups multi-turn conversationsflush_traces()blocks until buffered traces are exported (use in background workers)gen_trace_id()generates a validtrace_<32_alphanumeric>ID
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.