Skip to content

Fix execute_tool span kind#274

Merged
lmolkova merged 4 commits into
open-telemetry:mainfrom
lmolkova:fix/execute-tool-span-kind
Jul 17, 2026
Merged

Fix execute_tool span kind#274
lmolkova merged 4 commits into
open-telemetry:mainfrom
lmolkova:fix/execute-tool-span-kind

Conversation

@lmolkova

Copy link
Copy Markdown
Member

execute_tool is INTERNAL, not CLIENT.

Also add a rego live-check rule (genai_span_kind_unexpected) that pins the expected span kind per gen_ai.operation.name, which surfaces this class of bug.

execute_tool runs in-process, so its span must be INTERNAL, not CLIENT.
ToolInvocation was inheriting the CLIENT default from GenAIInvocation.

Also add a rego live-check rule (genai_span_kind_unexpected) that pins the
expected span kind per gen_ai.operation.name, which surfaces this class of bug.

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 corrects the span kind for execute_tool in opentelemetry-util-genai (tool execution is in-process, so spans should be INTERNAL rather than CLIENT) and adds a Weaver live-check policy rule to enforce per-operation span kind expectations.

Changes:

  • Emit execute_tool spans with SpanKind.INTERNAL.
  • Add a unit test asserting tool spans are INTERNAL.
  • Add a Rego live-check rule (genai_span_kind_unexpected) that validates span kind against gen_ai.operation.name.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
util/opentelemetry-util-genai/tests/test_toolcall.py Adds a test to ensure tool spans are created with SpanKind.INTERNAL.
util/opentelemetry-util-genai/src/opentelemetry/util/genai/_tool_invocation.py Sets span_kind=SpanKind.INTERNAL when creating ToolInvocation spans.
util/opentelemetry-util-genai/.changelog/+tool-span-internal-kind.fixed Adds a changelog fragment describing the user-visible fix (but filename does not meet CI requirements).
policies/genai_span_validation.rego Adds a policy rule to flag spans whose kind doesn’t match semconv expectations for the operation (with a sort() typing concern).

Comment thread util/opentelemetry-util-genai/.changelog/274.fixed
Comment thread policies/genai_span_validation.rego
@opentelemetry-pr-dashboard

Copy link
Copy Markdown

This PR has review comments. Review suggestions, whether from maintainers or automated reviewers, aren't always correct or required. Please evaluate each comment on its merits, then make sure each thread has a clear outcome.

For example, link to the commit if you applied a suggestion, explain why it wasn't applied, or ask a follow-up question.

Automation flags a PR for human review once every review thread has a reply or is marked as resolved.

Status across open PRs is visible on the pull request dashboard.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@lmolkova lmolkova changed the title Fix execute_tool span Fix execute_tool span kind Jul 16, 2026
lmolkova added 2 commits July 15, 2026 21:52
Renames the changelog fragment to 274.fixed to satisfy the changelog CI
check, and sorts imports in test_toolcall.py to fix the ruff lint gate.

Assisted-by: Claude Opus 4.8
@lmolkova
lmolkova added this pull request to the merge queue Jul 17, 2026
Merged via the queue into open-telemetry:main with commit dc2ee00 Jul 17, 2026
66 checks passed
@lmolkova
lmolkova deleted the fix/execute-tool-span-kind branch July 17, 2026 15:59
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.

4 participants