OpenAI Agents SDK Guardrail Span Classification Issues
Problem Description
The OpenAI Agents SDK integration has issues with guardrail span classification and duplicate span creation:
- Incorrect Span Classification: Guardrail events were being incorrectly classified as generic events or agent spans instead of proper
GUARDRAIL span types
- Duplicate Span Creation: Each guardrail creates 2 spans:
{guardrail_name} and {guardrail_name}.guardrail, making it unclear which span represents the actual guardrail execution
- Lost Usage Metrics: Recent fixes removed the wrong span, causing usage metrics to be lost from guardrail spans
Root Cause
Two functions in the OpenAI Agents SDK instrumentation were missing handlers for GuardrailSpanData:
get_span_kind() in exporter.py - didn't handle GuardrailSpanData
get_span_attributes() in attributes/common.py - didn't have a case for GuardrailSpanData
Expected Behavior
- Guardrail events should be properly classified as
GUARDRAIL spans
- Each guardrail should create only one span with proper usage metrics
- Guardrail spans should have appropriate attributes and observability data
Current Status
PR #1096 attempted to fix this but introduced new issues with duplicate spans and lost usage metrics.
Acceptance Criteria
Related
OpenAI Agents SDK Guardrail Span Classification Issues
Problem Description
The OpenAI Agents SDK integration has issues with guardrail span classification and duplicate span creation:
GUARDRAILspan types{guardrail_name}and{guardrail_name}.guardrail, making it unclear which span represents the actual guardrail executionRoot Cause
Two functions in the OpenAI Agents SDK instrumentation were missing handlers for
GuardrailSpanData:get_span_kind()inexporter.py- didn't handleGuardrailSpanDataget_span_attributes()inattributes/common.py- didn't have a case forGuardrailSpanDataExpected Behavior
GUARDRAILspansCurrent Status
PR #1096 attempted to fix this but introduced new issues with duplicate spans and lost usage metrics.
Acceptance Criteria
GUARDRAILspan typeRelated