Skip to main content
Well-structured traces make the difference between useful observability and noisy data. This page covers how to name spans consistently, structure your trace tree, and populate span input/output so the Profiler and Trace Detail View give you actionable insights.

Naming Conventions

Use consistent, parseable span names. The SGP Profiler aggregates performance metrics by span name. Inconsistent naming splits your data into separate rows and makes bottleneck analysis unreliable.
The SGP Profiler aggregates metrics by span name. A constant name such as turn groups all turns together; store the turn number in data. Use numbered names such as research_pass:1 consistently when you want separate profiler rows for each pass. These are conventions for manual spans, not restrictions on valid names.

The Ideal Trace Tree

A well-structured multi-turn agent trace looks like this: ✦ = auto-traced by built-in providers This example tree combines Temporal OpenAI Agents model and tool spans with LiteLLM research calls. The two turn spans can have different turn numbers in their metadata; unmarked grouping and tool spans are manually instrumented. In the Temporal OpenAI Agents integration, function tools such as a custom search_docs function produce tool spans. Hosted OpenAI tools such as Web Search and Code Interpreter appear as tool messages rather than separate tool spans. Key principles:
  • Turn spans are the primary grouping unit: every operation in a conversation turn nests under its turn span
  • Auto-traced spans nest automatically when you pass parent_span_id to built-in providers
  • Sub-tasks and research passes create intermediate grouping for complex multi-step operations
  • State updates capture what changed at the end of a turn

Span Input/Output Best Practices

Inspect an individual span’s input and output in the Trace Detail View span inspector. The Profiler inspector shows aggregate timing metrics and percentile bars for a span name, with links to matching spans. Open one of those spans to inspect its I/O.
The Traces table preview column extracts text from specific preferred keys in your span input and output (e.g., title, query, content). If the preview shows an unhelpful value, add a title key with the value you want displayed.
Agentex profiler view showing aggregated span metrics
  • Input: The user message or event that triggered this turn, plus current state
  • Output: The updated state after processing
Comparing input and output on a turn span lets you quickly see what changed during that turn.
Names and payloads depend on the built-in provider:
  • Temporal OpenAI Agents: streaming_model_get_response captures model, has_system_instructions, input_type, tools_count, and handoffs_count. Its output contains new_items (serialized response items), final_output (extracted text), and usage (token counts).
  • LiteLLM: Spans use the method name, such as chat_completion or chat_completion_stream_auto_send. Input is the serialized LLMConfig; output is the returned Completion or TaskMessage, depending on the method.
  • Input: The tool arguments as a dict
  • Output: The tool result (string or structured data)
  • Input: The context or question being reasoned about
  • Output: The reasoning result, confidence score, and planned next steps
  • Input: Previous state (or the delta being applied)
  • Output: The new state
These are most useful when your state changes are complex and you want to track exactly what was modified.

Manual Spans for Custom Logic

When built-in providers don’t cover your use case (agent reasoning, data processing, custom tool execution), create manual spans.

Using Agentex ADK (Temporal-aware)

Use adk.tracing.span() inside Temporal workflows and activities. It handles Temporal activity routing automatically.
Always check if span: before setting attributes. The span is None when trace_id is falsy, which prevents errors when tracing is disabled.

Using SGP SDK Directly (non-Temporal)

For standalone scripts or non-Temporal agents, use the SGP tracing SDK directly:

Span Type Mapping to SGP

Set __span_type__ in span data to control how the SGP UI categorizes the span:

Example: Multi-Level Research Activity

This complete activity groups multiple research passes under one activity span. Each pass contains a child span created by the LiteLLM provider. Register the activity with your Temporal worker and call it with the shared trace ID and parent span ID:
Each pass keeps at most 2,000 characters of response text for the next prompt and its manual span output. The provider span still captures its normal response. The resulting hierarchy has one provider span per pass:

Checklist

Must-Do

  • Set trace_id = task_id consistently across all spans
  • Create turn-level spans wrapping each conversation turn
  • Pass parent_span_id to all ADK methods and child operations
  • Set span.output before the span closes (inside the context manager)
  • Use consistent manual span names (turn, web_search, llm:gpt-4o, research_pass:1) and retain the provider’s automatic names

Should-Do

  • Include relevant context in span input, not just raw data but structured metadata
  • Set __span_type__ in data for proper SGP categorization
  • Handle errors gracefully by setting error output before the span closes
  • Use nested spans for multi-step operations (research passes, sub-tasks)

Avoid

  • Don’t create flat traces where everything sits at the root level. Use parent_id hierarchy
  • Don’t put massive payloads in input/output. Summarize or truncate large data
  • Don’t forget to check if span: before setting attributes (span is None when trace_id is falsy)
  • Don’t create spans without trace_id. They’ll be orphaned and invisible in the UI