Configuring Phoenix Tracing for Single Trace per User Query in AutoGen
Hello Phoenix Support team, I'm integrating Phoenix tracing into an AutoGen multi-agent application and observing that a single user query consistently results in over 50 traces being logged in the Phoenix dashboard. My goal is to achieve a single, consolidated trace per user chat/query. Here are the relevant code snippets and configuration details: AutoGen Agent Setup & Interaction:
import os
import asyncio
from dotenv import load_dotenv
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_agentchat.ui import Console
from autogen_ext.models.openai import OpenAIChatCompletionClient
async def main() -> None:
# ... (API key check and model_client initialization) ...
travel_manager = AssistantAgent(name="travel_manager", model_client=model_client, ...)
destination_expert = AssistantAgent(name="destination_expert", model_client=model_client, ...)
budget_planner = AssistantAgent(name="budget_planner", model_client=model_client, ...)
accommodation_specialist = AssistantAgent(name="accommodation_specialist", model_client=model_client, ...)
activity_planner = AssistantAgent(name="activity_planner", model_client=model_client, ...)
agent_team = RoundRobinGroupChat(
[travel_manager, destination_expert, budget_planner, accommodation_specialist, activity_planner],
max_turns=15
)
test_prompt = "Canada, budget 100000USD , time may 2026, vegetarian only"
stream = agent_team.run_stream(task=test_prompt)
await Console(stream)
# ... (error handling and close) ...Phoenix Instrumentation Code:
from phoenix.otel import register
from openinference.instrumentation.openai import OpenAIInstrumentor
# ... (load_dotenv) ...
def setup_phoenix_tracing():
"""Set up Phoenix tracing for AutoGen agents."""
try:
phoenix_api_key = os.getenv("PHOENIX_API_KEY")
phoenix_collector_endpoint = os.getenv("PHOENIX_COLLECTOR_ENDPOINT")
phoenix_project_name = os.getenv("PHOENIX_PROJECT_NAME", "autogen-test")
if not phoenix_api_key or not phoenix_collector_endpoint:
print("Warning: Phoenix tracing not configured. Set PHOENIX_API_KEY and PHOENIX_COLLECTOR_ENDPOINT in .env")
return None
print(f"Setting up Phoenix tracing for project: {phoenix_project_name}")
tracer_provider = register(
project_name=phoenix_project_name,
endpoint=phoenix_collector_endpoint,
auto_instrument=True
)
OpenAIInstrumentor().instrument(tracer_provider=tracer_provider)
print("Phoenix tracing configured successfully!")
return tracer_provider
except Exception as e:
print(f"Warning: Failed to setup Phoenix tracing: {e}")
return None
# ... (main function where setup_phoenix_tracing() is called) ...I am having these env variables: , PIECES_API_KEY, PHOENIX_COLLECTOR_ENDPOINT, PHOENIX_PROJECT_NAME, PHOENIX_API_KEY, OPENAI_API_KEY. Could you please advise on how to configure the tracing to log a single trace per user query/chat? Is there a specific way to configure arize-phoenix-otel or OpenAIInstrumentor to aggregate these spans more effectively in an AutoGen Multiagent setup? Any guidance on this would be really helpful. Thank you for your assistance. RunLLM
