Summary
Add PostHog LLM analytics integration for the OpenAI Agents SDK, enabling automatic tracking of agent execution, tool calls, handoffs, and LLM generations.
Implementation
The integration uses the SDK's official TracingProcessor interface to capture:
- Agent spans (
$ai_span type=agent)
- LLM generations (
$ai_generation) with token counts and costs
- Tool/function calls (
$ai_span type=tool)
- Agent handoffs (
$ai_span type=handoff)
- Guardrail checks (
$ai_span type=guardrail)
- Custom spans (
$ai_span type=custom)
- Full trace hierarchy (
$ai_trace)
- Conversation linking via
$ai_group_id (maps to SDK's group_id in RunConfig)
Properties
$ai_provider: "openai" (the underlying LLM provider)
$ai_framework: "openai-agents" (identifies the framework)
$ai_total_tokens: Sum of input + output tokens
$ai_error_type: Error categorization (model_behavior_error, user_error, input_guardrail_triggered, output_guardrail_triggered, max_turns_exceeded, unknown)
Usage
from posthog.ai.openai_agents import instrument
instrument(
client=posthog,
distinct_id="user_123",
privacy_mode=False,
)
# Run agents as normal - traces automatically sent to PostHog
Pull Requests
Branches
Real-World Example
- github-standup-agent: A multi-agent system that generates daily standup summaries from GitHub activity. Uses the PostHog OpenAI Agents SDK integration for tracing the Coordinator → Data Gatherer → Summarizer agent workflow.
Follow-up
Summary
Add PostHog LLM analytics integration for the OpenAI Agents SDK, enabling automatic tracking of agent execution, tool calls, handoffs, and LLM generations.
Implementation
The integration uses the SDK's official
TracingProcessorinterface to capture:$ai_spantype=agent)$ai_generation) with token counts and costs$ai_spantype=tool)$ai_spantype=handoff)$ai_spantype=guardrail)$ai_spantype=custom)$ai_trace)$ai_group_id(maps to SDK'sgroup_idinRunConfig)Properties
$ai_provider: "openai" (the underlying LLM provider)$ai_framework: "openai-agents" (identifies the framework)$ai_total_tokens: Sum of input + output tokens$ai_error_type: Error categorization (model_behavior_error, user_error, input_guardrail_triggered, output_guardrail_triggered, max_turns_exceeded, unknown)Usage
Pull Requests
Branches
feat/llma-add-openai-agents-sdk: https://github.com/PostHog/posthog-python/tree/feat/llma-add-openai-agents-sdkfeat/openai-agents-sdk-tracing: https://github.com/PostHog/llm-analytics-apps/tree/feat/openai-agents-sdk-tracingReal-World Example
Follow-up
$ai_group_id