fix(openai-agents): use SpanKind.INTERNAL for invoke_agent root span#155
Open
bhumikadangayach wants to merge 2 commits into
Open
fix(openai-agents): use SpanKind.INTERNAL for invoke_agent root span#155bhumikadangayach wants to merge 2 commits into
bhumikadangayach wants to merge 2 commits into
Conversation
The root span created in on_trace_start was hardcoded to SpanKind.SERVER, but this doesn't match the OTel definition of SERVER (handling a synchronous remote call) nor anything in the gen-ai-agent-spans semconv. OpenLLMetry's equivalent instrumentation uses INTERNAL for the same case. Fixes open-telemetry#154
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aligns the OpenAI Agents instrumentation’s root invoke_agent span kind with OpenTelemetry guidance by switching the root span created in on_trace_start from SpanKind.SERVER to SpanKind.INTERNAL, and adds a regression test to prevent reintroduction of the incorrect kind.
Changes:
- Update the root span started in
GenAISemanticProcessor.on_trace_startto useSpanKind.INTERNAL. - Add a unit regression test asserting the root span kind is
INTERNAL.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| instrumentation/opentelemetry-instrumentation-genai-openai-agents/src/opentelemetry/instrumentation/genai/openai_agents/span_processor.py | Changes the root span kind for on_trace_start from SERVER to INTERNAL. |
| instrumentation/opentelemetry-instrumentation-genai-openai-agents/tests/test_z_span_processor_unit.py | Adds a regression unit test validating the root span kind is INTERNAL. |
| name=trace.name, | ||
| attributes=attributes, | ||
| kind=SpanKind.SERVER, # Root span is typically server | ||
| kind=SpanKind.INTERNAL, # Root span is typically server |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #154.
The root span created in
on_trace_startwas hardcoded toSpanKind.SERVER, but this doesn't match the OTel definition of SERVER (handling a synchronous remote call) nor anything in the gen-ai-agent-spans semconv. OpenLLMetry's equivalent instrumentation uses INTERNAL for the same case.Verified the fix using the reporter's own repro script — confirmed the bug (
SpanKind.SERVER) before the change and the corrected behavior (SpanKind.INTERNAL) after.Added a regression test (
test_root_span_kind_is_internal) asserting the root span's kind is INTERNAL.Note: couldn't get the full local test suite for this package running due to an unrelated
pytest-recording/vcrfixture scope mismatch in my local environment — the new test follows the existingprocessor_setupfixture pattern used elsewhere in the file, so it should run correctly in CI.