Skip to content

fix(openai-agents): use SpanKind.INTERNAL for invoke_agent root span#155

Open
bhumikadangayach wants to merge 2 commits into
open-telemetry:mainfrom
bhumikadangayach:fix/agent-root-span-kind
Open

fix(openai-agents): use SpanKind.INTERNAL for invoke_agent root span#155
bhumikadangayach wants to merge 2 commits into
open-telemetry:mainfrom
bhumikadangayach:fix/agent-root-span-kind

Conversation

@bhumikadangayach

Copy link
Copy Markdown

Fixes #154.

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.

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/vcr fixture scope mismatch in my local environment — the new test follows the existing processor_setup fixture pattern used elsewhere in the file, so it should run correctly in CI.

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_start to use SpanKind.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

@lmolkova lmolkova left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be fixed with #90, would appreciate your review on it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

OpenAI Agents root span uses SERVER instead of INTERNAL

3 participants