feat(openai-agents): GenAI semconv compliance#3837
feat(openai-agents): GenAI semconv compliance#3837max-deygin-traceloop wants to merge 8 commits intomainfrom
Conversation
…LM_ → GEN_AI_ - Replace SpanAttributes.LLM_REQUEST_TYPE with GenAIAttributes.GEN_AI_OPERATION_NAME - Replace SpanAttributes.LLM_REQUEST_FUNCTIONS with GenAIAttributes.GEN_AI_TOOL_DEFINITIONS - Replace SpanAttributes.LLM_SYSTEM with GenAIAttributes.GEN_AI_SYSTEM - Replace SpanAttributes.LLM_USAGE_TOTAL_TOKENS with SpanAttributes.GEN_AI_USAGE_TOTAL_TOKENS - Add test_semconv_compliance.py and [tool.uv.sources] for local semconv_ai Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…l definitions to JSON array Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…en test constants, remove duplicate GEN_AI_SYSTEM key Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ssage format Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ve orphaned completion.tool.* attrs
- _realtime_wrappers.py: replace flat gen_ai.prompt.*/gen_ai.completion.* in
create_llm_span() with GEN_AI_INPUT_MESSAGES/GEN_AI_OUTPUT_MESSAGES JSON arrays
- _hooks.py: remove gen_ai.completion.tool.{name,type,strict_json_schema} sub-attributes
from FunctionSpanData handler (tool name already captured via GEN_AI_TOOL_NAME)
- tests: update test_realtime_session.py assertions to parse JSON array attributes
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…, remove AgentSpanData misfeature - _hooks.py: remove misplaced catch-all 'elif span_data:' that was shadowing SpeechSpanData, TranscriptionSpanData, SpeechGroupSpanData, and AgentSpanData branches - _hooks.py: remove AgentSpanData handler that incorrectly propagated model settings to agent spans (test spec: agent spans must NOT carry gen_ai.request.* params) - _hooks.py: replace hardcoded "openai.agent.model.frequency_penalty" with GenAIAttributes.GEN_AI_REQUEST_FREQUENCY_PENALTY constant - tests: fix dead "llm.usage.*" prefix check, fix vestigial "gen_ai.prompt" scan, fix hardcoded frequency_penalty string, fix long line in test_realtime_session.py Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
📝 WalkthroughWalkthroughPrompt and response attributes were consolidated: per-message indexed attributes (e.g., Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/opentelemetry-instrumentation-openai-agents/tests/test_semconv_compliance.py (1)
1-8: Consider extending_testing.pyto cover new message/tool attributes.The shared compliance tests in
opentelemetry.semconv_ai._testing(per the context snippet atpackages/opentelemetry-semantic-conventions-ai/opentelemetry/semconv_ai/_testing.py:1-56) currently validate renamedGEN_AI_*constants but do not include tests for:
GenAIAttributes.GEN_AI_INPUT_MESSAGESGenAIAttributes.GEN_AI_OUTPUT_MESSAGESGenAIAttributes.GEN_AI_TOOL_DEFINITIONSThese constants are imported from the upstream
opentelemetry.semconv._incubating.attributes.gen_ai_attributesmodule and used heavily throughout_hooks.pyand_realtime_wrappers.py. While the import will fail if the constants don't exist, explicit compliance tests would provide better validation and documentation.Would you like me to draft compliance tests for these new upstream constants in
_testing.py?🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/opentelemetry-instrumentation-openai-agents/tests/test_semconv_compliance.py` around lines 1 - 8, Add explicit compliance assertions in the shared test module _testing.py to verify the presence and expected values of the three new GenAI constants: GenAIAttributes.GEN_AI_INPUT_MESSAGES, GenAIAttributes.GEN_AI_OUTPUT_MESSAGES, and GenAIAttributes.GEN_AI_TOOL_DEFINITIONS; import these from opentelemetry.semconv._incubating.attributes.gen_ai_attributes (same source used by _hooks.py and _realtime_wrappers.py) and add simple equality/assertion checks that the exported constants in opentelemetry.semconv_ai match the upstream constants so the tests will fail if those names or values are missing or renamed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@packages/opentelemetry-instrumentation-openai-agents/tests/test_semconv_compliance.py`:
- Around line 1-8: Add explicit compliance assertions in the shared test module
_testing.py to verify the presence and expected values of the three new GenAI
constants: GenAIAttributes.GEN_AI_INPUT_MESSAGES,
GenAIAttributes.GEN_AI_OUTPUT_MESSAGES, and
GenAIAttributes.GEN_AI_TOOL_DEFINITIONS; import these from
opentelemetry.semconv._incubating.attributes.gen_ai_attributes (same source used
by _hooks.py and _realtime_wrappers.py) and add simple equality/assertion checks
that the exported constants in opentelemetry.semconv_ai match the upstream
constants so the tests will fail if those names or values are missing or
renamed.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 55f0bea4-7b6a-434a-89a3-58e2c26ee263
⛔ Files ignored due to path filters (1)
packages/opentelemetry-instrumentation-openai-agents/uv.lockis excluded by!**/*.lock
📒 Files selected for processing (8)
packages/opentelemetry-instrumentation-openai-agents/opentelemetry/instrumentation/openai_agents/_hooks.pypackages/opentelemetry-instrumentation-openai-agents/opentelemetry/instrumentation/openai_agents/_realtime_wrappers.pypackages/opentelemetry-instrumentation-openai-agents/pyproject.tomlpackages/opentelemetry-instrumentation-openai-agents/tests/test_openai_agents.pypackages/opentelemetry-instrumentation-openai-agents/tests/test_realtime.pypackages/opentelemetry-instrumentation-openai-agents/tests/test_realtime_session.pypackages/opentelemetry-instrumentation-openai-agents/tests/test_recipe_agents_hierarchy.pypackages/opentelemetry-instrumentation-openai-agents/tests/test_semconv_compliance.py
💤 Files with no reviewable changes (1)
- packages/opentelemetry-instrumentation-openai-agents/tests/test_realtime.py
packages/opentelemetry-instrumentation-openai-agents/pyproject.toml
Outdated
Show resolved
Hide resolved
| SpanAttributes.LLM_REQUEST_TYPE: "response", | ||
| GenAIAttributes.GEN_AI_SYSTEM: "openai", | ||
| GenAIAttributes.GEN_AI_OPERATION_NAME: "response", | ||
| GenAIAttributes.GEN_AI_SYSTEM: "openai", |
There was a problem hiding this comment.
recalling @avivhalfon comments, shouldn't this be provider?
doronkopit5
left a comment
There was a problem hiding this comment.
did you succeed testing sending traces with this instrumentation using a sample-app?
No longer needed since 0.5.0 is published on PyPI. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Migrate openai-agents instrumentation to OTel GenAI semconv
Aligns the OpenAI Agents SDK instrumentation with the upstream OpenTelemetry GenAI semantic conventions.
Changes:
SpanAttributes.LLM_*constants with upstreamGenAIAttributes.GEN_AI_*equivalentsgen_ai.prompt.{i}.*/gen_ai.completion.{i}.*attributes togen_ai.input.messages/gen_ai.output.messagesJSON arraysgen_ai.tool.definitions.{i}.*attributes togen_ai.tool.definitionsJSON arraygen_ai.operation.namedict keys in_hooks.pygen_ai.systemkey in_realtime_wrappers.pySummary by CodeRabbit
Refactor
gen_ai.input.messages,gen_ai.output.messages) instead of many per-message attributes.gen_ai.tool_definitions,gen_ai.usage.*,gen_ai.operation.name).Tests
Chores